zydhanlinnar11

Buka Cabang

May 28th, 2022 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. // Tested by zydhanlinnar11 on May 28, 2022
  2. #include <iostream>
  3. #include <vector>
  4. #include <cassert>
  5. using namespace std;
  6. typedef vector<int> vi;
  7.  
  8. int main() {
  9.     #ifdef ZYD_WSL
  10.         freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
  11.     #endif
  12.     ios_base::sync_with_stdio(false); cin.tie(NULL);
  13.     int n, m;
  14.     cin>>n>>m;
  15.     assert(2 <= n && n <= (int)1e6);
  16.     vi dist(n, -1);
  17.     dist[0] = 0;
  18.     for(int i=0; i<n; i++) {
  19.         int u, v, w;
  20.         cin>>u>>v>>w;
  21.         assert(0 <= u && u < n);
  22.         assert(0 <= v && v < n);
  23.         assert(1 <= w && w <= 100);
  24.         if(dist[u] == -1) swap(u, v);
  25.         dist[v] = dist[u] + w;
  26.     }
  27.     for(int i=1; i<n; i++) cout<<i<<" "<<dist[i]<<"\n";
  28. }
Add Comment
Please, Sign In to add comment