結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー dot_haraaidot_haraai
提出日時 2021-04-01 22:11:21
言語 Nim
(2.0.2)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 2,279 bytes
コンパイル時間 5,328 ms
コンパイル使用メモリ 76,000 KB
実行使用メモリ 30,148 KB
最終ジャッジ日時 2023-08-23 06:10:30
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 12 ms
6,216 KB
testcase_14 AC 12 ms
5,788 KB
testcase_15 AC 12 ms
5,792 KB
testcase_16 AC 12 ms
6,200 KB
testcase_17 AC 12 ms
6,008 KB
testcase_18 AC 39 ms
11,768 KB
testcase_19 AC 39 ms
12,328 KB
testcase_20 AC 66 ms
12,264 KB
testcase_21 AC 112 ms
15,364 KB
testcase_22 AC 143 ms
20,092 KB
testcase_23 AC 161 ms
30,148 KB
testcase_24 AC 148 ms
29,180 KB
testcase_25 AC 170 ms
29,104 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]

ソースコード

diff #

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()
  
0