結果
問題 | No.2565 はじめてのおつかい |
ユーザー | かもめのうで |
提出日時 | 2023-12-02 16:31:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,525 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,460 KB |
実行使用メモリ | 90,240 KB |
最終ジャッジ日時 | 2024-09-26 20:24:32 |
合計ジャッジ時間 | 8,139 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,504 KB |
testcase_01 | AC | 39 ms
54,016 KB |
testcase_02 | AC | 41 ms
53,760 KB |
testcase_03 | AC | 184 ms
90,240 KB |
testcase_04 | AC | 140 ms
90,240 KB |
testcase_05 | AC | 38 ms
53,888 KB |
testcase_06 | AC | 140 ms
79,660 KB |
testcase_07 | AC | 108 ms
78,088 KB |
testcase_08 | AC | 104 ms
79,140 KB |
testcase_09 | AC | 130 ms
79,484 KB |
testcase_10 | WA | - |
testcase_11 | AC | 167 ms
84,028 KB |
testcase_12 | AC | 94 ms
76,832 KB |
testcase_13 | AC | 112 ms
78,500 KB |
testcase_14 | AC | 132 ms
81,792 KB |
testcase_15 | WA | - |
testcase_16 | AC | 139 ms
85,632 KB |
testcase_17 | AC | 79 ms
76,952 KB |
testcase_18 | AC | 81 ms
79,232 KB |
testcase_19 | AC | 148 ms
82,384 KB |
testcase_20 | AC | 136 ms
82,432 KB |
testcase_21 | AC | 133 ms
82,452 KB |
testcase_22 | AC | 107 ms
80,560 KB |
testcase_23 | AC | 107 ms
80,064 KB |
testcase_24 | AC | 78 ms
77,684 KB |
testcase_25 | AC | 138 ms
82,688 KB |
testcase_26 | AC | 115 ms
79,596 KB |
testcase_27 | AC | 142 ms
82,856 KB |
testcase_28 | AC | 154 ms
82,432 KB |
testcase_29 | AC | 163 ms
85,208 KB |
testcase_30 | AC | 145 ms
83,584 KB |
testcase_31 | AC | 147 ms
82,688 KB |
testcase_32 | AC | 114 ms
80,128 KB |
testcase_33 | AC | 148 ms
82,944 KB |
testcase_34 | WA | - |
testcase_35 | AC | 151 ms
84,608 KB |
testcase_36 | AC | 154 ms
83,072 KB |
testcase_37 | AC | 113 ms
79,872 KB |
testcase_38 | AC | 157 ms
81,664 KB |
testcase_39 | AC | 140 ms
81,152 KB |
testcase_40 | AC | 155 ms
84,736 KB |
testcase_41 | AC | 169 ms
85,576 KB |
testcase_42 | AC | 121 ms
79,520 KB |
testcase_43 | AC | 141 ms
81,280 KB |
testcase_44 | AC | 109 ms
78,848 KB |
testcase_45 | AC | 89 ms
77,824 KB |
testcase_46 | AC | 142 ms
80,712 KB |
testcase_47 | AC | 118 ms
78,720 KB |
testcase_48 | AC | 113 ms
78,936 KB |
testcase_49 | AC | 91 ms
76,800 KB |
testcase_50 | AC | 130 ms
78,080 KB |
testcase_51 | AC | 41 ms
53,888 KB |
testcase_52 | AC | 107 ms
77,056 KB |
ソースコード
# n, m = map(int, input().split()) # c = list(map(int, input().split())) # cnt = [set() for _ in range(n)] # for i in range(n): # cnt[c[i]-1].add(i) # s = set() # edge = [0]*n # for _ in range(m): # v, u = map(int, input().split()) # v -= 1 # u -= 1 # if c[v] == c[u]: # if (v, u) not in s and (u, v) not in s: # edge[c[v]-1] += 1 # s.add((v, u)) # s.add((u, v)) # ans = 0 # for e, t in zip(edge, cnt): # if len(t) == 0: # continue # ans += max(len(t)-1-e, 0) # print(ans) n, m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): v, u = map(int, input().split()) v -= 1 u -= 1 g[v].append(u) from collections import deque def culc_dist(st: int, g: list): dist = [-1]*n q = deque() q.append(st) dist[st] = 0 while q: v = q.popleft() for nv in g[v]: if dist[nv] == -1: dist[nv] = dist[v] + 1 q.append(nv) return dist dist1 = culc_dist(0, g) dist2 = culc_dist(n-2, g) dist3 = culc_dist(n-1, g) if (dist1[n-2] == -1 or dist2[n-1] == -1 or dist3[0] == -1) and (dist3[n-3] == -1 or dist1[n-1] == -1 or dist2[0] == -1): print(-1) elif dist1[n-2] == -1 or dist2[n-1] == -1 or dist3[0] == -1: print(dist1[n-1]+dist3[n-2]+dist2[0]) elif dist3[n-3] == -1 or dist1[n-1] == -1 or dist2[0] == -1: print(dist1[n-2]+dist2[n-1]+dist3[0]) else: print(min(dist1[n-2]+dist2[n-1]+dist3[0], dist1[n-1]+dist3[n-2]+dist2[0]))