# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211692 | thebes | Bulb Game (FXCUP4_bulb) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#inlcude "bulb.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
const int MN = 3e5+5;
int N, i, res[MN], w[MN][2], vs[MN], f, f2, f3, f4;
pii ed[MN];
int acc(int n){
if(n<0) return 0;
if(res[n]) return res[n];
res[n]=ed[n].first<0?ed[n].first:acc(ed[n].first);
return res[n];
}
void solve(int n,int b){
if(n<0) return;
solve(ed[n].first,b);
solve(ed[n].second,0);
w[n][0]=ed[n].first<0?ed[n].first:w[ed[n].first][0];
if(b){
if(ed[n].first>=0) w[n][1]|=w[ed[n].first][1];
if(ed[n].second>=0){
w[n][1]|=(w[ed[n].second][0]==-1);
if(w[n][0]==-1) w[n][1]|=w[ed[n].second][1];
}