fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int node, edge;
  7. cin>>node>>edge;
  8. int u, v, w;
  9. int graph[node+1][node+1];
  10. memset(graph, 0, sizeof(graph));
  11. for(int i = 1; i <= edge; i++)
  12. {
  13. cin>>u>>v>>w;
  14. graph[u][v] = w;
  15. graph[v][u] = w;
  16. }
  17.  
  18. /// i = node, j = node
  19. for(int i = 1; i <node+1; i++)
  20. {
  21. for(int j = 1; j < node+1; j++)
  22. {
  23. cout<<graph[i][j]<<" ";
  24. }
  25. cout<<endl;
  26. }
  27.  
  28.  
  29. }
  30.  
Success #stdin #stdout 0.01s 5312KB
stdin
5 7
1 2 3
2 3 4
3 4 5
4 1 2
1 3 6
2 5 3
3 5 7
stdout
0 3 6 2 0 
3 0 4 0 3 
6 4 0 5 7 
2 0 5 0 0 
0 3 7 0 0