#include "bulb.h"
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 300010;
int l[MAX_N+1], r[MAX_N+1];
int N, T;
int l2[MAX_N+1];
int r2[MAX_N+1];
bool dp1[MAX_N+1];
bool dp2[MAX_N+1];
int cnt[MAX_N+1];
int num = 0;
void dfs(int x){
if(r[x]>=0){
dfs(r[x]);
r2[x] = l2[r[x]];
}else{
r2[x] = -r[x];
}
if(l[x]>=0){
dfs(l[x]);
cnt[x] = cnt[l[x]]+1;
l2[x] = l2[l[x]];
dp1[x] = (dp1[l[x]] && (r2[x]==1));
dp2[x] = (dp2[l[x]] || (r2[x]==1));
}else{
cnt[x] = 1;
l2[x] = -l[x];
dp1[x] = (r2[x]==1);
dp2[x] = (r2[x]==1 || l2[x]==1);
}
}
bool dfs2(int x){
if(r[x]>=0){
if(dp1[r[x]] && (r2[x]==1)){
return true;
}
if(dp1[r[x]] && (cnt[0] - cnt[x] + 1 + cnt[r[x]] == N)){
return true;
}
}else{
if(r2[x]==1){
return true;
}
if(cnt[0] - cnt[x]+1 == N){
return true;
}
}
if(r2[x]==1 && l[x]>=0){
return dfs2(l[x]);
}
return false;
}
int FindWinner(int t, vector<int> L, vector<int> R){
N = R.size(); T = t;
for(int i=0; i<N; i++){
l[i] = L[i]; r[i] = R[i];
}
dfs(0);
if(l2[0]==2){
return 0;
}
int idx = 0;
while(1){
num++;
if(L[idx]<0){
break;
}
idx = L[idx];
}
idx = 0;
bool tf = true;
int cnt = 1;
while(1){
if(R[idx]<0){
if(R[idx]!=-1){
tf = false;
}
}else{
if(r2[idx]!=1){
if(dp2[r[idx]]){
cnt--;
if(cnt<0){
tf = false;
}
}else{
tf = false;
}
}
}
if(L[idx]<0){
break;
}
idx = L[idx];
}
if(tf) return true;
if(dp1[0] && (num!=N)){
return true;
}
bool b = dfs2(0);
return b;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 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 |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
420 KB |
Output is correct |
7 |
Correct |
2 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 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 |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
424 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
400 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
420 KB |
Output is correct |
7 |
Correct |
2 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 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 |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
424 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
400 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
90 ms |
11420 KB |
Output is correct |
28 |
Correct |
91 ms |
13440 KB |
Output is correct |
29 |
Correct |
91 ms |
13604 KB |
Output is correct |
30 |
Correct |
104 ms |
17432 KB |
Output is correct |
31 |
Correct |
104 ms |
17316 KB |
Output is correct |
32 |
Correct |
90 ms |
12196 KB |
Output is correct |
33 |
Correct |
91 ms |
14084 KB |
Output is correct |
34 |
Correct |
90 ms |
14300 KB |
Output is correct |
35 |
Correct |
90 ms |
12280 KB |
Output is correct |
36 |
Correct |
90 ms |
13616 KB |
Output is correct |
37 |
Correct |
91 ms |
12724 KB |
Output is correct |
38 |
Correct |
90 ms |
13776 KB |
Output is correct |
39 |
Correct |
90 ms |
13944 KB |
Output is correct |
40 |
Correct |
89 ms |
12144 KB |
Output is correct |
41 |
Correct |
91 ms |
12052 KB |
Output is correct |
42 |
Correct |
90 ms |
13896 KB |
Output is correct |
43 |
Correct |
89 ms |
14228 KB |
Output is correct |
44 |
Correct |
90 ms |
13484 KB |
Output is correct |
45 |
Correct |
91 ms |
12380 KB |
Output is correct |
46 |
Correct |
92 ms |
13372 KB |
Output is correct |
47 |
Correct |
96 ms |
13056 KB |
Output is correct |
48 |
Correct |
95 ms |
13816 KB |
Output is correct |
49 |
Correct |
95 ms |
15016 KB |
Output is correct |
50 |
Correct |
94 ms |
12508 KB |
Output is correct |