-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10000.cpp
More file actions
61 lines (56 loc) · 778 Bytes
/
10000.cpp
File metadata and controls
61 lines (56 loc) · 778 Bytes
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
#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
vector<long>ve[110];
queue<long>q;
long d[110];
long n,s,a,u,v,end,mx;
void bfs(long x)
{
long y,b;
q.push(x);
while(!q.empty())
{
a=q.front();
for(y=0;y<ve[a].size();y++)
{
b=ve[a][y];
if(d[b]<=d[a])
{
d[b]=d[a]+1;
q.push(b);
}
}
q.pop();
}
}
int main()
{
long i,k=1;
while(~scanf("%ld",&n)&&n)
{
for(i=1;i<=n;i++)
{
d[i]=0;
ve[i].clear();
}
scanf("%ld",&s);
end=s;
while(scanf("%ld%ld",&u,&v)&&(u||v))
ve[u].push_back(v);
bfs(s);
i=s;
mx=0;
for(i=1;i<=n;i++)
{
if(d[i]>mx)
{
mx=d[i];
end=i;
}
}
printf("Case %ld: The longest path from %ld has length %ld, finishing at %ld.\n\n",k++,s,mx,end);
}
return 0;
}