s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s638063635 | p03767 | u623819879 | 1558024317 | Python | PyPy3 (2.4.0) | py | Runtime Error | 326 | 121952 | 88 | n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2]) |
s602387895 | p03767 | u623819879 | 1558023923 | Python | PyPy3 (2.4.0) | py | Runtime Error | 167 | 38384 | 82 | n=int(input())
a=[int(i) in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2]) |
s585166764 | p03767 | u623819879 | 1558023908 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38256 | 81 | n=int(input())
a=[int(i) in input().split()]
a=a.sort()[::-1]
print(sum[1:2*n:2]) |
s016169004 | p03767 | u623819879 | 1558023857 | Python | PyPy3 (2.4.0) | py | Runtime Error | 165 | 38448 | 79 | n=int(input())
a=[int(i) in input().split()]
a.sort()[::-1]
print(sum[1:2*n:2]) |
s383635325 | p03767 | u808373096 | 1558021160 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38384 | 81 | N = int(input())
A = sorted(list(map(int, input().split())))
print(sum(A[N:2*N])
|
s094794928 | p03767 | u808373096 | 1558021104 | Python | PyPy3 (2.4.0) | py | Runtime Error | 262 | 38256 | 74 | N = int(input())
A = sorted(map(int, input().split()))
print(sum(A[N:2*N]) |
s247272293 | p03767 | u066455063 | 1557276731 | Python | Python (3.4.3) | py | Runtime Error | 2113 | 155996 | 495 | N = int(input())
a = list(map(int, input().split()))
ans = 0
def quicksort(seq):
if len(seq) < 1:
return seq
pivot = seq[0]
left = []
right = []
for x in range(1, len(seq)):
if seq[x] <= pivot:
left.append(seq[x])
else:
right.append(seq[x])
left = quicksort(left)
right = quicksort(right)
foo = [pivot]
return left + foo + right
a = quicksort(a)
for i in range(N):
ans += a[-2]
a = a[1:-2]
print(ans) |
s987730425 | p03767 | u411544692 | 1554782666 | Python | Python (3.4.3) | py | Runtime Error | 210 | 39492 | 95 | N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
print(sum(A[1::2][N])) |
s790940139 | p03767 | u865413330 | 1552323814 | Python | Python (3.4.3) | py | Runtime Error | 2186 | 1602268 | 194 | n = int(input())
l = list(map(int, input().split()))
l.sort()
def calc(l):
if len(l) == 3:
return l[1]
power = l[-2]
l = l[1:-2]
return calc(l) + power
print(calc(l))
|
s047807063 | p03767 | u865413330 | 1552323750 | Python | Python (3.4.3) | py | Runtime Error | 2184 | 1602268 | 193 | n = int(input())
l = list(map (int, input().split()))
l.sort()
def calc(l):
if len(l) == 3:
return l[1]
power = l[-2]
l = l[1:-2]
return calc(l) + power
print(calc(l)) |
s255313464 | p03767 | u865413330 | 1552322925 | Python | Python (3.4.3) | py | Runtime Error | 2185 | 1604316 | 193 | n = int(input())
l = list(map (int, input().split()))
l.sort()
def calc(l):
if len(l) == 3:
return l[1]
power = l[-2]
l = l[1:-2]
return calc(l) + power
print(calc(l)) |
s893944394 | p03767 | u865413330 | 1552322746 | Python | Python (3.4.3) | py | Runtime Error | 2188 | 1604572 | 175 | n = int(input())
l = list(map (int, input().split()))
l.sort()
def calc(l):
if len(l) == 3:
return l[1]
l = l[1:-2]
return calc(l) + l[-2]
print(calc(l)) |
s314420430 | p03767 | u785578220 | 1551612574 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 120 | a =int(input())
x =list(map(int, input().split()))
x.sort()
s=0
for i in reversed(range(0,a//3,1):
s+=x[i+1]
print(s)
|
s411158797 | p03767 | u785578220 | 1551611785 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 122 | a =int(input())
x =list(map(int, input().split()))
x.sort()
s=0
for i in reversed(range(1,(a+1)//3,1):
s+=x[i]
print(s)
|
s769085937 | p03767 | u785578220 | 1551603633 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 117 | a =int(input())
x =list(map(int, input().split()))
x.sort()
s=0
for I in reversed(range(1,a//3,1):
s+=x[i]
print(s) |
s919679686 | p03767 | u631238602 | 1546293907 | Python | Python (3.4.3) | py | Runtime Error | 49 | 27612 | 104 | n = int(input())
arr = map(int, input().strip().split())
arr.sort(reverse=True)
print(sum(arr[1:2*n:2])) |
s751137150 | p03767 | u816116805 | 1541962292 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 715 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
"""
agc012 C
"""
n, m = map(int, input().split())
graph = [[] for i in range(n+1)]
for i in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
q = int(input())
qlist = [tuple(map(int, input().split())) for i in range(q)]
qlist.reverse()
dp = [[-1]*11 for i in range(n+1)]
col = [0]
def updatedp(v, t, d):
if dp[v][d] == -1:
dp[v][d] = t
if d > 0:
updatedp(v, t, d-1)
for u in graph[v]:
updatedp(u, t, d-1)
t = 0
for v, d, c in qlist:
col.append(c)
updatedp(v, t, d)
t += 1
for i in range(1, n+1):
print(col[dp[i][0]+1])
|
s355842979 | p03767 | u064408584 | 1540948930 | Python | Python (3.4.3) | py | Runtime Error | 262 | 37084 | 211 | n=int(input())
a=list(map(int, input().split()))
a.sort()
m=a[n:2*n]
ans=sum(m)
for i in range(0,n,2):
if m[i]+m[i+1]<=a[2*n+i]+a[n-i-1]:
ans+= a[2*n+i]+a[n-i-1]-m[i]-m[i+1]
else:break
print(ans) |
s301206195 | p03767 | u366644013 | 1534444040 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 79 | n = int(input)
a = sorted(list(map(int, input().split())))
print(sum(a[n:3*n])) |
s705527930 | p03767 | u366644013 | 1534443988 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 78 | n = int(input)
a = sorted(list(map(int, input().split())))
print(sum(a[n:3n])) |
s820943191 | p03767 | u366644013 | 1534443952 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 77 | n = int(input)
a = sorted(list(map(int, input().split())))
print(sum(a[n:3])) |
s185776241 | p03767 | u918928910 | 1514687944 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1069 | for t in range(1):
graph = {}
colors = {}
n, m = list(map(int, input().split()))
for i in range(m):
a, b = list(map(int, input().split()))
if a not in graph:
graph[a] = [b]
else:
graph[a].append(b)
if b not in graph:
graph[b] = [a]
else:
graph[b].append(a) #Generating the graph as a dictionary.
colors[a] = 0
colors[b] = 0 #Generating a colors dictionary to record color of each vertex.
for q in range(int(input())):
v, d, c = list(map(int, input().split()))
first, sec = [v], []
colors[v] = c
for level in range(d):
for i in first:
for j in graph[i]:
sec.append(j)
colors[j] = c
first, sec = sec, [] #Loop to color all vertices within d distance of given vertex v with color c.
for i in range(1, n+1):
print(colors[i])# your code goes here |
s491551451 | p03767 | u596276291 | 1512600282 | Python | PyPy3 (2.4.0) | py | Runtime Error | 250 | 41200 | 1333 | import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
color, depth, graph = [], [], {}
def func(v, d, c):
if not color[v]:
color[v] = c
if depth[v] >= d or d == 0:
return
for u in graph[v]:
func(u, d - 1, c)
def main():
global color, depth, graph
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
Q = int(input())
q = []
for _ in range(Q):
v, d, c = map(int, input().split())
q.append((v - 1, d, c))
color = [0] * N
depth = [0] * N
for i in range(Q - 1, -1, -1):
func(q[i][0], q[i][1], q[i][2])
print(*color, sep="\n")
if __name__ == '__main__':
main()
|
s850821103 | p03767 | u556160473 | 1492562364 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 332 | 10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 |
s191448718 | p03767 | u602860891 | 1491665618 | Python | Python (3.4.3) | py | Runtime Error | 262 | 37084 | 456 |
def main():
N = int(input())
a_list = get_a_list()
a_list.sort(reverse=True)
sum_second_a = 0
import pdb; pdb.set_trace()
while len(a_list) > 0:
a_list.pop(0)
sum_second_a += a_list.pop(0)
a_list.pop(-1)
print(sum_second_a)
def get_a_list():
a_list = []
strs = input().split()
for a in strs:
a_list.append(int(a))
return a_list
if __name__ == '__main__':
main()
|
s127703551 | p03767 | u026450699 | 1491230703 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 181 | N = int(raw_input())
list = map(int, raw_input().split(" "))
list.sort(reverse=True)
total = 0
unit = len(list) / 3
for i in range(unit, unit * 2):
total += list[i]
print total
|
s526044905 | p03767 | u209551477 | 1491184895 | Python | PyPy3 (2.4.0) | py | Runtime Error | 170 | 38256 | 1470 | N, X, Y = map( int, input().split() )
C = []
W = []
for i in range( N ):
c, w = map( int, input().split() )
C.append( c - 1 )
W.append( w )
c2w = [ [] for i in range( N ) ]
for i in range( N ):
c2w[ C[ i ] ].append( W[ i ] )
for i in range( N ):
c2w[ C[ i ] ].sort()
minw, _minwp = 2e9, -1
for i in range( N ):
if minw > c2w[ i ][ 0 ]:
minw = c2w[ i ][ 0 ]
_minwp = i
minw2 = 2e9
for i in range( N ):
if i == _minwp: continue
if minw2 > c2w[ i ][ 0 ]:
minw2 = c2w[ i ][ 0 ]
merged = [ False for i in range( N ) ]
hi = [ 1 for i in range( N ) ]
for i in range( N ):
if len( c2w[ i ] ) == 0: continue
lb, ub = 2, len( c2w[ i ] )
while lb <= ub:
mid = lb + ub >> 1
if c2w[ i ][ 0 ] + c2w[ i ][ mid - 1 ] <= X:
hi[ i ] = max( hi[ i ], mid )
lb = mid + 1
else:
ub = mid - 1
lb, ub = 1, len( c2w[ i ] )
www = minw2 if minw != minw2 and c2w[ i ][ 0 ] == minw else minw
while lb <= ub:
mid = lb + ub >> 1
if www + c2w[ i ][ mid - 1 ] <= Y:
hi[ i ] = max( hi[ i ], mid )
merged[ i ] = True
lb = mid + 1
else:
ub = mid - 1
MOD = int( 1e9 + 7 )
fact = [ 1 ]
inv_fact = [ 1 ]
for i in range( 1, N + 1, 1 ):
fact.append( fact[ i - 1 ] * i % MOD )
inv_fact.append( pow( fact[ i ], MOD - 2, MOD ) )
ans = fact[ sum( merged[ i ] * hi[ i ] for i in range( N ) ) ]
for i in range( N ):
if not merged[ i ]: continue
ans = ans * inv_fact[ hi[ i ] ] % MOD
print( ans )
|
s399299349 | p03767 | u006493569 | 1491151186 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38384 | 532 | n, m = map(int, input().split())
edges = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
edges += [[i, i] for i in range(n)]
q = int(input())
color = [0] * q
dp = [[0 for j in range(n)] for i in range(11)]
for i in range(q):
v, d, color[i] = map(int, input().split())
dp[d][v - 1] = i
for i in reversed(range(1, 11)):
for u, v in edges:
dp[i - 1][u] = max(dp[i - 1][u], dp[i][v])
dp[i - 1][v] = max(dp[i - 1][v], dp[i][u])
print(*[color[dp[0][i]] for i in range(n)], sep = '\n') |
s886802575 | p03767 | u608297208 | 1491149913 | Python | Python (3.4.3) | py | Runtime Error | 303 | 20792 | 1065 | import numpy as np
N,M = map(int,input().split())
nodes = [[False]* N for j in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = True
nodes[b-1][a-1] = True
mat1 = np.matrix(nodes,dtype=bool)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
mat2 = mat2.dot(mat1)
a = mat2.tolist()
A.append(a)
white = [i for i in range(N)]
Colour = [0] * N
paint = []
Q = int(input())
for q in range(Q):
line = list(map(int,input().split()))
paint.append(line)
white2 = white[:]
paint.reverse()
for p in paint:
v,d,c = p[0],p[1],p[2]
if d == 0 and v - 1 in w:
Colour[v - 1] = c
white2.remove(v - 1)
continue
elif d == 0:
continue
else:
for w in white:
if d == 1:
if not A[0][v - 1][w]:
continue
else:
Colour[w] = c
white2.remove(w)
else:
if A[d - 1][v - 1][w] or A[d - 2][v - 1][w]:
Colour[w] = c
white2.remove(w)
if len(white2) == 0:
break
if v - 1 in white:
Colour[v - 1] = c
if v - 1 in white2:
white2.remove(v - 1)
white = white2[:]
for C in Colour:
print(C) |
s433934644 | p03767 | u821262411 | 1491148770 | Python | Python (3.4.3) | py | Runtime Error | 251 | 39492 | 202 | N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
ans1=sum(b[N:2*N])
ans2=0
for i in range(N):
ans2 += b[i*3+1]
ans3=0
for i in range(N):
ans3 += b[i*2+4]
print(max(ans1,ans2,ans3)) |
s946289015 | p03767 | u024612773 | 1491142768 | Python | PyPy3 (2.4.0) | py | Runtime Error | 173 | 38640 | 533 | import numpy as np
n,m=map(int,input().split())
e = []
for _ in range(1,m+1):
a,b=map(int,input().split())
e.append((a,b))
q = int(input())
cs = [0] * (q+1)
dp = np.zeros((n+1, 11), int)
for i in range(1, q+1):
v,d,c=map(int,input().split())
cs[i] = c
dp[v,d] = i
for d in range(9, -1, -1):
for i in range(1,n+1):
dp[i,d] = max(dp[i,d], dp[i,d+1])
for a,b in e:
dp[a,d] = max(dp[a,d], dp[b,d+1])
dp[b,d] = max(dp[b,d], dp[a,d+1])
for i in range(1, n+1):
print(cs[dp[i,0]]) |
s339737418 | p03767 | u966695411 | 1491119278 | Python | Python (3.4.3) | py | Runtime Error | 35 | 9460 | 70 | print(sum(sorted(map(int,input().split()))[::-1][1:2*int(input()):2])) |
s988294771 | p03767 | u076936237 | 1491109240 | Python | Python (3.4.3) | py | Runtime Error | 152 | 12480 | 698 | import numpy as np
from collections import defaultdict
memo = {}
def dp(v, d, c):
if memo.get((v, d), False):
return None
memo[(v, d)] = True
if d == 0:
res[v-1] = c
return None
dp(v, d-1, c)
for e in dic.get(v, []):
dp(e, d-1, c)
N, M = tuple(map(int, input().split(' ')))
dic = defaultdict(list)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
dic[a].append(b)
dic[b].append(a)
Q = int(input())
vdc = [None]*Q
for q in range(Q):
vdc[q] = tuple(map(int, input().split(' ')))
res = np.zeros(N)
for q in range(Q-1, -1, -1):
v, d, c = vdc[q]
dp(v, d, c)
for i in range(N):
print(int(res[i]))
|
s559920375 | p03767 | u104282757 | 1491104482 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3316 | 909 | from collections import deque
G = dict()
N, M = map(int, input().split())
color = [0]*(N+1)
for n in range(1, N+1):
G[n] = []
for _ in range(M):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
Q = int(input())
data = [list(map(int, input().split())) for _ in range(Q)]
data.reverse()
color_d = [-1]*(N+1)
for v, d, c in data:
if color_d[v] >= d:
pass
# BFS
deq = deque([v])
if color[v] == 0:
color[v] = c
color_d[v] = d
while len(deq) > 0:
s = deq.popleft()
for t in G[s]:
if color_d[t] >= color_d[s] - 1:
pass
else:
color_d[t] = color_d[s] - 1
if color[t] == 0:
color[t] = c
if color_d[t] > 0:
deq.append(t)
for n in range(1, N+1):
print(color[n])
|
s378947166 | p03767 | u608297208 | 1491103752 | Python | Python (3.4.3) | py | Runtime Error | 311 | 21336 | 744 | import numpy as np
N,M = map(int,input().split())
nodes = [[False]* N for j in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = True
nodes[b-1][a-1] = True
mat1 = np.matrix(nodes,dtype=bool)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
mat2 = mat2.dot(mat1)
a = mat2.tolist()
A.append(a)
'''
for ai,a in enumerate(A):
for k in a:
print(k)
print(ai)
'''
Colour = [0] * N
Q = int(input())
for q in range(Q):
v,d,c = map(int,input().split())
Colour[v - 1] = c
if d == 0:
continue
for n in range(N):
if d == 1 :
if (not A[0][v - 1][n]):
continue
else:
Colour[n] = c
else:
if A[d - 1][v - 1][n] or A[d - 2][v - 1][n] > 0:
Colour[n] = c
for C in Colour:
print(C)
|
s363192506 | p03767 | u076936237 | 1491102310 | Python | Python (3.4.3) | py | Runtime Error | 148 | 12508 | 750 | import numpy as np
from numpy import linalg as LA
import math
mat_dic = {}
def f(mat, n):
if mat_dic.get(n, None) is not None:
return mat_dic.get(n, None)
if n == 1:
return mat
if int(math.sqrt(n))**2 == n:
return LA.matrix_power(f(mat, int(math.sqrt(n))), 2)
return mat.dot(f(mat, n-1))
N, M = tuple(map(int, input().split(' ')))
mat = np.identity(N)
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = f(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s644580471 | p03767 | u946912540 | 1491102298 | Python | Python (3.4.3) | py | Runtime Error | 208 | 37084 | 81 | n = input()
x = [int(_) for _ in input().split()]
x.sort()
print(sum(x[n:n*2]))
|
s261635964 | p03767 | u076936237 | 1491101204 | Python | Python (3.4.3) | py | Runtime Error | 565 | 46116 | 522 | import numpy as np
N = int(input())
a = list(map(int, input().split(' ')))
a.sort()
x = []
for n in range(N):
x.append([])
for i in range(3):
x[n].append(0)
for i in range(N*3):
x[i % N][i // N] = a[i]
for i in range(N-1, -1, -1):
for j in range(i-1, -1, -1):
if x[i][1] == x[j][1] and [j][2] < x[i][1] and x[i][2] > x[j][2]:
x[j][2], x[i][1] = x[i][1], x[j][2]
break
else:
break
res = 0
for n in range(N):
res += x[n][1]
print(res)
|
s576078522 | p03767 | u794250528 | 1491100928 | Python | PyPy3 (2.4.0) | py | Runtime Error | 176 | 38640 | 1000 | import collections
if __name__ == '__main__':
n, m = map(int, input().split())
routes = collections.defaultdict(list)
for _ in range(m):
a, b = (int(x) - 1 for x in input().split())
routes[a].append(b)
routes[b].append(a)
matrix = [[None for _ in range(n)] for _ in range(n)]
for i in range(n):
cnt = 1
buffer = set([i])
matrix[i][i] = 0
while buffer and not all(matrix[i]):
temp = set()
for x in buffer:
for j in routes[x]:
if matrix[i][j] is None:
matrix[i][j] = cnt
temp.add(j)
buffer = temp
cnt += 1
colors = [0 for _ in range(n)]
q = int(input())
for _ in range(q):
v, d, c = map(int, input().split())
v -= 1
for w in range(n):
if matrix[v][w] is not None and matrix[v][w] <= d: colors[w] = c
for color in colors: print(color)
|
s923988382 | p03767 | u454697629 | 1491099310 | Python | Python (3.4.3) | py | Runtime Error | 1795 | 33804 | 320 | # -*- coding: utf-8 -*-
"""
Created on Sat Apr 1 22:07:55 2017
@author: taichiNakamura
"""
N = int(input())
# スペース区切りの整数の入力
num = map(int, input().split())
import numpy as np
num = np.array(num)
num = np.sort(num)
sum = 0
for i in range(N):
sum += num[3*N - 2 - i*2]
# 出力
print(sum) |
s861563223 | p03767 | u391812144 | 1491097021 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 379 | input_lines = str(input())
input_lines2 = str(input())
n = int(input_lines)
aAry = input_lines2.split(' ')
aAry = map(int,aAry)
aAry = sorted(aAry)
#print(aAry)
answer1 = 0L
for i in range(n):
answer1 += int(aAry[(-i-1)*2])
answer2 = 0L
for i in range(n):
answer2 += int(aAry[-i-3])
if answer1 >= answer2:
answer = answer1
else:
answer = answer2
print(answer) |
s573180680 | p03767 | u943329882 | 1491096820 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 177 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
N = int(raw_input())
a = raw_input().split(" ")
output = 0
a.sort()
for i in a[N:2*N]:
output = output + int(i)
print output |
s456969319 | p03767 | u515802486 | 1491095316 | Python | Python (3.4.3) | py | Runtime Error | 208 | 37084 | 377 | import sys
INF = 10**9+7
stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))
n = ni()
a = nil()
a.sort()
ans = 0
for i in range(n):
ans += a[-2-i*n]
print(ans) |
s295789251 | p03768 | u456353530 | 1600969952 | Python | PyPy3 (7.3.0) | py | Runtime Error | 1157 | 143756 | 1083 | N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
vdc = [list(map(int, input().split())) for _ in range(Q)]
L = [[] for _ in range(N)]
for a, b in ab:
a -= 1
b -= 1
L[a].append(b)
L[b].append(a)
D = [[0] * 10 for _ in range(N)]
Ans = [0] * N
def check(v, d, c):
if D[v][d] != 0: return
if d == 0:
D[v][d] = c
return
for i in range(d, -1, -1):
if D[v][i] != 0: break
D[v][i] = c
for i in L[v]:
pass
import queue
Que = queue.Queue
get = queue.Queue.get
put = queue.Queue.put
emp = queue.Queue.empty
for v, d, c in vdc[::-1]:
v -= 1
if D[v][d] != 0: continue
t = (d << 18) + v
S = Que()
put(S, t)
while not emp(S):
t = get(S)
dd = t >> 18
vv = t & ((1 << 18) - 1)
if Ans[vv] == 0: Ans[vv] = c
if dd == 0:
D[vv][dd] = c
continue
for i in range(dd, -1, -1):
if D[vv][i] != 0: break
D[vv][i] = c
for i in L[vv]:
if D[i][dd - 1] != 0: continue
t = ((dd - 1) << 18) + i
put(S, t)
for i in Ans:
print(i) |
s386582497 | p03768 | u368796742 | 1600484884 | Python | Python (3.8.2) | py | Runtime Error | 2218 | 449556 | 1323 | import sys
sys.setrecursionlimit(10**6)
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
e[a].append(b)
e[b].append(a)
qv = int(input())
Q = [list(map(int,input().split())) for i in range(qv)]
Q = Q[::-1]
l = [[0]*(11) for i in range(n+1)]
for v,d,c in Q:
if l[v][d] > 0:
continue
l[v][d] = c
dic = {}
color = [0]*(n+1)
left = [i for i in range(1,n+1)]
num = 0
while num < qv and left:
v,d,c = Q[num]
if v not in dic:
for i in range(10,-1,-1):
if l[v][i] > 0:
M = i
break
dic[v] = [set() for i in range(n+1)]
s = set()
s.add(v)
dic[v][0] |= s
dist = [float("INF")]*(n+1)
dist[v] = 0
q = [v]
for i in range(1,M+1):
nq = []
for now in q:
for nex in e[now]:
if dist[nex]<= i:
continue
nq.append(nex)
dist[nex] = i
s.add(nex)
dic[v][i] |= s
q = nq
nl = []
for i in left:
if i in dic[v][d]:
color[i] = c
else:
nl.append(i)
num += 1
left = nl
for i in color[1:]:
print(i) |
s624081518 | p03768 | u368796742 | 1600484726 | Python | Python (3.8.2) | py | Runtime Error | 2219 | 449452 | 1300 | import sys
sys.setrecursionlimit(10**6)
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
e[a].append(b)
e[b].append(a)
qv = int(input())
Q = [list(map(int,input().split())) for i in range(qv)]
Q = Q[::-1]
l = [[0]*(11) for i in range(n+1)]
for v,d,c in Q:
if l[v][d] > 0:
continue
l[v][d] = c
dic = {}
color = [0]*(n+1)
left = [i for i in range(1,n+1)]
num = 0
while num < qv and left:
v,d,c = Q[num]
if v not in dic:
for i in range(10,-1,-1):
if l[v][i] > 0:
M = i
break
dic[v] = [set() for i in range(n+1)]
s = set()
s.add(v)
dist = [float("INF")]*(n+1)
dist[v] = 0
q = [v]
for i in range(1,M+1):
nq = []
for now in q:
for nex in e[now]:
if dist[nex]<= i:
continue
nq.append(nex)
dist[nex] = i
s.add(nex)
dic[v][i] |= s
q = nq
nl = []
for i in left:
if i in dic[v][d]:
color[i] = c
else:
nl.append(i)
num += 1
left = nl
for i in color[1:]:
print(i) |
s121472303 | p03768 | u368796742 | 1600484618 | Python | Python (3.8.2) | py | Runtime Error | 2282 | 2565712 | 1300 | import sys
sys.setrecursionlimit(10**6)
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
e[a].append(b)
e[b].append(a)
qv = int(input())
Q = [list(map(int,input().split())) for i in range(qv)]
Q = Q[::-1]
l = [[0]*(11) for i in range(n+1)]
for v,d,c in Q:
if l[v][d] > 0:
continue
l[v][d] = c
dic = {}
color = [0]*(n+1)
left = [i for i in range(1,n+1)]
num = 0
while num < qv and left:
v,d,c = Q[num]
if v not in dic:
for i in range(10,-1,-1):
if l[v][i] > 0:
M = i
break
dic[v] = [set() for i in range(n+1)]
s = set()
s.add(v)
dist = [float("INF")]*(n+1)
dist[v] = 0
q = [v]
for i in range(1,m+1):
nq = []
for now in q:
for nex in e[now]:
if dist[nex]<= i:
continue
nq.append(nex)
dist[nex] = i
s.add(nex)
dic[v][i] |= s
q = nq
nl = []
for i in left:
if i in dic[v][d]:
color[i] = c
else:
nl.append(i)
num += 1
left = nl
for i in color[1:]:
print(i) |
s644983166 | p03768 | u368796742 | 1600484543 | Python | Python (3.8.2) | py | Runtime Error | 2266 | 2515072 | 1299 | import sys
sys.setrecursionlimit(10**6)
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
e[a].append(b)
e[b].append(a)
qv = int(input())
Q = [list(map(int,input().split())) for i in range(qv)]
Q = Q[::-1]
l = [[0]*(11) for i in range(n+1)]
for v,d,c in Q:
if l[v][d] > 0:
continue
l[v][d] = c
dic = {}
color = [0]*(n+1)
left = [i for i in range(1,n+1)]
num = 0
while num < qv and left:
v,d,c = Q[num]
if v not in dic:
for i in range(10,0,-1):
if l[v][i] > 0:
M = i
break
dic[v] = [set() for i in range(n+1)]
s = set()
s.add(v)
dist = [float("INF")]*(n+1)
dist[v] = 0
q = [v]
for i in range(1,m+1):
nq = []
for now in q:
for nex in e[now]:
if dist[nex]<= i:
continue
nq.append(nex)
dist[nex] = i
s.add(nex)
dic[v][i] |= s
q = nq
nl = []
for i in left:
if i in dic[v][d]:
color[i] = c
else:
nl.append(i)
num += 1
left = nl
for i in color[1:]:
print(i) |
s316698858 | p03768 | u368796742 | 1600484383 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2280 | 2674536 | 1290 | from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
e[a].append(b)
e[b].append(a)
qv = int(input())
Q = [list(map(int,input().split())) for i in range(qv)]
Q = Q[::-1]
l = [[0]*(11) for i in range(n+1)]
for v,d,c in Q:
if l[v][d] > 0:
continue
l[v][d] = c
dic = {}
color = [0]*(n+1)
left = [i for i in range(1,n+1)]
num = 0
while num < qv and left:
v,d,c = Q[num]
if v not in dic:
for i in range(10,0,-1):
if l[v][i] > 0:
M = i
break
dic[v] = [set() for i in range(n+1)]
s = set()
s.add(v)
dist = [float("INF")]*(n+1)
dist[v] = 0
q = [v]
for i in range(1,m+1):
nq = []
for now in q:
for nex in e[now]:
if dist[nex]<= i:
continue
nq.append(nex)
dist[nex] = i
s.add(nex)
dic[v][i] |= s
q = nq
nl = []
for i in left:
if i in dic[v][d]:
color[i] = c
else:
nl.append(i)
num += 1
left = nl
for i in color[1:]:
print(i) |
s120311933 | p03768 | u520276780 | 1600028834 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 141436 | 730 | import sys
sys.setrecursionlimit(100000)
n,m=map(int, input().split())
e=[[] for _ in range(n)]
for _ in range(m):
ai,bi=map(int, input().split())
ai-=1;bi-=1
e[ai].append(bi);e[bi].append(ai)
Q=int(input())
q=[tuple(map(int, input().split())) for _ in range(Q)]
q.reverse()
color=[0]*n
from collections import deque
que=deque()
used=set()
def bfs(v,d,c):
if d<0:
return
used.add(v)
if not color[v]:
color[v]=c
#que.append((v,d))
for u in e[v]:
que.append((u,d-1))
while que:
u,dd=que.popleft()
if u not in used:
bfs(u,dd,c)
for v,d,c in q:
v-=1
used=set()
bfs(v,d,c)
#print(v,d,c," ",*color)
for c in color:
print(c)
|
s263671955 | p03768 | u520276780 | 1600028772 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2213 | 234964 | 689 | n,m=map(int, input().split())
e=[[] for _ in range(n)]
for _ in range(m):
ai,bi=map(int, input().split())
ai-=1;bi-=1
e[ai].append(bi);e[bi].append(ai)
Q=int(input())
q=[tuple(map(int, input().split())) for _ in range(Q)]
q.reverse()
color=[0]*n
from collections import deque
que=deque()
used=set()
def bfs(v,d,c):
if d<0:
return
used.add(v)
if not color[v]:
color[v]=c
#que.append((v,d))
for u in e[v]:
que.append((u,d-1))
while que:
u,dd=que.popleft()
if u not in used:
bfs(u,dd,c)
for v,d,c in q:
v-=1
used=set()
bfs(v,d,c)
#print(v,d,c," ",*color)
for c in color:
print(c)
|
s056828270 | p03768 | u520276780 | 1600028288 | Python | PyPy3 (7.3.0) | py | Runtime Error | 601 | 159772 | 603 | n,m=map(int, input().split())
e=[[] for _ in range(n)]
for _ in range(m):
ai,bi=map(int, input().split())
ai-=1;bi-=1
e[ai].append(bi);e[bi].append(ai)
Q=int(input())
q=[tuple(map(int, input().split())) for _ in range(Q)]
q.reverse()
color=[0]*n
from collections import deque
que=deque()
def bfs(v,d,c):
if color[v] or d<0:
return
que.append((v,d))
color[v]=c
for u in e[v]:
que.append((u,d-1))
while que:
u,dd=que.popleft()
bfs(u,dd,c)
for v,d,c in q:
v-=1
bfs(v,d,c)
#print(v,d,c," ",*color)
for c in color:
print(c)
|
s789222202 | p03768 | u156302018 | 1599793297 | Python | Python (3.8.2) | py | Runtime Error | 25 | 8944 | 221 | N = int(input())
moti_list = []
for i in range(N):
moti_list.append(int(input()))
moti_list.sort(reverse=True)
tower = 1
for j in range(N - 1):
if moti_list[j] > moti_list[j + 1]:
tower += 1
print(tower) |
s384268022 | p03768 | u102461423 | 1592639677 | Python | Python (3.8.2) | py | Runtime Error | 431 | 62104 | 1381 | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def graph_input(N, M):
G = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = map(int, readline().split())
G[a].append(b)
G[b].append(a)
ind = np.cumsum(list(map(len, G)))
G = np.concatenate(G).astype(np.int32)
return G, ind
def main(N, G, ind, V, D, C):
# 強さ n で塗った時刻
dp = np.full((N + 1, 11), -1, np.int32)
for t in range(len(V)):
v, d = V[t], D[t]
dp[v, d] = t
for n in range(10, 0, -1):
for v in range(1, N + 1):
dp[v, n - 1] = max(dp[v, n - 1], dp[v, n])
for i in range(ind[v - 1], ind[v]):
w = G[i]
dp[w, n - 1] = max(dp[w, n - 1], dp[v, n])
dp = dp[:, 0]
for v in range(1, N + 1):
t = dp[v]
c = C[t] if t != -1 else 0
print(c)
signature = '(i8,i4[:],i4[:],i4[:],i4[:],i4[:])'
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', signature)(main)
cc.compile()
from my_module import main
N, M = map(int, readline().split())
G, ind = graph_input(N, M)
Q = int(readline())
nums = np.array(read().split(), np.int32)
V = nums[::3]
D = nums[1::3]
C = nums[2::3]
main(N, G, ind, V, D, C) |
s281355212 | p03768 | u102461423 | 1592639563 | Python | Python (3.8.2) | py | Runtime Error | 475 | 62272 | 1381 | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def graph_input(N, M):
G = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = map(int, readline().split())
G[a].append(b)
G[b].append(a)
ind = np.cumsum(list(map(len, G)))
G = np.concatenate(G).astype(np.int32)
return G, ind
def main(N, G, ind, V, D, C):
# 強さ n で塗った時刻
dp = np.full((N + 1, 11), -1, np.int32)
for t in range(len(V)):
v, d = V[t], D[t]
dp[v, d] = t
for n in range(10, 0, -1):
for v in range(1, N + 1):
dp[v, n - 1] = max(dp[v, n - 1], dp[v, n])
for i in range(ind[v - 1], ind[v]):
w = G[i]
dp[w, n - 1] = max(dp[w, n - 1], dp[v, n])
dp = dp[:, 0]
for v in range(1, N + 1):
t = dp[v]
c = C[t] if t != -1 else 0
print(c)
signature = '(i8,i4[:],i4[:],i4[:],i4[:],i4[:])'
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', signature)(main)
cc.compile()
from my_module import main
N, M = map(int, readline().split())
G, ind = graph_input(N, M)
Q = int(readline())
nums = np.array(read().split(), np.int32)
V = nums[::3]
D = nums[1::3]
C = nums[2::3]
main(N, G, ind, V, D, C) |
s317553841 | p03768 | u543954314 | 1589728502 | Python | Python (3.4.3) | py | Runtime Error | 728 | 43740 | 658 | from collections import deque
n, m = map(int, input().split())
G = [list() for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1; b -= 1
G[a].append(b)
G[b].append(a)
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)][::-1]
dp = [[Q]*n for _ in range(11)]
for i, (v, d, _) in enumerate(queries):
dp[v-1][d] = i
for d in range(10, 0, -1):
for v in range(n):
if dp[v][d] < Q:
dp[v][d-1] = min(dp[v][d-1], dp[v][d])
for x in G[v]:
dp[x][d-1] = min(dp[x][d-1], dp[v][d])
queries.append((-1, -1, 0))
color = [queries[dp[v][0]][2] for v in range(n)]
print(*color, sep='\n')
|
s829273071 | p03768 | u543954314 | 1589728429 | Python | Python (3.4.3) | py | Runtime Error | 2223 | 1747400 | 656 | from collections import deque
n, m = map(int, input().split())
G = [list() for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1; b -= 1
G[a].append(b)
G[b].append(a)
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)][::-1]
dp = [[Q]*n for _ in range(n)]
for i, (v, d, _) in enumerate(queries):
dp[v-1][d] = i
for d in range(10, 0, -1):
for v in range(n):
if dp[v][d] < Q:
dp[v][d-1] = min(dp[v][d-1], dp[v][d])
for x in G[v]:
dp[x][d-1] = min(dp[x][d-1], dp[v][d])
queries.append((-1, -1, 0))
color = [queries[dp[v][0]][2] for v in range(n)]
print(*color, sep='\n') |
s808084751 | p03768 | u693716675 | 1586978264 | Python | Python (3.4.3) | py | Runtime Error | 1803 | 56948 | 1024 | #b
#by using the condition d<=10, we should memorize V*d whether the pair is already searched.
#if searched, we can stop.
n,m = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
colors = [0]*n
checker = [[0 for _ in range(10)] for _ in range(n)]
def dfs(d,v,c):
if checker[v][d] != 0 or d<0:
return
#d>=0 and (v,d) is not checked
colors[v] = c
checker[v][d] = 1 #checked
dfs(d-1, v, c) #dが低いやつについて全て埋めておく必要がある。もう先着ありで無理ですよ、って宣言。
nodes=edges[v]
for u in nodes:
dfs(d-1, u, c)
for _ in range(m):
a,b = [int(i) for i in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
q = int(input())
info = []
for _ in range(q):
v,d,c = [int(i) for i in input().split()]
info.append((v,d,c))
info.reverse()
for tupple in info:
v,d,c = tupple
#not bfs but dfs
dfs(d,v-1,c)
for i in range(n):
print(colors[i])
|
s541748232 | p03768 | u141610915 | 1584314873 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2118 | 262012 | 966 | import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)
for _ in range(M):
u, v = map(int, input().split())
e[u].append(v)
e[v].append(u)
base = 10 ** 6
def clean():
global res
for i in range(1, N + 1):
if len(res[i]) == 0: continue
p = max(res[i])
z = p % base
d = p // base
newrs = set()
newrs.add(p)
for x in res[i]:
if qd[x % base] > d: newrs.add(x)
res[i] = newrs
res = [set() for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
v, d, c = map(int, input().split())
qd[i] = d
qc[i] = c
res[v].add(d * base + i)
#print(qc)
clean()
for t in range(10):
tres = [set() | s for s in res]
for x in range(1, N + 1):
for y in e[x]:
for z in res[x]:
if qd[z % base] > t: tres[y].add(z)
res = tres
clean()
#print(res)
for r in res[1: ]:
if len(r): print(qc[max(r)])
else: print(0) |
s968990045 | p03768 | u141610915 | 1584313979 | Python | PyPy3 (2.4.0) | py | Runtime Error | 479 | 84956 | 885 | import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)
for _ in range(M):
u, v = map(int, input().split())
e[u].append(v)
e[v].append(u)
res = [set() for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
v, d, c = map(int, input().split())
qd[i] = d
qc[i] = c
res[v].add(i)
#print(qd)
def clean():
global res
for i in range(1, N + 1):
a = sorted(res[i], reverse = True)
d = -1
for j in range(len(a)):
x = a[j]
if qd[x] <= d: res[i].discard(y)
d = max(d, qd[x])
clean()
for t in range(10):
tres = [set() | s for s in res]
for x in range(1, N + 1):
for y in e[x]:
for z in res[x]:
if qd[z] > t: tres[y].add(z)
res = tres
clean()
#print(res)
for r in res[1: ]:
if len(r): print(qc[max(r)])
else: print(0) |
s725843396 | p03768 | u597486843 | 1554514365 | Python | Python (3.4.3) | py | Runtime Error | 2112 | 58496 | 1069 | from collections import deque
import numpy as np
import sys
n, m = map(int, input().split())
g = {}
maxD = np.array([-1 for i in range(n)])
color = np.array([0 for _ in range(n)])
for u, v in (map(int, sys.stdin.readline().split()) for _ in [0]*n):
u-=1
v-=1
if u not in g:
g[u] = []
if v not in g:
g[v] = []
g[u].append(v)
g[v].append(u)
q = int(input())
Q = [list(map(int, l.split())) for l in sys.stdin][::-1]
def bfs(curQ):
while len(curQ) > 0:
node, dis, col = curQ.pop()
if maxD[node] > dis:
continue
if dis < 0:
continue
maxD[node] = dis
if color[node] == 0:
color[node] = col
if node in g:
for v in g[node]:
if dis-1 > maxD[v]:
curQ.append([v, dis-1, col])
for node, dis, col in Q:
curQ = deque()
curQ.append([node-1, dis, col])
bfs(curQ)
ans = ''
for x in color:
ans += str(x)+'\n'
print(ans)
|
s140751034 | p03768 | u597486843 | 1554502214 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 812 | n, m = map(int, input().split())
g = {}
used = {i:[False for _ in range(11)] for i in range(n)}
color = [0 for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
u-=1
v-=1
if u not in g:
g[u] = []
if v not in g:
g[v] = []
g[u].append(v)
g[v].append(u)
q = int(input())
Q = []
for _ in range(q):
node, dis, col = map(int, input().split())
Q.append([node-1, dis, col])
Q = Q[::-1]
def bfs(now, dist, col):
if dist < 0:
return
if used[now][dist]:
return
used[now][dist] = True
if not color[now]:
color[now] = col
if now in g:
for x in g[now]:
bfs(x, dist - 1, col)
for node, dis, col in Q:
bfs(node, dis, col)
for x in color:
print(x) |
s044026409 | p03768 | u597486843 | 1554501807 | Python | Python (3.4.3) | py | Runtime Error | 1966 | 74360 | 793 | n, m = map(int, input().split())
g = {}
used = {i:[False for _ in range(11)] for i in range(n)}
color = [0 for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
u-=1
v-=1
if u not in g:
g[u] = []
if v not in g:
g[v] = []
g[u].append(v)
g[v].append(u)
q = int(input())
Q = []
for _ in range(q):
node, dis, col = map(int, input().split())
Q.append([node-1, dis, col])
Q = Q[::-1]
def bfs(now, dist, col):
if dist < 0:
return
if used[now][dist]:
return
used[now][dist] = True
if not color[now]:
color[now] = col
for x in g[now]:
bfs(x, dist - 1, col)
for node, dis, col in Q:
bfs(node, dis, col)
for x in color:
print(x) |
s870376264 | p03768 | u760171369 | 1553114345 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 389864 | 960 | import numpy as np
N, M = map(int, input().split())
# グラフの初期化
A = [[] for i in range(N)]
# グラフの作成
for k in range(M):
a, b = map(int, input().split())
a, b = sorted([a, b])
A[a-1].append(b-1)
# 距離
distance = np.full((N, N), np.inf)
for i in range(N):
cnt = 0
distance[i, i] = cnt
places = A[i]
while places:
cnt += 1
for k in places:
distance[i, k] = min(distance[i, k], cnt)
distance[k, i] = distance[i, k]
places = list({k for place in places for k in A[place]})
for k in range(i):
if distance[i, k] != np.inf:
distance[i] = np.minimum(distance[i, k] + distance[k], distance[i])
distance[:, i] = distance[i]
# 色塗り
Q = int(input())
colors = np.zeros(N)
for k in range(Q):
v, d, c = map(int, input().split())
v -= 1
colors[distance[v] <= d] = c
# 結果
for k in range(N):
print(int(colors[k])) |
s371094304 | p03768 | u760171369 | 1553102638 | Python | Python (3.4.3) | py | Runtime Error | 2112 | 17860 | 575 | import numpy as np
N, M = map(int, input().split())
# グラフの初期化
a = []
for k in range(N):
a.append(set())
A = np.array(a)
# グラフの作成
for k in range(M):
a, b = map(int, input().split())
A[a-1].update([b-1])
A[b-1].update([a-1])
# 色塗り
Q = int(input())
colors = np.zeros(N)
for k in range(Q):
v, d, c = map(int, input().split())
v -= 1
colors[v] = c
v = [v]
for length in range(d):
s = set()
for m in A[v]:
s.update(m)
v = list(s)
colors[v] = c
# 結果
for k in range(M):
print(int(colors[k])) |
s705454079 | p03768 | u062147869 | 1552619254 | Python | PyPy3 (2.4.0) | py | Runtime Error | 425 | 81584 | 706 | import sys
input = sys.stdin.readline
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
Q=int(input())
X=[[int(i) for i in input().split()] for i in range(Q)]
color=[0]*Q
dp=[[-1]*N for i in range(10)]
for i in range(Q-1,-1,-1):
v, d, c=X[i]
v=v-1
color[i]=c
dp[d][v]=i
for d in range(9,0,-1):
for x in range(N):
for y in table[x]:
dp[d-1][y]=max(dp[d][x],dp[d-1][y])
for i in range(N):
s=-1
for d in range(10):
s=max(s,dp[d][i])
if s==-1:
print(0)
else:
print(color[s])
|
s371067788 | p03768 | u226155577 | 1519330982 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 51448 | 622 | N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
dp = [[-1]*10 for i in range(N)]
mark = {}
Q = int(input())
col = [0]*(Q+1)
col[-1] = 0
C = []
for i in range(Q):
v, d, c = map(int, input().split())
col[i] = c
C.append((v-1, d))
def dfs(v, d, idx):
if idx < dp[v][d]:
return
dp[v][d] = idx
if d:
for w in G[v]:
dfs(w, d-1, idx)
for i in range(Q-1, -1, -1):
v, d = C[i]
dfs(v, d, i)
print(*(col[max(e for e in dp[i])] for i in range(N)), sep='\n') |
s683429608 | p03768 | u918928910 | 1514687961 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 103380 | 1069 | for t in range(1):
graph = {}
colors = {}
n, m = list(map(int, input().split()))
for i in range(m):
a, b = list(map(int, input().split()))
if a not in graph:
graph[a] = [b]
else:
graph[a].append(b)
if b not in graph:
graph[b] = [a]
else:
graph[b].append(a) #Generating the graph as a dictionary.
colors[a] = 0
colors[b] = 0 #Generating a colors dictionary to record color of each vertex.
for q in range(int(input())):
v, d, c = list(map(int, input().split()))
first, sec = [v], []
colors[v] = c
for level in range(d):
for i in first:
for j in graph[i]:
sec.append(j)
colors[j] = c
first, sec = sec, [] #Loop to color all vertices within d distance of given vertex v with color c.
for i in range(1, n+1):
print(colors[i])# your code goes here |
s836988671 | p03768 | u551313534 | 1491534296 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 31932 | 731 | import scipy.sparse as sp
import numpy as np
def query(mat, v, d, c, color):
acc1 = acc2 = sp.identity(n, format='csr')
for i in range(d):
acc1 *= mat
# acc2 += acc1
# vec = acc2.getrow(v-1)
# mask = vec.sign()
# color -= color.multiply(mask)
# color += c*mask
return color
n, m = [int(x) for x in input().split()]
mat = sp.lil_matrix((n, n))
for i in range(m):
a, b = [int(x) for x in input().split()]
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat = mat.tocsr()
q = int(input())
color = sp.csr_matrix([[0 for i in range(n)]])
for i in range(q):
v,d,c = [int(x) for x in input().split()]
color = query(mat, v, d, c, color)
for i in range(n):
print(int(color[0,i]))
|
s270922189 | p03768 | u551313534 | 1491534121 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 32552 | 734 | import scipy.sparse as sp
import numpy as np
def query(mat, v, d, c, color):
acc1 = acc2 = sp.identity(n, format='csr')
for i in range(1, d+1):
acc1 *= mat
acc2 += acc1
# vec = acc2.getrow(v-1)
# mask = vec.sign()
# color -= color.multiply(mask)
# color += c*mask
return color
n, m = [int(x) for x in input().split()]
mat = sp.lil_matrix((n, n))
for i in range(m):
a, b = [int(x) for x in input().split()]
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat = mat.tocsr()
q = int(input())
color = sp.csr_matrix([[0 for i in range(n)]])
for i in range(q):
v,d,c = [int(x) for x in input().split()]
color = query(mat, v, d, c, color)
for i in range(n):
print(int(color[0,i]))
|
s777842327 | p03768 | u551313534 | 1491533958 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 30888 | 683 | import scipy.sparse as sp
import numpy as np
def query(mat, v, d, c, color):
acc1 = acc2 = sp.identity(n, format='csr')
for i in range(1, d+1):
acc1 *= mat
acc2 += acc1
vec = acc2.getrow(v-1)
mask = vec.sign()
color -= color.multiply(mask)
color += c*mask
return color
n, m = [int(x) for x in input().split()]
mat = sp.lil_matrix((n, n))
for i in range(m):
a, b = [int(x) for x in input().split()]
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat = mat.tocsr()
q = int(input())
color = sp.csr_matrix([[0 for i in range(n)]])
for i in range(q):
v,d,c = [int(x) for x in input().split()]
color = query(mat, v, d, c, color)
|
s548451116 | p03768 | u551313534 | 1491533904 | Python | Python (3.4.3) | py | Runtime Error | 2113 | 31536 | 730 | import scipy.sparse as sp
import numpy as np
def query(mat, v, d, c, color):
acc1 = acc2 = sp.identity(n, format='csr')
for i in range(1, d+1):
acc1 *= mat
acc2 += acc1
vec = acc2.getrow(v-1)
mask = vec.sign()
color -= color.multiply(mask)
color += c*mask
return color
n, m = [int(x) for x in input().split()]
mat = sp.lil_matrix((n, n))
for i in range(m):
a, b = [int(x) for x in input().split()]
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat = mat.tocsr()
q = int(input())
color = sp.csr_matrix([[0 for i in range(n)]])
for i in range(q):
v,d,c = [int(x) for x in input().split()]
color = query(mat, v, d, c, color)
for i in range(n):
print(int(color[0,i]))
|
s388222341 | p03768 | u551313534 | 1491533213 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 31528 | 754 | #! /usr/bin/env python3
import scipy.sparse as sp
import numpy as np
def query(mat, v, d, c, color):
acc1 = acc2 = sp.identity(n, format='csr')
for i in range(1, d+1):
acc1 *= mat
acc2 += acc1
vec = acc2.getrow(v-1)
mask = vec.sign()
color -= color.multiply(mask)
color += c*mask
return color
n, m = [int(x) for x in input().split()]
mat = sp.lil_matrix((n, n))
for i in range(m):
a, b = [int(x) for x in input().split()]
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat = mat.tocsr()
q = int(input())
color = sp.csr_matrix([[0 for i in range(n)]])
for i in range(q):
v,d,c = [int(x) for x in input().split()]
color = query(mat, v, d, c, color)
for i in range(n):
print(int(color[0,i]))
|
s625553384 | p03768 | u692632484 | 1491349720 | Python | Python (3.4.3) | py | Runtime Error | 845 | 55168 | 832 | import copy
temp=input().split()
N=int(temp[0])
M=int(temp[1])
ab=[[int(j)-1 for j in input().split()] for i in range(M)]
Q=int(input())
vdc=[[int(j)-1 for j in input().split()] for i in range(Q)]
#color=[-1 for i in range(N)]
chain=[[] for i in range(N)]
for i in range(M):
chain[ab[i][0]]+=[ab[i][1]]
chain[ab[i][1]]+=[ab[i][0]]
for i in range(N):
chain[i]+=[i]
INF=-1
dp=[INF for i in range(N)]
for i in range(Q):
dp[vdc[i][0]][vdc[i][1]+1]=i
#print(chain)
#print(vdc)
#print(dp)
for i in range(9,-1,-1):
nextDp=[INF for i in range(N)]
for j in range(N):
tempMax=INF
for k in chain[j]:
if tempMax<dp[k]:
tempMax=dp[k]
if tempMax<dp[k]:
tempMax=dp[k]
dp[j]=tempMax
dp=copy.deepcopy(nextDp)
# for i in range(N)
#print(dp)
for i in range(N):
if dp[i]==INF:
print(0)
else:
print(vdc[dp[i]][2]+1)
|
s935140979 | p03768 | u594567187 | 1491194779 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1442 | 112544 | 662 | vertices,edges = (int(n) for n in input().split(" "))
edge = [[n,n] for n in range(vertices)]
for e in range(edges):
u,v = (int(n) - 1 for n in input().split(" "))
edge.append([u,v])
color = [0 for n in range(vertices + 1)]
query = int(input())
dp = [[0 for n in range(11)] for m in range(vertices)]
for q in range(query):
e,d,col = (int(n) for n in input().split(" "))
dp[e-1][d] = q + 1
color[q + 1] = col
for dep in range(10,0,-1):
for u,v in edge:
dp[u][dep - 1] = max(dp[u][dep - 1],dp[v][dep],dp[u][dep])
dp[v][dep - 1] = max(dp[v][dep - 1],dp[u][dep],dp[v][dep])
for v in range(vertices):
print(color[dp[v][0]]) |
s981845332 | p03768 | u594567187 | 1491194109 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1229 | 99544 | 629 | vertices,edges = (int(n) for n in input().split(" "))
edge = []
for e in range(edges):
u,v = (int(n) - 1 for n in input().split(" "))
edge.append([u,v])
color = [0 for n in range(vertices)]
query = int(input())
dp = [[0 for n in range(11)] for m in range(vertices)]
for q in range(query):
e,d,col = (int(n) for n in input().split(" "))
dp[e-1][d] = q + 1
color[q + 1] = col
for dep in range(10,0,-1):
for u,v in edge:
dp[u][dep - 1] = max(dp[u][dep - 1],dp[v][dep],dp[u][dep])
dp[v][dep - 1] = max(dp[v][dep - 1],dp[u][dep],dp[v][dep])
for v in range(vertices):
print(color[dp[v][0]])
|
s835209492 | p03768 | u608297208 | 1491186025 | Python | Python (3.4.3) | py | Runtime Error | 2222 | 1953524 | 599 | def painting(N,A,v,d,c):
if d < 0:
return
if A[v][d] == 0:
A[v][d] = c
for ni,n in enumerate(N[v]):
if n == 1:
painting(N,A,ni,d-1,c)
N,M = list(map(int,input().split()))
nodes = [[0]*N for i in range(N)]
dp = [[0]*10 for i in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = 1
nodes[b-1][a-1] = 1
for i in range(N):
nodes[i][i] = 1
Q = int(input())
paint = [list(map(int,input().split())) for q in range(Q)]
paint.reverse()
for q in paint:
v,d,c = q
v = v - 1
painting(nodes,dp,v,d,c)
print("\n".join(list(map(str,[dp[i][0] for i in range(N)]))))
|
s590649519 | p03768 | u006493569 | 1491151172 | Python | PyPy2 (5.6.0) | py | Runtime Error | 34 | 28396 | 532 | n, m = map(int, input().split())
edges = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
edges += [[i, i] for i in range(n)]
q = int(input())
color = [0] * q
dp = [[0 for j in range(n)] for i in range(11)]
for i in range(q):
v, d, color[i] = map(int, input().split())
dp[d][v - 1] = i
for i in reversed(range(1, 11)):
for u, v in edges:
dp[i - 1][u] = max(dp[i - 1][u], dp[i][v])
dp[i - 1][v] = max(dp[i - 1][v], dp[i][u])
print(*[color[dp[0][i]] for i in range(n)], sep = '\n') |
s237620267 | p03768 | u608297208 | 1491150016 | Python | Python (3.4.3) | py | Runtime Error | 2272 | 2003940 | 1070 | import numpy as np
N,M = map(int,input().split())
nodes = [[False]* N for j in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = True
nodes[b-1][a-1] = True
mat1 = np.matrix(nodes,dtype=bool)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
mat2 = mat2.dot(mat1)
a = mat2.tolist()
A.append(a)
white = [i for i in range(N)]
Colour = [0] * N
paint = []
Q = int(input())
for q in range(Q):
line = list(map(int,input().split()))
paint.append(line)
white2 = white[:]
paint.reverse()
for p in paint:
v,d,c = p[0],p[1],p[2]
if d == 0 and v - 1 in white:
Colour[v - 1] = c
white2.remove(v - 1)
continue
elif d == 0:
continue
else:
for w in white:
if d == 1:
if not A[0][v - 1][w]:
continue
else:
Colour[w] = c
white2.remove(w)
else:
if A[d - 1][v - 1][w] or A[d - 2][v - 1][w]:
Colour[w] = c
white2.remove(w)
if len(white2) == 0:
break
if v - 1 in white:
Colour[v - 1] = c
if v - 1 in white2:
white2.remove(v - 1)
white = white2[:]
for C in Colour:
print(C)
|
s027653641 | p03768 | u608297208 | 1491149939 | Python | Python (3.4.3) | py | Runtime Error | 2231 | 2023140 | 1065 | import numpy as np
N,M = map(int,input().split())
nodes = [[False]* N for j in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = True
nodes[b-1][a-1] = True
mat1 = np.matrix(nodes,dtype=bool)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
mat2 = mat2.dot(mat1)
a = mat2.tolist()
A.append(a)
white = [i for i in range(N)]
Colour = [0] * N
paint = []
Q = int(input())
for q in range(Q):
line = list(map(int,input().split()))
paint.append(line)
white2 = white[:]
paint.reverse()
for p in paint:
v,d,c = p[0],p[1],p[2]
if d == 0 and v - 1 in w:
Colour[v - 1] = c
white2.remove(v - 1)
continue
elif d == 0:
continue
else:
for w in white:
if d == 1:
if not A[0][v - 1][w]:
continue
else:
Colour[w] = c
white2.remove(w)
else:
if A[d - 1][v - 1][w] or A[d - 2][v - 1][w]:
Colour[w] = c
white2.remove(w)
if len(white2) == 0:
break
if v - 1 in white:
Colour[v - 1] = c
if v - 1 in white2:
white2.remove(v - 1)
white = white2[:]
for C in Colour:
print(C) |
s640051356 | p03768 | u024612773 | 1491142784 | Python | PyPy3 (2.4.0) | py | Runtime Error | 179 | 38384 | 533 | import numpy as np
n,m=map(int,input().split())
e = []
for _ in range(1,m+1):
a,b=map(int,input().split())
e.append((a,b))
q = int(input())
cs = [0] * (q+1)
dp = np.zeros((n+1, 11), int)
for i in range(1, q+1):
v,d,c=map(int,input().split())
cs[i] = c
dp[v,d] = i
for d in range(9, -1, -1):
for i in range(1,n+1):
dp[i,d] = max(dp[i,d], dp[i,d+1])
for a,b in e:
dp[a,d] = max(dp[a,d], dp[b,d+1])
dp[b,d] = max(dp[b,d], dp[a,d+1])
for i in range(1, n+1):
print(cs[dp[i,0]]) |
s823330118 | p03768 | u379559362 | 1491106085 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 537 | q = int(input())
node_color = [0 for _ in range(n + 1)]
vdc = [list(map(int, input().split())) for _ in range(q)]
vdc = vdc[::-1]
painted = set()
visited = [[0] * 11 for _ in range(n + 1)]
def dfs(now, dist, color):
if dist < 0:
return
if visited[now][dist]:
return
visited[now][dist] += 1
if not node_color[now]:
node_color[now] = color
for x in node[now]:
dfs(x, dist - 1, color)
for i in vdc:
v, d, c = i
dfs(v, d, c)
for m in range(n):
print(node_color[m + 1])
|
s774064154 | p03768 | u076936237 | 1491102319 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 776648 | 750 | import numpy as np
from numpy import linalg as LA
import math
mat_dic = {}
def f(mat, n):
if mat_dic.get(n, None) is not None:
return mat_dic.get(n, None)
if n == 1:
return mat
if int(math.sqrt(n))**2 == n:
return LA.matrix_power(f(mat, int(math.sqrt(n))), 2)
return mat.dot(f(mat, n-1))
N, M = tuple(map(int, input().split(' ')))
mat = np.identity(N)
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = f(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s707639581 | p03768 | u330205771 | 1491101398 | Python | Python (2.7.6) | py | Runtime Error | 2110 | 760556 | 1163 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp = map(int, raw_input().split())
a.append(temp[0])
b.append(temp[1])
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(N):
for j in range(N):
if distance[i][j] != -1:
for k in range(N):
if i != k:
if distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(N):
distance[i][i] = 0
color = np.zeros(N)
for q in range(Q):
for n in range(N):
if distance[v[q] - 1][n] != -1:
if distance[v[q] - 1][n] <= d[q]:
color[n] = c[q]
for n in range(N):
print(int(color[n])) |
s336483641 | p03768 | u054556734 | 1491101384 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 18368 | 404 | n,m=map(int,input().split())
a=[0 for i in range(m+1)]
b=[0 for i in range(m+1)]
for i in range(1,m+1): a[i],b[i]=map(int,input().split())
q=int(input())
v=[0 for i in range(m+1)]
d=[0 for i in range(m+1)]
c=[0 for i in range(m+1)]
for i in range(1,q+1): v[i],d[i],c[i]=map(int,input().split())
for i in range(1,q+1):
for j in range(1,q+1):
if abs(v[j]-v[i])<d[i]: c[j]=c[i]
print(c[i]) |
s055157232 | p03768 | u330205771 | 1491100626 | Python | Python (2.7.6) | py | Runtime Error | 2110 | 760556 | 1170 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp = map(int, raw_input().split())
a.append(temp[0])
b.append(temp[1])
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(N):
for j in range(i + 1, N):
if distance[i][j] != -1:
for k in range(N):
if i != k:
if distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(N):
distance[i][i] = 0
color = np.zeros(N)
for q in range(Q):
for n in range(N):
if distance[v[q] - 1][n] != -1:
if distance[v[q] - 1][n] <= d[q]:
color[n] = c[q]
for n in range(N):
print(int(color[n])) |
s101512179 | p03768 | u608297208 | 1491100559 | Python | PyPy3 (2.4.0) | py | Runtime Error | 179 | 38640 | 666 | import numpy as np
N,M = map(int,input().split())
nodes = [[0 for i in range(N)] for j in range(N)]
for m in range(M):
a,b = map(int,input().split())
nodes[a-1][b-1] = 1
nodes[b-1][a-1] = 1
mat1 = np.matrix(nodes)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
mat2 = mat2.dot(mat1)
a = mat2.tolist()
A.append(a)
Colour = [0] * N
Q = int(input())
for q in range(Q):
v,d,c = map(int,input().split())
Colour[v - 1] = c
if d == 0:
continue
for n in range(N):
if d == 1 :
if A[0][v - 1][n] == 0:
continue
else:
Colour[n] = c
else:
if A[d - 1][v - 1][n] + A[d - 2][v - 1][n] > 0:
Colour[n] = c
for C in Colour:
print(C) |
s831234009 | p03768 | u076936237 | 1491100490 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 776396 | 750 | import numpy as np
from numpy import linalg as LA
import math
mat_dic = {}
def f(mat, n):
if mat_dic.get(n, None) is not None:
return mat_dic.get(n, None)
if n == 1:
return mat
if int(math.sqrt(n))**2 == n:
return LA.matrix_power(f(mat, int(math.sqrt(n))), 2)
return mat.dot(f(mat, n-1))
N, M = tuple(map(int, input().split(' ')))
mat = np.identity(N)
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = f(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s894191200 | p03768 | u039623862 | 1491100432 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2117 | 205316 | 1527 | import collections
N,M = map(int, input().split())
nodes = [collections.defaultdict(int) for i in range(N)]
for i in range(M):
a,b = map(int, input().split())
nodes[a-1][b-1] = 1
nodes[b-1][a-1] = 1
shots = []
Q = int(input())
for i in range(Q):
v,d,c = map(int, input().split())
shots.append((v-1, d, c))
colors = [0 for i in range(N)]
sizes = [-1 for i in range(N)]
edges = [[] for i in range(N)]
for query in range(Q-1, -1, -1):
v, d, c = shots[query]
dq = collections.deque()
dq.append((d, v))
visited = [False for i in range(N)]
while dq:
size, idx = dq.popleft()
if sizes[idx] >= size:
continue
else:
sizes[idx] = size
visited[idx] = True
if colors[idx] == 0:
colors[idx] = c
for nv, nd in nodes[idx].items():
if not visited[nv]:
dq.append((size-nd, nv))
len_next_nodes = len(nodes[idx])
if len_next_nodes >= 150:
continue
next_nodes = nodes[idx].items()
for nvi, ndi in nodes[idx].items():
if nvi == idx:
continue
nodes[nvi].pop(idx)
for nvj, ndj in nodes[idx].items():
if nvj in nodes[nvi]:
nodes[nvi][nvj] = nodes[nvj][nvi] = min(nodes[nvi][nvj], nodes[idx][nvi] + nodes[idx][nvj])
else:
nodes[nvi][nvj] = nodes[nvj][nvi] = nodes[idx][nvi] + nodes[idx][nvj]
print(*colors, sep='\n')
|
s117056211 | p03768 | u076936237 | 1491100084 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 778692 | 640 | import numpy as np
from numpy import linalg as LA
mat_dic = {}
def f(mat, n):
if mat_dic.get(n, None) is not None:
return mat_dic.get(n, None)
if n == 1:
return mat
return mat.dot(f(mat, n-1))
N, M = tuple(map(int, input().split(' ')))
mat = np.identity(N)
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = f(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s885791362 | p03768 | u107077660 | 1491100051 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 283500 | 485 | N, M = map(int, input().split())
G = [[set([j]) for i in range(11)] for j in range(N)]
for _ in range(M):
a, b = map(int, input().split())
G[a-1][1].add(b-1)
G[b-1][1].add(a-1)
for i in range(N):
if len(G[i][1]) == 1:
continue
for d in range(1,11):
for j in G[i][d-1]:
G[i][d] |= G[j][1]
if len(G[i][d] == N):
break
C = [0]*N
Q = int(input())
for _ in range(Q):
v, d, c = map(int, input().split())
for i in G[v-1][d]:
C[i] = c
for i in range(N):
print(C[i]) |
s847799752 | p03768 | u330205771 | 1491099897 | Python | Python (2.7.6) | py | Runtime Error | 2112 | 760568 | 1138 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp1, temp2 = map(int, raw_input().split())
a.append(temp1)
b.append(temp2)
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(N):
for j in range(i + 1, N):
if distance[i][j] != -1:
for k in range(N):
if j != k and distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(N):
distance[i][i] = 0
color = np.zeros(N)
for q in range(Q):
for n in range(N):
if distance[v[q] - 1][n] != -1:
if distance[v[q] - 1][n] <= d[q]:
color[n] = c[q]
for n in range(N):
print(int(color[n])) |
s594591177 | p03768 | u330205771 | 1491099624 | Python | Python (2.7.6) | py | Runtime Error | 2110 | 760572 | 1120 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp1, temp2 = map(int, raw_input().split())
a.append(temp1)
b.append(temp2)
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(N):
for j in range(N):
if distance[i][j] != -1:
for k in range(N):
if distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(N):
distance[i][i] = 0
color = np.zeros(N)
for q in range(Q):
for n in range(N):
if distance[v[q] - 1][n] != -1:
if distance[v[q] - 1][n] <= d[q]:
color[n] = c[q]
for n in range(N):
print(int(color[n])) |
s862345943 | p03768 | u076936237 | 1491099581 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 776904 | 480 | import numpy as np
from numpy import linalg as LA
N, M = tuple(map(int, input().split(' ')))
mat = np.identity(N)
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = LA.matrix_power(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s245493509 | p03768 | u330205771 | 1491099252 | Python | Python (2.7.6) | py | Runtime Error | 2112 | 760572 | 1118 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp1, temp2 = map(int, raw_input().split())
a.append(temp1)
b.append(temp2)
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(N):
count = 0
for j in range(N):
if distance[i][j] != -1:
for k in range(N):
if distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(N):
distance[i][i] = 0
color = np.zeros(N)
for q in range(Q):
for n in range(N):
if distance[v[q] - 1][n] != -1 and distance[v[q] - 1][n] <= d[q]:
color[n] = c[q]
for n in range(N):
print(int(color[n])) |
s881984706 | p03768 | u076936237 | 1491098512 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 776396 | 483 | import numpy as np
from numpy import linalg as LA
N, M = tuple(map(int, input().split(' ')))
mat = np.zeros((N, N))
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = LA.matrix_power(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s993527938 | p03768 | u076936237 | 1491098512 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 776012 | 483 | import numpy as np
from numpy import linalg as LA
N, M = tuple(map(int, input().split(' ')))
mat = np.zeros((N, N))
res = np.zeros(N)
for m in range(M):
a, b = tuple(map(int, input().split(' ')))
mat[a-1, b-1] = 1
mat[b-1, a-1] = 1
mat[a-1, a-1] = 1
mat[b-1, b-1] = 1
Q = int(input())
for q in range(Q):
v, d, c = tuple(map(int, input().split(' ')))
x = LA.matrix_power(mat, d)
res[x[v-1,:] > 0] = c
for i in range(N):
print(int(res[i]))
|
s261393373 | p03768 | u330205771 | 1491098496 | Python | Python (2.7.6) | py | Runtime Error | 2109 | 760572 | 1118 | import numpy as np
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(M):
temp1, temp2 = map(int, raw_input().split())
a.append(temp1)
b.append(temp2)
Q = int(raw_input())
v = []
d = []
c = []
for i in range(Q):
temp = map(int, raw_input().split())
v.append(temp[0])
d.append(temp[1])
c.append(temp[2])
distance = -np.ones(N * N).reshape((N, N))
for i in range(M):
distance[a[i] - 1][b[i] - 1] = 1
distance[b[i] - 1][a[i] - 1] = 1
for i in range(M):
count = 0
for j in range(M):
if distance[i][j] != -1:
for k in range(M):
if distance[j][k] != -1:
temp = distance[i][j] + distance[j][k]
if distance[i][k] == -1 or temp < distance[i][k]:
distance[i][k] = temp
distance[k][i] = temp
for i in range(M):
distance[i][i] = 0
color = np.zeros(M)
for q in range(Q):
for m in range(M):
if distance[v[q] - 1][m] != -1 and distance[v[q] - 1][m] <= d[q]:
color[m] = c[q]
for m in range(M):
print(int(color[m])) |
s004363919 | p03768 | u477320129 | 1491098430 | Python | PyPy3 (2.4.0) | py | Runtime Error | 703 | 69152 | 1123 | # import heapq
from collections import deque
class Node:
def __init__(self):
self.color = 0
self.to = []
def bfs(graph, cur, color, dist):
visited = set()
q = deque([(0, cur)])
while q:
# d, c = heapq.heappop(q)
d, c = q.popleft()
if c in visited:
continue
graph[c].color = color
visited.add(c)
if d == dist:
continue
for n in graph[c].to:
if n in visited:
continue
# heapq.heappush(q, (d+1, n))
q.append((d+1, n))
def main():
N, M = [int(i) for i in input().split()]
graph = [Node() for _ in range(N+1)]
for _ in range(M):
a, b = [int(i) for i in input().split()]
graph[a].to.append(b)
graph[b].to.append(a)
Q = int(input())
assert 1 <= N <= 2000
assert 1 <= M <= 2000
assert 1 <= Q <= 2000
for _ in range(Q):
v, d, c = [int(i) for i in input().split()]
bfs(graph, v, c, d)
for i in range(1, N+1):
print(graph[i].color)
if __name__ == "__main__":
main()
|
s479734277 | p03768 | u477320129 | 1491098339 | Python | PyPy3 (2.4.0) | py | Runtime Error | 695 | 69216 | 1156 | # import heapq
from collections import deque
class Node:
def __init__(self):
self.color = 0
self.to = []
def bfs(graph, cur, color, visited, dist):
q = deque([(0, cur)])
while q:
# d, c = heapq.heappop(q)
d, c = q.popleft()
if visited[c]:
continue
graph[c].color = color
visited[c] = True
if d == dist:
continue
for n in graph[c].to:
if visited[n]:
continue
# heapq.heappush(q, (d+1, n))
q.append((d+1, n))
def main():
N, M = [int(i) for i in input().split()]
graph = [Node() for _ in range(N+1)]
for _ in range(M):
a, b = [int(i) for i in input().split()]
graph[a].to.append(b)
graph[b].to.append(a)
Q = int(input())
assert 1 <= N <= 2000
assert 1 <= M <= 2000
assert 1 <= Q <= 2000
for _ in range(Q):
v, d, c = [int(i) for i in input().split()]
visited = [False] * (N + 1)
bfs(graph, v, c, visited, d)
for i in range(1, N+1):
print(graph[i].color)
if __name__ == "__main__":
main()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.