結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー |
![]() |
提出日時 | 2020-02-26 23:49:03 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 719 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 31,744 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 15:37:24 |
合計ジャッジ時間 | 1,267 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<stdio.h> int p[100005]; int root(int n) { if (p[n] != n) p[n] = root(p[n]); return p[n]; } void uni(int x, int y) { x = root(x); y = root(y); if (x != y) p[x] = y; return; } int main() { int n; scanf("%d", &n); int u, v; int i; for (i = 0; i < n; i++) p[i] = i; int q[100005]; for (i = 0; i < n; i++) q[i] = 0; for (i = 0; i < n - 1; i++) { scanf("%d %d", &u, &v); uni(u, v); q[u]++; q[v]++; } int c = 0; for (i = 0; i < n; i++) if (root(i) == i) c++; if (c == 1) printf("Bob\n"); else if (c > 2) printf("Alice\n"); else { c = 0; for (i = 0; i < n; i++) if (q[i] != 2) c++; if (c != 1) printf("Alice\n"); else printf("Bob\n"); } return 0; }