Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tested by zydhanlinnar11 on May 28, 2022
- #include <iostream>
- #include <vector>
- #include <cassert>
- using namespace std;
- typedef vector<int> vi;
- int main() {
- #ifdef ZYD_WSL
- freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
- #endif
- ios_base::sync_with_stdio(false); cin.tie(NULL);
- int n, m;
- cin>>n>>m;
- assert(2 <= n && n <= (int)1e6);
- vi dist(n, -1);
- dist[0] = 0;
- for(int i=0; i<n; i++) {
- int u, v, w;
- cin>>u>>v>>w;
- assert(0 <= u && u < n);
- assert(0 <= v && v < n);
- assert(1 <= w && w <= 100);
- if(dist[u] == -1) swap(u, v);
- dist[v] = dist[u] + w;
- }
- for(int i=1; i<n; i++) cout<<i<<" "<<dist[i]<<"\n";
- }
Add Comment
Please, Sign In to add comment