結果

問題 No.2563 色ごとのグループ
ユーザー chaemonchaemon
提出日時 2023-12-02 15:17:45
言語 Nim
(2.0.2)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 16,228 bytes
コンパイル時間 5,417 ms
コンパイル使用メモリ 95,488 KB
実行使用メモリ 28,160 KB
最終ジャッジ日時 2024-09-26 18:24:12
合計ジャッジ時間 9,188 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 76 ms
12,544 KB
testcase_25 AC 70 ms
13,568 KB
testcase_26 AC 104 ms
18,816 KB
testcase_27 AC 115 ms
27,008 KB
testcase_28 AC 123 ms
20,608 KB
testcase_29 AC 166 ms
28,032 KB
testcase_30 AC 161 ms
28,032 KB
testcase_31 AC 173 ms
28,160 KB
testcase_32 AC 163 ms
27,904 KB
testcase_33 AC 209 ms
25,472 KB
testcase_34 AC 218 ms
24,064 KB
testcase_35 AC 211 ms
24,320 KB
testcase_36 AC 216 ms
25,472 KB
testcase_37 AC 213 ms
25,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import macros
macro Please(x): untyped = nnkStmtList.newTree()

Please use Nim-ACL
Please use Nim-ACL
Please use Nim-ACL


static:
  when not defined SecondCompile:
    # md5sum: 98981870bc02ae70ef8434588707ba34  atcoder.tar.xz

    template getFileName():string = instantiationInfo().filename
    let fn = getFileName()
    block:
      let (output, ex) = gorgeEx("if [ -e ./atcoder ]; then exit 1; else exit 0; fi")
      # doAssert ex == 0, "atcoder directory already exisits"
    discard staticExec("echo \"/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4O//KPhdADCdCIqmAHyeLmzPetXzWpgQcDgKgJF+nO8CaeoEXtTnzoPMLTNbu+bsJrT6J0XXB4A/nh1fzToAtdHLWtjqboHwf+xmMaDJs0iYITLVMB+bWALP6qdO+DUw5FlP0RIG6+vGnxArxOCa6Xg9MkzydUh+9S7h0KmG92tl5NKS/IBroXRRLMJ/Ih1E9Wo4//TZ0ueFi2zGhCXmRnrHxg0zCF78FJB9LyN0VWYWCXVAUJ9xSe1+Cj01G8WXhBJAOucideFBSuCcS6pFEImJx4MxT5G55IGTpH11gZUOlkEZvybnvHPWk8iA3G7XWxETRhRWFvdux9NmterJI+enGt9y9XrHTcqDfjsBf6HAGAvQ90FzaAHtz+zpOvnTFd47iXvhdBt3niKrJLuCjYsh2B9JZKEGbRnd+z2+EmeTrg1ixoGV40rT+zr9n5jFXK8kj6JS60QujRfBGe8eTXW+4cfEN87ok2BVjpwEMJvCJA9PCJC1+IIJaP0J32cgV2YQhvoLMMCWdT2dl4Yw95vHO5rjH0B+jzjbNsrkVvmmUJwQTXu02OHZRi8pRNsBsD1BSV+tOxkp3yWShU3tt88GMyZIOIfXF8vrWjtj9ZK/VYdljjTZLnDlim/mhPfszsyNTK9DzADW3rRLUjLYc80IcwxFE/aufV7S6LIM53KKUzkMdSpJfJ6+0Si+qYdQrON2T9oggKn6Lr40sU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EI9JCUcjqNFvjrc0vtTdhui+nJUyfaXelF28+5azAAtK0WEoha7lJkozhzB7wnesjnSHvuXAayJVb94dDxKInglaO4frI1v+c58FGum0QEaYYFJHF1ur5BFPAhmiGkOHz0tscnk+qINqc2a4nuGpCFew4Lpmy8gMyikO6PxkiGttTImW37yZup97F9ENDz5gzZ55PqRpLUcdXo12txfxKsaTo0uGkV5ORr4PEUYYyBGUStp3oPpeUa+NfsqygzyejtzRU7wU27B6L7e+R9HPhK4CqwuQnaXlKw50PHFgbHr6bNn0uF2sx0V0OhrMCroZrt9PvntJ8sgkrOLmIwDLIhvlG770NwABlFKA4AMAeynnaLHEZ/sCAAAAAARZWg==\" | base64 -d > atcoder.tar.xz && tar -Jxvf atcoder.tar.xz")
    let (output, ex) = gorgeEx("nim cpp -d:release -d:SecondCompile -d:danger --path:./ --opt:speed --multimethods:on --warning[SmallLshouldNotBeUsed]:off --checks:off -o:a.out " & fn)
    discard staticExec("rm -rf ./atcoder");doAssert ex == 0, output;quit(0)


when defined SecondCompile:
  const DO_CHECK = false;const DEBUG = false
else:
  const DO_CHECK = true;const DEBUG = false
const
  USE_DEFAULT_TABLE = true
  DO_TEST = false

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/header/chaemon_header.nim
include atcoder/extra/header/chaemon_header


# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/dsu.nim
import atcoder/dsu


proc solve() =
  # 色ごとにDSUを作る
  let N, M = nextInt()
  var
    C = Seq[N: nextInt() - 1]
    col_ct = Seq[N: seq[int]]
    node_to_colid = Seq[N: int]
  for i in N:
    node_to_colid[i] = col_ct[C[i]].len
    col_ct[C[i]].add i
  debug node_to_col_id, col_ct
  var ds = Seq[DSU]
  for i in N:
    ds.add initDSU(col_ct[i].len)
  ans := 0
  for _ in M:
    var u, v = nextInt() - 1
    if C[u] != C[v]: continue
    let
      c = C[u]
      ui = node_to_colid[u]
      vi = node_to_colid[v]
    debug c, ui, vi
    if ds[c].leader(ui) != ds[c].leader(vi):
      ds[c].merge(ui, vi)
  for i in N:
    for j in col_ct[i].len - 1:
      let
        u = col_ct[i][j]
        v = col_ct[i][j + 1]
        c = C[u]
        ui = node_to_colid[u]
        vi = node_to_colid[v]
      if ds[c].leader(ui) != ds[c].leader(vi):
        ans.inc
        ds[c].merge(ui, vi)
  echo ans
  discard

solve()

0