QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#98929 | #4218. Hidden Graph | _yjh | WA | 4ms | 3524kb | C++14 | 2.9kb | 2023-04-20 22:23:23 | 2023-04-20 22:23:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int n,mx,m,col[2005],d[2005],dd[2005];
bool del[2005],vis[2005];
vector <int> nt[2005];
vector <int> v[2005];
queue <int> q;
bool check(int x,int nw) {
for(int i=1;i<=nw;i++) dd[i]=v[i].size(),del[i]=false,vis[i]=0;
while(!q.empty()) q.pop();
for(int i=1;i<=nw;i++) {
if(dd[i]<=x-1) {
q.push(i);
del[i]=true;
}
}
int cnt=0;
while(!q.empty()) {
cnt++;
int s=q.front();
// cout<<"S"<<s<<'\n';
vis[s]=true;
q.pop();
for(int to:v[s]) {
if(vis[to]) continue;
dd[to]--;
if(dd[to]<=x-1&&!del[to]) {
q.push(to);
del[to]=true;
}
}
}
// cout<<"WYY"<<x<<' '<<cnt<<'\n';
if(cnt==nw) return 1;
return 0;
}
int main() {
cin>>n;
nt[1].push_back(1);
mx=1;
for(int nw=2;nw<=n;nw++) {
for(int i=1;i<=mx;i++) {
if(!nt[i].size()) continue;
int sz=nt[i].size();
while(sz) {
cout<<"? "<<sz+1<<' ';
for(int k:nt[i]) {
if(!del[k]) cout<<k<<' ';
}
cout<<nw<<endl;
int x,y;
cin>>x>>y;
if(x==-1||y==-1) break;
if(x==nw) swap(x,y);
v[y].push_back(x);
v[x].push_back(y);
m++;
del[x]=true;
sz--;
}
// nt[i].clear();
}
for(int i=1;i<=n;i++) nt[i].clear();
mx=n+1;
for(int i=1;i<=nw;i++) {
del[i]=false;
col[i]=0;
// cout<<i<<' '<<v[i].size()<<'\n';
// mx=min(mx,int(v[i].size())+1);
d[i]=v[i].size();
}
// cout<<mx<<'\n';
// if(n==2000) assert(mx<=3);
int l=1,r=n,ans=-1;
while(l<=r) {
int mid=(l+r)/2;
if(check(mid,nw)) r=mid-1,ans=mid;
else l=mid+1;
}
mx=ans;
// cout<<mx<<'\n';
for(int i=1;i<=nw;i++) {
if(d[i]<=mx-1) {
q.push(i);
del[i]=true;
// cout<<"A!"<<i<<'\n';
// break;
}
}
for(int i=1;i<=nw;i++) del[i]=0;
// cout<<q.front()<<'\n';
set <int> tmp;
while(!q.empty()) {
int s=q.front();
q.pop();
tmp.clear();
// cout<<s<<col[s]<<'\n';
if(!col[s]) {
for(int to:v[s]) {
if(col[to]) tmp.insert(col[to]);
}
// sort(tmp.begin(),tmp.end());
int nww=1;
for(int i:tmp) {
if(nww!=i) break;
nww++;
}
// cout<<"S"<<nww<<'\n';
col[s]=nww;
for(int to:v[s]) {
d[to]--;
// if(!del[to]) q.push(to);
// cout<<"QW"<<to<<' '<<d[to]<<' '<<del[to]<<'\n';
if(d[to]<=mx-1&&!del[to]) {
del[to]=true;
q.push(to);
}
}
nt[col[s]].push_back(s);
}
}
// for(int i=1;i<=nw;i++) {
// cout<<i<<':';
// for(int to:v[i]) {
// cout<<to<<' ';
// }
// cout<<'\n';
// }
for(int i=1;i<=nw;i++) {
del[i]=false;
// assert(col[i]);
// cout<<col[i]<<' ';
}
// cout<<'\n';
}
cout<<'!'<<' '<<m<<'\n';
for(int i=1;i<=n;i++) {
for(int j:v[i]) {
if(j<i) continue;
cout<<i<<' '<<j<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3388kb
input:
3 1 2 1 3 2 3
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ! 3 1 2 1 3 2 3
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
10 1 2 1 3 -1 -1 -1 -1 1 4 4 5 2 5 -1 -1 -1 -1 2 6 -1 -1 -1 -1 3 7 -1 -1 -1 -1 -1 -1 4 8 3 8 -1 -1 -1 -1 -1 -1 -1 -1 3 9 -1 -1 -1 -1 4 10 3 10 -1 -1
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ? 3 2 3 4 ? 2 1 4 ? 4 2 3 4 5 ? 3 2 3 5 ? 2 3 5 ? 2 1 5 ? 4 2 3 4 6 ? 3 3 4 6 ? 3 5 1 6 ? 4 3 4 6 7 ? 3 4 6 7 ? 3 5 1 7 ? 2 2 7 ? 4 3 4 6 8 ? 3 3 6 8 ? 2 6 8 ? 4 5 7 1 8 ? 2 2 8 ? 6 5 6 7 8 1 9 ? 4 4 2 3 9 ? 3 4 2 9 ? 7 5 6 7 8 9 1 10 ? 4 4 2 3 10 ? 3 2 3 10 ? 2 2 10 ! 12 1 2...
result:
ok correct
Test #3:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
5 2 1 3 1 3 2 4 1 4 2 -1 -1 -1 -1 5 1 5 2
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ? 2 1 4 ? 2 2 4 ? 2 3 4 ? 3 3 4 5 ? 2 1 5 ? 2 2 5 ! 7 1 2 1 3 1 4 1 5 2 3 2 4 2 5
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3392kb
input:
3 2 1 1 3 -1 -1
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ! 2 1 2 1 3
result:
ok correct
Test #5:
score: 0
Accepted
time: 3ms
memory: 3516kb
input:
6 1 2 3 1 3 2 -1 -1 4 2 3 4 4 5 -1 -1 2 5 3 5 -1 -1 -1 -1 -1 -1 3 6
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ? 2 1 4 ? 2 2 4 ? 2 3 4 ? 3 1 4 5 ? 2 1 5 ? 2 2 5 ? 2 3 5 ? 3 1 4 6 ? 2 5 6 ? 2 2 6 ? 2 3 6 ! 9 1 2 1 3 2 3 2 4 2 5 3 4 3 5 3 6 4 5
result:
ok correct
Test #6:
score: -100
Wrong Answer
time: 4ms
memory: 3472kb
input:
27 -1 -1 3 1 3 2 -1 -1 -1 -1 1 5 2 5 -1 -1 3 5 6 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10 8 -1 -1 -1 -1 6 11 4 11 -1 -1 -1 -1 5 11 1 9 -1 -1 12 11 -1 -1 5 12 -1 -1 8 13 -1 -1 10 13 6 13 -1 -1 1 11 -1 -1 14 12 6 14 -1 -1 14 8 -1 -1 5 13 -1 -1 10 15 -1 -1 ...
output:
? 2 1 2 ? 3 1 2 3 ? 2 2 3 ? 3 1 2 4 ? 2 3 4 ? 4 1 2 4 5 ? 3 2 4 5 ? 2 4 5 ? 2 3 5 ? 4 1 2 4 6 ? 3 2 4 6 ? 2 3 6 ? 2 5 6 ? 4 2 4 6 7 ? 2 3 7 ? 2 5 7 ? 5 2 4 6 7 8 ? 4 2 4 7 8 ? 2 3 8 ? 2 5 8 ? 5 2 4 6 7 9 ? 3 8 3 9 ? 2 5 9 ? 6 2 4 6 7 9 10 ? 3 8 3 10 ? 2 3 10 ? 2 5 10 ? 7 2 4 6 7 9 10 11 ? 6 2 4 7 9 ...
result:
wrong answer read 80 edges but expected 88 edges