Submission #58222530


Source Code Expand

import sys

sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
a = [0] * n
adj = [[] for i in range(n)]
edges = []
for i in range(m):
    x, y, w = map(int, input().split())
    edges.append((x, y, w))
    adj[x - 1].append((y - 1, w))
    adj[y-1].append((x-1, -w))

vis = [0] * n

from collections import deque
def bfs(start):
  q=deque([start])
  vis[start]=1
  while q:
      x = q.popleft()
      for y, w in adj[x]:
          if not vis[y]:
              a[y] = a[x] + w
              q.append(y)
              vis[y] = 1

for i in range(n):
    if not vis[i]:
        bfs(i)

print(*a)

Submission Info

Submission Time
Task D - Hidden Weights
User decsp
Language Python (PyPy 3.10-v7.3.12)
Score 400
Code Size 638 Byte
Status AC
Exec Time 421 ms
Memory 163520 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 67 ms 76932 KiB
00_sample_02.txt AC 68 ms 77220 KiB
00_sample_03.txt AC 67 ms 77268 KiB
01_random_01.txt AC 211 ms 115676 KiB
01_random_02.txt AC 354 ms 150176 KiB
01_random_03.txt AC 371 ms 147460 KiB
01_random_04.txt AC 394 ms 156660 KiB
01_random_05.txt AC 137 ms 95504 KiB
01_random_06.txt AC 290 ms 128120 KiB
01_random_07.txt AC 396 ms 153968 KiB
01_random_08.txt AC 400 ms 157548 KiB
01_random_09.txt AC 149 ms 99520 KiB
01_random_10.txt AC 345 ms 144744 KiB
01_random_11.txt AC 356 ms 145716 KiB
01_random_12.txt AC 421 ms 156996 KiB
01_random_13.txt AC 180 ms 103660 KiB
01_random_14.txt AC 403 ms 155652 KiB
01_random_15.txt AC 374 ms 145112 KiB
01_random_16.txt AC 404 ms 157508 KiB
01_random_17.txt AC 223 ms 116916 KiB
01_random_18.txt AC 300 ms 131120 KiB
01_random_19.txt AC 302 ms 136960 KiB
01_random_20.txt AC 396 ms 157144 KiB
02_handmade_01.txt AC 394 ms 159584 KiB
02_handmade_02.txt AC 381 ms 158648 KiB
02_handmade_03.txt AC 367 ms 158712 KiB
02_handmade_04.txt AC 301 ms 163520 KiB
02_handmade_05.txt AC 146 ms 104692 KiB
02_handmade_06.txt AC 247 ms 154044 KiB