Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fast()(ios_base::sync_with_stdio(false),cin.tie(NULL));
- int main()
- {
- int test;
- fast()
- cin>>test;
- for(int t=1; t<=test; t++)
- {
- int node,edge;
- cin>>node>>edge;
- int path[node+2][node+2];
- for(int i=0; i<=node; i++)
- for(int j=0; j<=node; j++)
- path[i][j]=101;
- for(int i=0; i<edge; i++)
- {
- int u,v;
- cin>>u>>v;
- path[u][v]=1;
- path[v][u]=1;
- path[u][u]=0;
- path[v][v]=0;
- }
- for(int i=0; i<node; i++)
- {
- for(int j=0; j<node; j++)
- {
- for(int k=0; k<node; k++)
- {
- if(path[j][k]>path[j][i]+path[i][k])
- path[j][k]=path[j][i]+path[i][k];
- }
- }
- }
- int s,d,mintime=0;
- cin>>s>>d;
- for(int i=0;i<node;i++)
- {
- if(path[s][i]!=101 && path[i][d]!=101)
- {
- mintime=max(mintime,path[s][i]+path[i][d]);
- }
- }
- cout<<"Case "<<t<<": "<<mintime<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement