QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#655673 | #9484. Colored Complete Graph | AFewSuns Fan Club (Ruixi Wan, Hengfei Dai, Jiaxian Xie)# | TL | 0ms | 0kb | C++14 | 1.4kb | 2024-10-19 09:07:35 | 2024-10-19 09:07:40 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;
const int N = 5e4 + 5;
int n, to[N];
vector<int> o[2], g[N][2];
int q(int u, int v) {
cout << "! " << u << ' ' << v << '\n', fflush(stdout);
char c; cin >> c;
return c == 'R' ? 0 : 1;
}
void add(int u, int v, int o) {
g[u][o].eb(v), g[v][o].eb(u);
}
void solve() {
cin >> n;
F (i, 2, n) {
int c = q(1, i);
add(1, i, c);
o[c].eb(i);
}
int cur = 0;
while (!o[cur ^ 1].empty()) {
int u = o[cur].back();
while (!o[cur ^ 1].empty() && q(u, o[cur ^ 1].back()) == cur)
add(u, o[cur ^ 1].back(), cur), o[cur ^ 1].pop_back();
if (!o[cur ^ 1].empty()) add(u, o[cur ^ 1].back(), cur ^ 1), o[cur].pop_back(), cur ^= 1;
}
cout << "!\n";
F (i, 1, n)
for (int j : g[i][cur])
if (i < j) cout << i << ' ' << j << '\n';
}
bool Med;
int main() {
// FIO("");
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
int T = 1;
// cin >> T;
while (T--) solve();
// cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3
output:
! 1 2