Submission #64086347
Source Code Expand
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
vector<vector<int>> adj;
vector<int> color;
bool dfs(int u, int c) {
color[u] = c;
for (int v : adj[u]) {
if (color[v] == -1) {
if (!dfs(v, 1 - c)) return false;
} else if (color[v] == c) {
return false;
}
}
return true;
}
int main() {
int n;
cin >> n;
adj.resize(n + 1);
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
color.assign(n + 1, -1);
dfs(1, 0);
int a = 0, b = 0;
for (int i = 1; i <= n; ++i) {
if (color[i] == 0) a++;
else b++;
}
int cnt = a * b - (n - 1);
if (cnt % 2 == 1) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
cout << flush;
while (true) {
int i, j;
for (i = 1; i <= n; ++i) {
for (j = i + 1; j <= n; ++j) {
if (color[i] != color[j]) {
bool has_edge = false;
for (int v : adj[i]) {
if (v == j) {
has_edge = true;
break;
}
}
if (!has_edge) {
cout << i << " " << j << endl;
cout << flush;
goto read_opponent;
}
}
}
}
read_opponent:
int x, y;
cin >> x >> y;
if (x == -1 && y == -1) break;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Tree Game |
| User | yyyyt |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1732 Byte |
| Status | TLE |
| Exec Time | 2210 ms |
| Memory | 3904 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 425 | ||||
| Status | AC |
|
| Set Name | Test Cases |
|---|---|
| Sample | |
| All | hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 3 ms | 3812 KiB |
| random_01.txt | TLE | 2208 ms | 3900 KiB |
| random_02.txt | TLE | 2207 ms | 3756 KiB |
| random_03.txt | TLE | 2207 ms | 3904 KiB |
| random_04.txt | TLE | 2208 ms | 3900 KiB |
| random_05.txt | TLE | 2207 ms | 3836 KiB |
| random_06.txt | TLE | 2207 ms | 3664 KiB |
| random_07.txt | TLE | 2207 ms | 3700 KiB |
| random_08.txt | TLE | 2207 ms | 3840 KiB |
| random_09.txt | AC | 3 ms | 3796 KiB |
| random_10.txt | TLE | 2210 ms | 3660 KiB |
| random_11.txt | AC | 4 ms | 3696 KiB |
| random_12.txt | TLE | 2207 ms | 3564 KiB |
| random_13.txt | TLE | 2207 ms | 3564 KiB |
| random_14.txt | TLE | 2207 ms | 3740 KiB |
| random_15.txt | TLE | 2207 ms | 3720 KiB |
| random_16.txt | TLE | 2210 ms | 3684 KiB |
| random_17.txt | TLE | 2208 ms | 3760 KiB |
| random_18.txt | TLE | 2208 ms | 3752 KiB |
| random_19.txt | TLE | 2207 ms | 3776 KiB |
| random_20.txt | TLE | 2207 ms | 3812 KiB |
| random_21.txt | TLE | 2208 ms | 3752 KiB |
| random_22.txt | TLE | 2208 ms | 3600 KiB |
| random_23.txt | AC | 3 ms | 3788 KiB |
| random_24.txt | TLE | 2207 ms | 3644 KiB |
| random_25.txt | TLE | 2207 ms | 3632 KiB |
| random_26.txt | TLE | 2207 ms | 3748 KiB |
| random_27.txt | TLE | 2207 ms | 3740 KiB |
| random_28.txt | TLE | 2208 ms | 3604 KiB |