結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー maguroflymagurofly
提出日時 2024-06-20 16:36:34
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 12,845 ms
コンパイル使用メモリ 402,744 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-06-20 16:36:56
合計ジャッジ時間 12,409 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 0 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 WA -
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 WA -
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 20 ms
9,216 KB
testcase_22 AC 25 ms
11,264 KB
testcase_23 AC 26 ms
11,776 KB
testcase_24 AC 25 ms
11,776 KB
testcase_25 AC 32 ms
11,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `N` should have a snake case name
 --> src/main.rs:5:3
  |
5 |         N: usize,
  |         ^ help: convert the identifier to snake case: `n`
  |
  = note: `#[warn(non_snake_case)]` on by default

ソースコード

diff #

const TAKANA: bool = true;

fn main() {
	proconio::input! {
		N: usize,
		edges: [(usize, usize); N - 1],
	}
	
	let mut graph = vec![vec![]; N];
	for &(u, v) in &edges {
		graph[u].push(v);
		graph[v].push(u);
	}
	
	let mut visited = vec![false; N];
	let mut stack = vec![];
	for s in 0 .. N {
		if visited[s] == TAKANA {
			continue;
		}
		let mut size = 0;
		visited[s] = TAKANA;
		stack.push(s);
		while let Some(u) = stack.pop() {
			size += 1;
			for &v in &graph[u] {
				if visited[v] == TAKANA {
					continue;	
				}
				// 歩いた跡に高菜を生やしていく
				visited[v] = TAKANA;
				stack.push(v);
			}
		}
		if size <= 2 {
			println!("Alice");
			return;
		}
	}
	println!("Bob");
}
0