-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1056-2.cpp
87 lines (78 loc) · 1.75 KB
/
1056-2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @author : Maruf Tuhin
* @School : CUET CSE 11
* @TOPCODER : the_redback
* @CodeForces : the_redback
* @UVA : Redback
* @link : http://www.fb.com/maruf.2hin
*/
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
using namespace std;
#define inf 10000000
#define mem(a,b) memset(a,b,sizeof(a))
#define NN 50
int a[NN+7][NN+7];
map<string,int>mp;
string s,ss;
int warsh(int n)
{
int i,j,k;
for(k=0; k<n; k++)
for(i=0; i<n; i++)
for(j=0; j<n; j++)
a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
int ret=-inf;
for(i=0; i<n; i++)
for(j=0; j<n; j++)
ret=max(ret,a[i][j]);
return ret;
}
main()
{
//freopen("C:\\Users\\Maruf Tuhin\\Desktop\\in.txt","r",stdin);
//ios_base::sync_with_stdio(false);
int i,j,k,l,n,r,c;
int tc,t=1;
//cin>>tc;
while(~scanf("%d%d",&n,&r))
{
if(n==0 && r==0)
return 0;
k=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=inf;
for(i=0; i<r; i++)
{
cin>>s>>ss;
if(mp.find(s)==mp.end())
mp[s]=k++;
if(mp.find(ss)==mp.end())
mp[ss]=k++;
a[mp[s]][mp[ss]]=a[mp[ss]][mp[s]]=1;
a[mp[ss]][mp[ss]]=a[mp[s]][mp[s]]=0;
}
int ret=warsh(n);
if(ret>=inf)
printf("Network %d: DISCONNECTED\n",t++);
else
printf("Network %d: %d\n",t++,ret);
puts("");
mp.clear();
}
return 0;
}