Josif_tepe

Untitled

Jan 28th, 2026
155
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. int adj[maxn][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 < n; i++) {
  18.         for(int j = 0; j < n; j++) {
  19.             adj[i][j] = 0;
  20.         }
  21.     }
  22.    
  23.     for(int i = 0; i < m; i++) {
  24.         int a, b, c;
  25.         cin >> a >> b >> c;
  26.        
  27.         adj[a][b] = c;
  28.         adj[b][a] = c;
  29.     }
  30.    
  31.     for(int i = 0; i < n; i++) {
  32.         for(int j = 0; j < n; j++) {
  33.             cout << adj[i][j] << " ";
  34.         }
  35.         cout << endl;
  36.     }
  37.    
  38.    
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment