Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- long long n,t,m,a,b,c,tab[255][255],inf=1000000007;
- int main()
- {
- cin>>t;
- for(int j=0;t>j;j++)
- {
- cin>>n;
- cin>>m;
- for(int x=1;n>=x;x++)
- {
- for(int y=1;n>=y;y++)
- {
- if(x!=y)
- tab[x][y]=inf;
- else
- tab[x][y]=0;
- }
- }
- for(int i=0;m>i;i++)
- {
- cin>>a;
- cin>>b;
- cin>>c;
- tab[a][b]=min(tab[a][b],c);
- tab[b][a]=min(tab[b][a],c);
- }
- for(int f=1;n>=f;f++)
- for(int g=1;n>=g;g++)
- for(int h=1;n>=h;h++)
- {
- if(tab[g][h]>tab[g][f]+tab[f][h])
- {
- tab[g][h]=tab[g][f]+tab[f][h];
- tab[h][g]=tab[g][f]+tab[f][h];
- }
- }
- for(int i=1;n>=i;i++)
- {
- for(int j=1;n>=j;j++)
- {
- if(tab[i][j]!=inf)
- cout<<tab[i][j]<<" ";
- else
- cout<<"-1"<<" ";
- }
- cout<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement