-
Notifications
You must be signed in to change notification settings - Fork 0
/
contest2.cpp
83 lines (78 loc) · 1.49 KB
/
contest2.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
83
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e5;
vector <int > adj[N];
int visited[N];
queue<int> q;
int level[N];
bool flag=true;
int case1=0;
void bfs(int source)
{
visited[source] = 1;
q.push(source);
while(!q.empty())
{
int u = q.front();
q.pop();
//cout <<u<<endl;
for( auto x : adj[u])
{
if( visited[x] == 0)
{
visited[x]=1;
q.push(x);
level[x] = level[u] + 1;
}
}
}
}
void sol()
{
int t;
cin >> t;
if(t==0) flag = false;
while ( t-- )
{
int x ,y ;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
while(true)
{
case1++;
int so;
int ttl;
cin >> so >> ttl;
if(so ==0 and ttl ==0)
{
break;
case1--;
}
else
bfs(so);
int reached = 0,not_reached=0,total_node=0;
for(int i=0;i<N;i++)
{
if(visited!=0)
{
total_node++;
if(level[i] <=ttl )
reached++;
}
}
cout<<"Case "<<case1<<": "<< abs(reached-total_node)<<" nodes not reachable from node "<<so<<" with TTL = "<< ttl<<endl;
}
}
int main()
{
int t;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while(flag)
{
sol();
}
}