QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497072#4218. Hidden GraphPZhengWA 0ms3660kbC++141.9kb2024-07-28 18:46:392024-07-28 18:46:40

Judging History

你现在查看的是最新测评结果

  • [2024-07-28 18:46:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-07-28 18:46:39]
  • 提交

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(n);
		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) {
				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> pos;
		vector<int> vis(n + 1, 0);
		for(int j = 1; j <= tot; j++) {
			int now = q(i, vis, j, col);
			if(now == -1)
				pos.push_back(j);
			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: 0
Wrong Answer
time: 0ms
memory: 3660kb

input:

3
1 2
1 3

output:

? 2 1 2
? 2 1 3
! 2
1 2
1 3

result:

wrong answer read 2 edges but expected 3 edges