QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#497092 | #4218. Hidden Graph | PZheng | RE | 1ms | 3752kb | C++14 | 1.9kb | 2024-07-28 18:58:50 | 2024-07-28 18:58:51 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <random>
#include <chrono>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
int tot = 0;
int q(int x, vector<int>& vis, int co, vector<int>& col) {
int cnt = 1;
for(int i = 1; i <= x; i++)
cnt += col[i] == co && !vis[i];
if(cnt == 1)
return -1;
cout << "? " << cnt << " ";
for(int i = 1; i <= x; i++)
if(col[i] == co && !vis[i])
cout << i << " ";
cout << x << endl;
int r1, r2;
cin >> r1 >> r2;
if(r1 == -1)
return r1;
return r1 + r2 - x;
}
void solve() {
int n;
cin >> n;
vector<array<int, 2>> ans;
vector<int> deg(n + 1, 0);
vector<vector<int>> e(n + 1);
auto add = [&](int u, int v) {
e[u].push_back(v);
e[v].push_back(u);
deg[u]++;
deg[v]++;
};
vector<int> col(n + 1, 0);
auto co = [&](int x) {
vector<int> b(x);
col = vector<int>(n + 1, 0);
for(int i = 1; i <= x; i++) {
tot = max(tot, deg[i] + 1);
b[i - 1] = i;
sort(b.begin(), b.end(), [&](int u, int v){
return deg[u] > deg[v];
});
}
for(int i = 1; i <= tot; i++)
for(auto u : b) {
if(col[u])
continue;
bool flag = 1;
for(auto v : e[u]) {
if(col[v] == i)
flag = 0;
}
if(flag)
col[u] = i;
}
};
for(int i = 1; i <= n; i++) {
vector<int> vis(n + 1, 0);
for(int j = 1; j <= tot; j++) {
int now = q(i, vis, j, col);
while(now != -1) {
vis[now] = 1;
add(i, now);
ans.push_back({now, i});
now = q(i, vis, j, col);
}
}
co(i);
}
cout << "! " << ans.size() << endl;
for(auto x : ans)
cout << x[0] << ' ' << x[1] << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
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: 3612kb
input:
10 1 2 1 3 -1 -1 1 4 -1 -1 -1 -1 2 5 4 5 -1 -1 -1 -1 2 6 -1 -1 -1 -1 3 7 -1 -1 -1 -1 4 8 3 8 -1 -1 -1 -1 3 9 -1 -1 3 10 4 10 -1 -1 -1 -1
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ? 2 1 4 ? 3 2 3 4 ? 2 1 5 ? 4 2 3 4 5 ? 3 3 4 5 ? 2 3 5 ? 3 1 5 6 ? 4 2 3 4 6 ? 3 3 4 6 ? 4 1 5 6 7 ? 4 2 3 4 7 ? 3 2 4 7 ? 5 1 5 6 7 8 ? 4 2 3 4 8 ? 3 2 3 8 ? 2 2 8 ? 6 1 5 6 7 8 9 ? 4 2 3 4 9 ? 3 2 4 9 ? 4 2 3 4 10 ? 3 2 4 10 ? 2 2 10 ? 7 1 5 6 7 8 9 10 ! 12 1 2 1 3 1 4 2 5...
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
5 2 1 3 1 3 2 4 1 4 2 -1 -1 5 1 5 2 -1 -1
output:
? 2 1 2 ? 2 1 3 ? 2 2 3 ? 2 1 4 ? 2 2 4 ? 2 3 4 ? 2 1 5 ? 2 2 5 ? 3 3 4 5 ! 7 1 2 1 3 2 3 1 4 2 4 1 5 2 5
result:
ok correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 3588kb
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: 1ms
memory: 3624kb
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