-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAKBAR.cpp
More file actions
64 lines (64 loc) · 1.09 KB
/
AKBAR.cpp
File metadata and controls
64 lines (64 loc) · 1.09 KB
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
#include<vector>
#include<stdio.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test int t;scanf("%d",&t);while(t--)
using namespace std;
vector<int> grph[1000001];
int protect[1000001],flag,visited[1000001];
void assign_protection(int strng,int node)
{
printf("Inside assign protection %d %d\n",node,strng);
if(strng==0)
{
if(protect[node]>1)
flag=1;
protect[node]++;
return;
}
loop(i,0,grph[node].size())
{
if(visited[node]==0){
visited[node]=1;
assign_protection(strng-1,grph[node][i]);
visited[node]=0;
}
}
}
int main()
{
test
{
int n,r,m,k,s;
scanf("%d%d%d",&n,&r,&m);
while(r--)
{
scanf("%d%d",&k,&s);
grph[k].push_back(s);
grph[s].push_back(k);
}
for(int i=0;i<n;i++){
for(int j=0;j<grph[i].size();j++)
printf("%d ",grph[i][j]);
printf("\n");
}
while(m--)
{
scanf("%d%d",&k,&s);
if(flag==0)
assign_protection(s,k);
}
if(flag==1)
printf("No\n");
else
printf("Yes\n");
for(int i=1;i<=n;i++)
printf("%d",protect[i]);
printf("\n");
flag=0;
for(int i=1;i<=n;i++){
grph[i].clear();
protect[i]=0;
}
}
return 0;
}