-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy path00336.cc
54 lines (54 loc) · 1.1 KB
/
00336.cc
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
// https://uva.onlinejudge.org/external/3/336.pdf
#include<bits/stdc++.h>
using namespace std;
using ii=tuple<int,int>;
using vii=vector<ii>;
using vi=vector<int>;
using vvi=vector<vi>;
using mii=unordered_map<int,int>;
using qi=queue<int>;
int main(){
for(int T=1;;){
int m,u,v,w,n=0,k;
cin>>m;
if(!m)break;
mii x;
vii e(m);
for(int i=0;i<m;i++){
cin>>u>>v;
if(!x[u])x[u]=++n;
if(!x[v])x[v]=++n;
e[i]=make_tuple(x[u]-1,x[v]-1);
}
vvi g(n);
for(ii a:e){
tie(u,v)=a;
g[u].push_back(v);
g[v].push_back(u);
}
for(;;){
cin>>w>>k;
if(!w)break;
u=x[w]-1;
vi s(n);
if(u>=0){
s[u]=1;
qi q;
q.push(u);
while(!q.empty()){
u=q.front();
q.pop();
if(s[u]<=k)
for(int v:g[u])
if(!s[v]){
s[v]=s[u]+1;
q.push(v);
}
}
}
int c=0;
for(int x:s)c+=(!x);
cout<<"Case "<<T++<<": "<<c<<" nodes not reachable from node "<<w<<" with TTL = "<<k<<".\n";
}
}
}