Josif_tepe

Untitled

Jan 28th, 2026
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. typedef long long ll;
  7. const int maxn = 105;
  8.  
  9. vector<pair<int, int>> graph[maxn];
  10. int main() {
  11.     int n; // number of nodes(vertices)
  12.     cin >> n;
  13.    
  14.     int m; // number of edges
  15.     cin >> m;
  16.    
  17.     for(int i = 0; i < m; i++) {
  18.         int a, b, c;
  19.         cin >> a >> b >> c;
  20.        
  21.         graph[a].push_back({b, c});
  22.         graph[b].push_back({a, c});
  23.     }
  24.    
  25.     for(int i = 0; i < n; i++) {
  26.        
  27.         for(int j = 0; j < graph[i].size(); j++) {
  28.             cout << i << "-->" << graph[i][j].first << " = " << graph[i][j].second << endl;
  29.         }
  30.     }
  31.    
  32.    
  33.    
  34.    
  35.    
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment