結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | dot_haraai |
提出日時 | 2021-04-01 22:11:21 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 2,279 bytes |
コンパイル時間 | 4,174 ms |
コンパイル使用メモリ | 89,404 KB |
実行使用メモリ | 19,468 KB |
最終ジャッジ日時 | 2024-06-01 03:53:48 |
合計ジャッジ時間 | 6,311 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 11 ms
6,940 KB |
testcase_14 | AC | 11 ms
6,944 KB |
testcase_15 | AC | 11 ms
6,944 KB |
testcase_16 | AC | 11 ms
6,944 KB |
testcase_17 | AC | 11 ms
6,944 KB |
testcase_18 | AC | 32 ms
7,808 KB |
testcase_19 | AC | 33 ms
9,344 KB |
testcase_20 | AC | 50 ms
9,728 KB |
testcase_21 | AC | 81 ms
11,904 KB |
testcase_22 | AC | 115 ms
14,592 KB |
testcase_23 | AC | 132 ms
19,340 KB |
testcase_24 | AC | 120 ms
19,468 KB |
testcase_25 | AC | 122 ms
19,344 KB |
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport] /home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport] /home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport] /home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport] /home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [UnusedImport] /home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport] /home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport] /home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]
ソースコード
import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc getLowLink(G:seq[seq[int]],start:int=0):(seq[int],seq[(int,int)])= var N = G.len order = newseqwith(N,-1) used = newseqwith(N,false) loww = newseqwith(N,0) acP = newseq[int]() bridge = newseq[(int,int)]() proc dfs(idx, k, par:int):int= var k = k isA = false cnt = 0 used[idx]=true order[idx]=k k+=1 loww[idx]=order[idx] for nxt in G[idx]: if not used[nxt]: cnt+=1 k = dfs(nxt,k,idx) loww[idx].min=loww[nxt] isA = isA or ( par != -1 and (loww[nxt] >= order[idx])) if order[idx]<loww[nxt]: bridge.add((min(idx,nxt),max(idx,nxt))) elif nxt != par: loww[idx].min=order[nxt] isA = isA or (par == -1 and cnt>1) if isA: acP.add(idx) return k proc build()= var k = 0 for i in 0..<N: if not used[i]: k = dfs(i,k,-1) build() return (acP, bridge) var case1 = @[ @[1], @[0,2], @[1,3], @[2] ] case2 = @[ @[1], @[0,2], @[1] ] #echo getLowLink(case2) proc solve():string= var n = scan() es = newseqwith(n,newseq[int]()) q = initDeque[int]() cnt = 0 touched = newseqwith(n,-1) for i in 0..<n-1: var f = scan() t = scan() es[f].add(t) es[t].add(f) var (acP,bridge)=getlowlink(es) for i in 0..<n: #echo i, ", ", touched[i] if touched[i]<0: touched[i]=cnt q.addLast(i) while q.len>0: var p = q.popFirst() for nxt in es[p]: if touched[nxt]<0: touched[nxt]=cnt q.addLast(nxt) cnt+=1 if cnt+min(1,bridge.len)>=3: return "Alice" else: return "Bob" echo solve()