提出 #64057664
ソースコード 拡げる
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
std::vector<std::vector<int> > hen;
std::vector<int> depth;
void dfs(int i, int prev) {
for (auto j : hen[i]) if (j != prev) {
depth[j] = depth[i] + 1;
dfs(j, i);
}
}
int main() {
int n = ri();
hen.resize(n);
for (int i = 1; i < n; i++) {
int x = ri() - 1;
int y = ri() - 1;
hen[x].push_back(y);
hen[y].push_back(x);
}
depth.resize(n);
dfs(0, -1);
std::set<std::pair<int, int> > remaining;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) if ((depth[i] + depth[j]) % 2) remaining.insert({j, i});
}
for (int i = 0; i < n; i++) {
for (auto j : hen[i]) remaining.erase({i, j}), remaining.erase({j, i});
}
if (remaining.size() % 2) puts("First");
else puts("Second");
fflush(stdout);
while (1) {
if (remaining.size() % 2) {
assert(remaining.size());
printf("%d %d\n", remaining.begin()->first + 1, remaining.begin()->second + 1);
fflush(stdout);
remaining.erase(remaining.begin());
} else {
int x = ri() - 1;
int y = ri() - 1;
if (x == -2) break;
assert(remaining.count({x, y}) || remaining.count({y, x}));
remaining.erase({x, y});
remaining.erase({y, x});
}
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Tree Game |
| ユーザ | QCFium |
| 言語 | C++ 23 (gcc 12.2) |
| 得点 | 425 |
| コード長 | 1311 Byte |
| 結果 | AC |
| 実行時間 | 11 ms |
| メモリ | 4040 KiB |
コンパイルエラー
Main.cpp: In function ‘int ri()’:
Main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||
|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 425 / 425 | ||
| 結果 | AC |
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| hand_01.txt | AC | 3 ms | 3720 KiB |
| random_01.txt | AC | 11 ms | 3908 KiB |
| random_02.txt | AC | 11 ms | 3872 KiB |
| random_03.txt | AC | 10 ms | 4040 KiB |
| random_04.txt | AC | 10 ms | 3812 KiB |
| random_05.txt | AC | 10 ms | 3924 KiB |
| random_06.txt | AC | 11 ms | 3932 KiB |
| random_07.txt | AC | 11 ms | 4012 KiB |
| random_08.txt | AC | 10 ms | 3840 KiB |
| random_09.txt | AC | 3 ms | 3712 KiB |
| random_10.txt | AC | 4 ms | 3936 KiB |
| random_11.txt | AC | 3 ms | 3804 KiB |
| random_12.txt | AC | 4 ms | 3880 KiB |
| random_13.txt | AC | 5 ms | 3780 KiB |
| random_14.txt | AC | 6 ms | 3840 KiB |
| random_15.txt | AC | 5 ms | 3900 KiB |
| random_16.txt | AC | 6 ms | 3980 KiB |
| random_17.txt | AC | 10 ms | 3932 KiB |
| random_18.txt | AC | 11 ms | 3936 KiB |
| random_19.txt | AC | 11 ms | 3956 KiB |
| random_20.txt | AC | 10 ms | 3952 KiB |
| random_21.txt | AC | 7 ms | 3868 KiB |
| random_22.txt | AC | 3 ms | 3864 KiB |
| random_23.txt | AC | 3 ms | 3860 KiB |
| random_24.txt | AC | 4 ms | 3804 KiB |
| random_25.txt | AC | 3 ms | 3724 KiB |
| random_26.txt | AC | 9 ms | 4020 KiB |
| random_27.txt | AC | 9 ms | 3976 KiB |
| random_28.txt | AC | 3 ms | 3924 KiB |