#include <bits/stdc++.h>
using namespace std;
#include "chameleon.h"
vector<pair<int,int> > eds,adj[1005];
vector<int> st,v;
unordered_set<int> disj[2];
int vis[1005];
void change(int x, int g){
if(disj[g].find(x)==disj[g].end()) return;
disj[g].erase(x);
disj[g^1].insert(x);
vis[x]=1;
for(auto i:adj[x]){
if(!vis[i.first]) change(i.first,g^1);
}
}
void Solve(int n){
int x;
for(int i=1; i<=2*n; i++){
vector<int> ds;
for(int j:disj[0]) ds.push_back(j);
ds.push_back(i);
x=Query(ds);
if(x<(int)ds.size()){
ds.pop_back();
int lo=0,hi=(int)ds.size(),mid;
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
lo++,hi=(int)ds.size();
v.clear();
for(int j=lo; j<hi; j++) v.push_back(ds[j]);
v.push_back(i);
if(Query(v)<(int)v.size()){
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
lo++,hi=(int)ds.size();
v.clear();
for(int j=lo; j<hi; j++) v.push_back(ds[j]);
v.push_back(i);
if(Query(v)<(int)v.size()){
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
}
}
}
ds.clear();
for(int j:disj[1]) ds.push_back(j);
ds.push_back(i);
x=Query(ds);
if(x<(int)ds.size()){
ds.pop_back();
int lo=0,hi=(int)ds.size(),mid;
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
for(int j=0; j<=1000; j++) vis[j]=0;
change(ds[lo],1);
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
lo++,hi=(int)ds.size();
v.clear();
for(int j=lo; j<hi; j++) v.push_back(ds[j]);
v.push_back(i);
if(Query(v)<(int)v.size()){
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
for(int j=0; j<=1000; j++) vis[j]=0;
change(ds[lo],1);
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
lo++,hi=(int)ds.size();
v.clear();
for(int j=lo; j<hi; j++) v.push_back(ds[j]);
v.push_back(i);
if(Query(v)<(int)v.size()){
while(lo<hi){
mid=(lo+hi)/2;
v.clear();
v.push_back(i);
for(int j=lo; j<=mid; j++) v.push_back(ds[j]);
x=Query(v);
if(x<(int)v.size()) hi=mid;
else lo=mid+1;
}
if((int)ds.size()>lo){
for(int j=0; j<=1000; j++) vis[j]=0;
change(ds[lo],1);
eds.push_back({ds[lo],i});
adj[i].push_back({ds[lo],eds.size()-1});
adj[ds[lo]].push_back({i,eds.size()-1});
st.push_back(0);
}
}
}
}
disj[1].insert(i);
}
for(int i=1; i<=2*n; i++){
if((int)adj[i].size()==1) continue;
assert((int)adj[i].size()==3);
int a=Query({i,adj[i][0].first,adj[i][1].first});
int b=Query({i,adj[i][0].first,adj[i][2].first});
int c=Query({i,adj[i][1].first,adj[i][2].first});
if(a==1) st[adj[i][2].second]=1;
if(b==1) st[adj[i][1].second]=1;
if(c==1) st[adj[i][0].second]=1;
}
for(int i=0; i<(int)eds.size(); i++){
if(st[i]==0) Answer(eds[i].first,eds[i].second);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
9 ms |
516 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
532 KB |
Output is correct |
8 |
Correct |
10 ms |
344 KB |
Output is correct |
9 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
22 ms |
580 KB |
Output is correct |
4 |
Correct |
22 ms |
600 KB |
Output is correct |
5 |
Correct |
22 ms |
600 KB |
Output is correct |
6 |
Correct |
22 ms |
552 KB |
Output is correct |
7 |
Correct |
22 ms |
600 KB |
Output is correct |
8 |
Correct |
22 ms |
604 KB |
Output is correct |
9 |
Correct |
22 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
9 ms |
516 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
532 KB |
Output is correct |
8 |
Correct |
10 ms |
344 KB |
Output is correct |
9 |
Correct |
9 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
22 ms |
580 KB |
Output is correct |
31 |
Correct |
22 ms |
600 KB |
Output is correct |
32 |
Correct |
22 ms |
600 KB |
Output is correct |
33 |
Correct |
22 ms |
552 KB |
Output is correct |
34 |
Correct |
22 ms |
600 KB |
Output is correct |
35 |
Correct |
22 ms |
604 KB |
Output is correct |
36 |
Correct |
22 ms |
600 KB |
Output is correct |
37 |
Correct |
33 ms |
600 KB |
Output is correct |
38 |
Correct |
13 ms |
344 KB |
Output is correct |
39 |
Correct |
33 ms |
644 KB |
Output is correct |
40 |
Correct |
33 ms |
576 KB |
Output is correct |
41 |
Correct |
39 ms |
588 KB |
Output is correct |
42 |
Correct |
10 ms |
344 KB |
Output is correct |
43 |
Correct |
21 ms |
600 KB |
Output is correct |
44 |
Correct |
33 ms |
604 KB |
Output is correct |
45 |
Correct |
34 ms |
600 KB |
Output is correct |