#include <bits/stdc++.h>
#include "bulb.h"
using namespace std;
struct bec
{
int st,dr;
}val[300005];
bool notbec (int nr)
{
if (nr==-1||nr==-2)
{
return 0;
}
return 1;
}
void dfs (int x,vector <int> l,vector <int> r)
{
if (notbec(l[x]))
{
dfs(l[x],l,r);
val[x].st=val[l[x]].st;
}
else
{
val[x].st=l[x];
}
if (notbec(r[x]))
{
dfs(r[x],l,r);
val[x].dr=val[r[x]].st;
}
else
{
val[x].dr=r[x];
}
}
int FindWinner(int t,vector<int> l,vector<int> r)
{
int n= l.size(),poz,poz1;
poz=0;
while (poz!=-1&&poz!=-2)
{
poz=l[poz];
}
if (poz==-2)
{
return 0;
}
else
{
dfs(0,l,r);
if (val[0].dr==-2)
{
poz=l[0];
while (notbec(poz)==1)
{
if (val[r[poz]].st==-2)
{
return 0;
}
poz=l[poz];
}
poz=r[0];
while (notbec(poz)==1)
{
if (val[r[poz]].st==-1)
{
return 1;
}
poz=l[poz];
}
return 1;
}
else
{
int ok;
poz=l[0];
while (notbec(poz)==1)
{
poz1=r[poz];
ok=0;
while (notbec(poz1)==1)
{
if (val[r[poz1]].st==-2)
{
ok=1;
break;
}
poz1=l[poz1];
}
if (ok==0)
{
return 1;
}
poz=l[poz];
}
return 1;
}
}
}
Compilation message
bulb.cpp: In function 'int FindWinner(int, std::vector<int>, std::vector<int>)':
bulb.cpp:39:6: warning: unused variable 'n' [-Wunused-variable]
int n= l.size(),poz,poz1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
13 ms |
8312 KB |
Output is correct |
5 |
Correct |
13 ms |
8312 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
13 ms |
8312 KB |
Output is correct |
7 |
Correct |
13 ms |
8312 KB |
Output is correct |
8 |
Correct |
3 ms |
632 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
13 ms |
8312 KB |
Output is correct |
7 |
Correct |
13 ms |
8312 KB |
Output is correct |
8 |
Correct |
3 ms |
632 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |