結果
| 問題 | No.3719 Share the Tree |
| コンテスト | |
| ユーザー |
ぽえ
|
| 提出日時 | 2026-09-15 11:20:16 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 116 ms / 2,000 ms |
| + 1µs | |
| コード長 | 1,228 bytes |
| 記録 | |
| コンパイル時間 | 2,323 ms |
| コンパイル使用メモリ | 341,708 KB |
| 実行使用メモリ | 6,528 KB |
| 平均クエリ数 | 2.00 |
| 最終ジャッジ日時 | 2026-09-18 20:51:04 |
| 合計ジャッジ時間 | 6,332 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
string player; cin >> player;
int n; cin >> n;
cout << n-2 << endl;
if (player == "Alice") {
vector<vector<int>> g(n);
for (int i=0; i<n-1; i++) {
int x, y; cin >> x >> y; x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
vector<int> s(n); for (int i=0; i<n; i++) s[i] = g[i].size();
priority_queue<int, vector<int>, greater<int>> q; for (int i=0; i<n; i++) if (s[i] == 1) q.push(i);
vector<int> ans;
for (int i=0; i<n-2; i++) {
auto x = q.top(); q.pop();
for (auto& y : g[x]) if (s[y] != 0) {
ans.push_back(y);
s[x] = 0; s[y]--;
if (s[y] == 1) q.push(y);
break;
}
}
for (int i=0; i<n-2; i++) cout << ans[i]+1 << ' ';
cout << endl;
} else {
vector<int> a(n-2), s(n, 1); for (auto& i : a) { cin >> i; i--; }
for (auto& i : a) s[i]++;
priority_queue<int, vector<int>, greater<int>> q;
for (int i=0; i<n; i++) if (s[i] == 1) q.push(i);
for (auto& i : a) {
auto x = q.top(); q.pop();
cout << x+1 << ' ' << i+1 << endl;
s[x]--; s[i]--;
if (s[i] == 1) q.push(i);
}
{
auto x = q.top(); q.pop();
auto y = q.top(); q.pop();
cout << y+1 << ' ' << x+1 << endl;
}
}
}
ぽえ