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