QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657861 | #9484. Colored Complete Graph | ucup-team4975# | RE | 0ms | 3588kb | C++23 | 2.8kb | 2024-10-19 15:35:48 | 2024-10-19 15:35:49 |
Judging History
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
char getcol()
{
/*int res = rng() % 2;
if (res == 0)
return 'R';
return 'B';*/
char col;
cin >> col;
return col;
}
void solve()
{
int n;
cin >> n;
vector<PII> edge1;
vector<PII> edge2;
for (int i = 1; i <= n; i++) {
int nxt1 = i + 1, nxt2 = i + 2;
if (nxt1 > n)
nxt1 -= n;
if (nxt2 > n)
nxt2 -= n;
cout << "? " << i << " " << nxt1 << endl;
char col;
col = getcol();
if (col == 'R') {
edge1.push_back(PII(i, nxt1));
}
else {
edge2.push_back(PII(i, nxt1));
}
cout << "? " << i << " " << nxt2 << endl;
// cin >> col;
col = getcol();
if (col == 'R') {
edge1.push_back(PII(i, nxt2));
}
else {
edge2.push_back(PII(i, nxt2));
}
}
vector<int> f(n + 1, 0);
for (int i = 1; i <= n; i++) {
f[i] = i;
}
function<int(int)> find = [&](int x) {
if (x == f[x])
return x;
return f[x] = find(f[x]);
};
int cnt = 0;
vector<PII> ans;
/*for (auto [x, y] : edge1) {
cout << x << " " << y << endl;
}*/
for (int i = 0; i < edge1.size(); i++) {
int x = edge1[i].fir;
int y = edge1[i].sec;
x = find(x);
y = find(y);
if (x == y) {
continue;
}
f[y] = x;
cnt++;
ans.push_back(edge1[i]);
}
if (cnt == n - 1) {
cout << "!" << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].fir << " " << ans[i].sec << endl;
}
return;
}
ans.clear();
for (int i = 1; i <= n; i++) {
f[i] = i;
}
cnt = 0;
for (int i = 0; i < edge2.size(); i++) {
int x = edge2[i].fir;
int y = edge2[i].sec;
x = find(x);
y = find(y);
if (x == y) {
continue;
}
f[y] = x;
cnt++;
ans.push_back(edge2[i]);
}
assert(cnt == n - 1);
cout << "!" << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].fir << " " << ans[i].sec << endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
// FINISH
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 B R B B R B
output:
? 1 2 ? 1 3 ? 2 3 ? 2 1 ? 3 1 ? 3 2 ! 1 2 2 3
result:
ok AC
Test #2:
score: -100
Runtime Error
input:
983 B R R B B B B B B B B R B R R R R R R R R R R R R B B R R B R B R R R B B R B R R R R R R B R B B B B R R R R B B R R B R B R B B B B R B R R B R B B R R R R B B B B B B R B R R B R B B R B R B R B R R R R B B B B R R B B B B R R B R B B B B R B B B R R B B R R R R R R B R R R B B B B R B B B B ...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 3 5 ? 4 5 ? 4 6 ? 5 6 ? 5 7 ? 6 7 ? 6 8 ? 7 8 ? 7 9 ? 8 9 ? 8 10 ? 9 10 ? 9 11 ? 10 11 ? 10 12 ? 11 12 ? 11 13 ? 12 13 ? 12 14 ? 13 14 ? 13 15 ? 14 15 ? 14 16 ? 15 16 ? 15 17 ? 16 17 ? 16 18 ? 17 18 ? 17 19 ? 18 19 ? 18 20 ? 19 20 ? 19 21 ? 20 21 ? 20 22 ? 21 22 ? 21 ...