#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bulb.h"
#include "bulb.h"
#include<bits/stdc++.h>
using namespace std;
int l[300100],r[300100];
bool exist[300100];
vector<int> wen,owe;
void dfs(int node)
{
r[node]=-owe[node];
if(owe[node]>=0)
{
dfs(owe[node]);
r[node]=l[owe[node]];
}
if(r[node]==2)
exist[node]=true;
l[node]=-wen[node];
if(wen[node]>=0)
{
dfs(wen[node]);
l[node]=l[wen[node]];
if(exist[node]==false&&exist[wen[node]])
exist[node]=true;
}
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int N = L.size();
for(int i=0;i<N;i++)
{
wen.push_back(L[i]);
owe.push_back(R[i]);
}
dfs(0);
if(l[0]==2)
return 0;
int node=0,s=0,p=0;
while(r[node]==1)
{
s++;
p++;
if(owe[node]<0)
return 1;
if(!exist[owe[node]])
return 1;
if(r[owe[node]]==2)
p++;
if(wen[node]<0)
break;
node=wen[node];
}
s++;
int first=owe[node];
if(r[node]==2)
{
while(first>=0)
{
s++;
if(r[first]==2)
return 0;
first=wen[first];
}
if(s==N)
return 1;
return 0;
}
if(p==N)
return 0;
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
404 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
404 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
92 ms |
10244 KB |
Output is correct |
28 |
Correct |
91 ms |
10172 KB |
Output is correct |
29 |
Correct |
94 ms |
10248 KB |
Output is correct |
30 |
Correct |
99 ms |
19544 KB |
Output is correct |
31 |
Correct |
103 ms |
19668 KB |
Output is correct |
32 |
Correct |
94 ms |
10252 KB |
Output is correct |
33 |
Correct |
96 ms |
10276 KB |
Output is correct |
34 |
Correct |
93 ms |
10284 KB |
Output is correct |
35 |
Correct |
94 ms |
10200 KB |
Output is correct |
36 |
Correct |
94 ms |
10308 KB |
Output is correct |
37 |
Correct |
95 ms |
10236 KB |
Output is correct |
38 |
Correct |
95 ms |
10244 KB |
Output is correct |
39 |
Correct |
93 ms |
10176 KB |
Output is correct |
40 |
Correct |
93 ms |
10284 KB |
Output is correct |
41 |
Correct |
94 ms |
10196 KB |
Output is correct |
42 |
Correct |
93 ms |
10212 KB |
Output is correct |
43 |
Correct |
93 ms |
10204 KB |
Output is correct |
44 |
Correct |
93 ms |
10284 KB |
Output is correct |
45 |
Correct |
94 ms |
10280 KB |
Output is correct |
46 |
Correct |
93 ms |
10204 KB |
Output is correct |
47 |
Correct |
94 ms |
12252 KB |
Output is correct |
48 |
Correct |
100 ms |
12356 KB |
Output is correct |
49 |
Correct |
94 ms |
12292 KB |
Output is correct |
50 |
Correct |
94 ms |
12252 KB |
Output is correct |