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