QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641992 | #4218. Hidden Graph | ship2077 | WA | 1ms | 3624kb | C++23 | 1.7kb | 2024-10-15 08:17:53 | 2024-10-15 08:17:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=2005;bool vis[M];
int n,num,col[M],tmp[M],deg[M];
vector<pair<int,int>>ans;
vector<int>res[M],adj[M];
struct info{ int val,pos;
bool operator <(const info &a) const
{return a.val<val;}
};
pair<int,int> query(vector<int>&qry){
if (qry.size()<2) return make_pair(-1,-1);
cout<<"? "<<qry.size(); for (auto x:qry) cout<<' '<<x; cout<<'\n';
int x,y; cin>>x>>y;
if (!~x) return make_pair(-1,-1);
adj[x].emplace_back(y);
adj[y].emplace_back(x);
ans.emplace_back(x,y);
return minmax(x,y);
}
void build(int n){
vector<int>rec; priority_queue<info>q; num=0;
for (int i=1;i<=n;i++) col[i]=-1,vis[i]=tmp[i]=0,res[i].clear();
for (int i=1;i<=n;i++) q.push({deg[i]=adj[i].size(),i});
while (!q.empty()){
auto [val,x]=q.top();q.pop();
if (vis[x]) continue;
vis[x]=1;rec.emplace_back(x);
for (auto y:adj[x]) q.push({--deg[y],y});
}
reverse(rec.begin(),rec.end());
for (auto x:rec){
for (auto y:adj[x])
if (~col[y]) tmp[col[y]]=x;
for (int i=1;i<=n;i++)
if (tmp[i]!=x) {col[x]=i;break;}
res[col[x]].emplace_back(x);num=max(num,col[x]);
}
}
int main(){ cin>>n;
for (int i=1;i<=n;i++){
for (int j=1;j<=num;j++){
res[j].emplace_back(i);
int x=query(res[j]).first;
while (~x){
res[j].erase(lower_bound(res[j].begin(),res[j].end(),x));
x=query(res[j]).first;
}
}
build(i);
}
cout<<"! "<<ans.size()<<'\n';
for (auto [x,y]:ans) cout<<x<<' '<<y<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
3 1 2 2 3 1 3
output:
? 2 1 2 ? 2 2 3 ? 2 1 3 ! 3 1 2 2 3 1 3
result:
ok correct
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
10 1 2 -1 -1 1 3 1 4 -1 -1 -1 -1 2 5 2 5 2 5 -1 -1 2 6 -1 -1 -1 -1 3 7 3 7 -1 -1 4 8 3 8 -1 -1 -1 -1 3 9 -1 -1 -1 -1 -1 -1 4 10 3 10 -1 -1
output:
? 2 1 2 ? 2 2 3 ? 2 1 3 ? 2 1 4 ? 3 3 2 4 ? 2 1 5 ? 4 4 3 2 5 ? 3 3 2 5 ? 2 2 5 ? 3 5 1 6 ? 4 2 4 3 6 ? 3 4 3 6 ? 4 5 1 6 7 ? 4 2 4 3 7 ? 3 2 3 7 ? 2 2 7 ? 4 2 3 4 8 ? 3 2 3 8 ? 2 2 8 ? 5 5 1 7 6 8 ? 4 2 3 4 9 ? 3 2 4 9 ? 6 5 1 7 8 6 9 ? 7 5 1 7 8 9 6 10 ? 4 2 3 4 10 ? 3 2 3 10 ? 2 2 10 ! 14 1 2 1 3...
result:
wrong answer read 14 edges but expected 12 edges