QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#761119 | #9570. Binary Tree | Meowmeowmeow# | Compile Error | / | / | C++17 | 3.5kb | 2024-11-18 21:02:53 | 2024-11-18 21:02:54 |
Judging History
answer
include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 200005
#define pb push_back
int n,m;
set<int>v[MAXN];
int s[MAXN];
int c[MAXN],fa[MAXN];
void dfs(int x,int ls) {
s[x] = 1;
m ++;
c[m] = x;
for(auto y:v[x]) {
if(y != ls) {
fa[y] = x;
dfs(y,x);
s[x] += s[y];
}
}
}
signed main() {
int T;
cin >> T;
while(T --) {
for(int i = 0 ; i <= n; i ++) {
v[i].clear();
v[i].erase(v[i].begin(),v[i].end());
s[i] = 0; c[i] = 0; fa[i] = 0;
}
cin >> n;
int pp = 0;
for(; (1<<pp) <= n; pp ++) ;
for(int i = 1; i <= n; i ++) {
int x,y;
cin >> x >> y;
if(x != 0) {
v[i].insert(x);
v[x].insert(i);
}
if(y != 0) {
v[i].insert(y);
v[y].insert(i);
}
}
int o = 1;
int cnt = 0;
while(1) {
cnt ++;
if(cnt > pp) {
return 0;
}
m = 0;
fa[o] = 0;
dfs(o,0);
if(s[o] == 1) {
cout<<"! "<<o<<"\n";
fflush(stdout);
break;
}
int ss = s[o];
int t = 0,ux = 0,uy = 0;
for(int i = 1; i <= m; i ++) {
int x = c[i],mx = 0;
for(auto y:v[x]) {
if(fa[y] == x) mx = max(mx,s[y]);
else {
mx = max(mx,ss-s[x]);
}
}
if(mx <= m/2) {
t = x;
//cout<<t<<" "<<mx<<" "<<ss<<"?\n";
if(v[x].size() == 1) {
ux = *v[x].begin();
uy = t;
} else {
int wp[5],nt = 0;
for(auto y:v[x]) {
int sy = 0;
if(fa[y] == x) sy = s[y];
else sy = ss-s[y];
nt ++;
wp[nt] = sy*1000000+y;
}
sort(wp+1,wp+nt+1);
ux = wp[nt]%1000000;
uy = wp[nt-1]%1000000;
}
break;
}
}
if(t == 0) return 0;
if(v[t].size() == 1) {
cout<<"? "<<t<<" "<<ux<<"\n"; fflush(stdout);
int ans;
cin >> ans;
if(ans == 0) {
cout<<"! "<<t<<"\n"; fflush(stdout);
break;
} else {
cout<<"! "<<ux<<"\n"; fflush(stdout);
break;
}
}
if(ux <= 0 || uy <= 0 || ux > n || uy > n) return 0;
cout<<"? "<<ux<<" "<<uy<<"\n"; fflush(stdout);
int ans;
cin >> ans;
if(ans == 0) {
v[ux].erase(t);
o = ux;
}
if(ans == 2) {
v[uy].erase(t);
o = uy;
}
if(ans == 1) {
v[t].erase(ux);
v[t].erase(uy);
o = t;
}
}
//cout<<o<<"\n";
}
return 0;
}
Details
answer.code:1:1: error: ‘include’ does not name a type 1 | include<bits/stdc++.h> | ^~~~~~~ answer.code:9:1: error: ‘set’ does not name a type 9 | set<int>v[MAXN]; | ^~~ answer.code: In function ‘void dfs(long long int, long long int)’: answer.code:17:16: error: ‘v’ was not declared in this scope 17 | for(auto y:v[x]) { | ^ answer.code: In function ‘int main()’: answer.code:28:5: error: ‘cin’ was not declared in this scope 28 | cin >> T; | ^~~ answer.code:31:13: error: ‘v’ was not declared in this scope 31 | v[i].clear(); | ^ answer.code:42:17: error: ‘v’ was not declared in this scope 42 | v[i].insert(x); | ^ answer.code:46:17: error: ‘v’ was not declared in this scope 46 | v[i].insert(y); | ^ answer.code:61:17: error: ‘cout’ was not declared in this scope 61 | cout<<"! "<<o<<"\n"; | ^~~~ answer.code:62:25: error: ‘stdout’ was not declared in this scope 62 | fflush(stdout); | ^~~~~~ answer.code:1:1: note: ‘stdout’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’? +++ |+#include <cstdio> 1 | include<bits/stdc++.h> answer.code:62:18: error: ‘fflush’ was not declared in this scope 62 | fflush(stdout); | ^~~~~~ answer.code:70:28: error: ‘v’ was not declared in this scope 70 | for(auto y:v[x]) { | ^ answer.code:71:41: error: ‘max’ was not declared in this scope; did you mean ‘mx’? 71 | if(fa[y] == x) mx = max(mx,s[y]); | ^~~ | mx answer.code:73:30: error: ‘max’ was not declared in this scope; did you mean ‘mx’? 73 | mx = max(mx,ss-s[x]); | ^~~ | mx answer.code:79:24: error: ‘v’ was not declared in this scope 79 | if(v[x].size() == 1) { | ^ answer.code:91:25: error: ‘sort’ was not declared in this scope; did you mean ‘short’? 91 | sort(wp+1,wp+nt+1); | ^~~~ | short answer.code:99:16: error: ‘v’ was not declared in this scope 99 | if(v[t].size() == 1) { | ^ answer.code:100:17: error: ‘cout’ was not declared in this scope 100 | cout<<"? "<<t<<" "<<ux<<"\n"; fflush(stdout); | ^~~~ answer.code:100:54: error: ‘stdout’ was not declared in this scope 100 | cout<<"? "<<t<<" "<<ux<<"\n"; fflush(stdout); | ^~~~~~ answer.code:100:54: note: ‘stdout’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’? answer.code:100:47: error: ‘fflush’ was not declared in this scope 100 | cout<<"? "<<t<<" "<<ux<<"\n"; fflush(stdout); | ^~~~~~ answer.code:112:13: error: ‘cout’ was not declared in this scope 112 | cout<<"? "<<ux<<" "<<uy<<"\n"; fflush(stdout); | ^~~~ answer.code:112:51: error: ‘stdout’ was not declared in this scope 112 | cout<<"? "<<ux<<" "<<uy<<"\n"; fflush(stdout); | ^~~~~~ answer.code:112:51: note: ‘stdout’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’? answer.code:112:44: error: ‘fflush’ was not declared in this scope 112 | cout<<"? "<<ux<<" "<<uy<<"\n"; fflush(stdout); | ^~~~~~ answer.code:116:17: error: ‘v’ was not declared in this scope 116 | v[ux].erase(t); | ^ answer.code:120:17: error: ‘v’ was not declared in this scope 120 | v[uy].erase(t); | ^ answer.code:124:17: error: ‘v’ was not declared in this scope 124 | v[t].erase(ux); | ^