Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n,m;
- struct ed{
- int fr, to, w;
- };
- vector <ed> G;
- const ll inf = 1e18;
- vector <ll> dst;
- void frd(){
- dst.resize(n, inf);
- dst[0] = 0;
- for (int l = 0; l < n; ++l){
- // cout<<"l = "<<l<<"\n";
- for (int i = 0; i < m; ++i){
- if (dst[G[i].fr] == inf) continue;
- if (dst[G[i].to] > dst[G[i].fr] + G[i].w){
- dst[G[i].to] = dst[G[i].fr] + G[i].w;
- }
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>m;
- G.resize(m);
- for (int i = 0; i < m;++i) {
- cin>>G[i].fr>>G[i].to>>G[i].w;
- G[i].fr--;
- G[i].to--;
- }
- frd();
- for (int i = 0; i < n;++i) {
- if (dst[i] == inf) {
- cout<< 30000<<' ';
- continue;
- }
- cout<<dst[i]<<' ';
- }
- cout<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement