From d368c89147ccee5bc3c7847bd5c33e29e1a0f451 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 17 Nov 2024 22:01:54 +0800 Subject: [PATCH] update --- src/P3371/P3371.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ src/P3371/P3371_1.in | 16 ++++++++++++ src/P3371/P3371_1.out | 1 + src/P6147/P6147.cpp | 23 +++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 src/P3371/P3371.cpp create mode 100644 src/P3371/P3371_1.in create mode 100644 src/P3371/P3371_1.out create mode 100644 src/P6147/P6147.cpp diff --git a/src/P3371/P3371.cpp b/src/P3371/P3371.cpp new file mode 100644 index 0000000..bfb21d4 --- /dev/null +++ b/src/P3371/P3371.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include +#include + +using ll = int64_t; +using std::cin, std::cout; + +const ll maxn = 1e5+5; +ll n, m, s, dist[maxn], inf {(1ll<<31)-1}; +std::vector> adj[maxn]; + +int main(){ + std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + + cin>>n>>m>>s; + + std::fill(dist, dist+1+n, inf); + dist[s]=0; + for(ll i{1}; i<=m; i++){ + ll u, v, w; + cin>>u>>v>>w; + for(auto& edge: adj[u]){ + if(edge.first==v){ + edge.second=std::min(edge.second, w); + goto end; + } + } + adj[u].emplace_back(v, w); + end:; + } + + std::priority_queue, std::vector>, std::greater<>> pq; + + pq.emplace(0, s); + + while(pq.size()){ + auto [d, u] = pq.top(); + pq.pop(); + + if(d>dist[u])continue; + + for(auto& edge: adj[u]){ + auto [v, w] {edge}; + if(dist[u] + w < dist[v]){ + dist[v] = dist[u] + w; + pq.emplace(dist[v], v); + } + } + } + + for(ll i{1}; i<=n; i++){ + cout< +#include +#include + +using ll = int64_t; +using std::cin, std::cout; + +const ll maxn = 1e5+5; +ll n; +std::vector adj[maxn]; + +int main(){ + std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + + cin>>n; + for(ll i{1}; i>u>>v; + adj[u].push_back(v); + } + + +} \ No newline at end of file