problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03634
u001024152
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["# D\nN = int(input())\nedge = [[] for _ in range(N)]\nfor _ in range(N):\n ai,bi,ci = map(int, input().split())\n edge[ai-1].append((bi-1, ci))\n edge[bi-1].append((ai-1, ci))\nQ,K = map(int, input().split())\nK = K-1\nx,y = [],[]\nfor _ in range(Q):\n xi,yi = map(int, input().split())\n x.append(xi-1)\n y.append(yi-1)\n\n\ndist = [float('inf')]*N # from K\nvisited = [False]*N\nq = [K]\ndist[K] = 0\nvisited[K] = True\nwhile q:\n cur = q.pop()\n visited[cur] = True\n for nex,cost in edge[cur]:\n if not visited[nex]:\n q.append(nex)\n dist[nex] = dist[cur]+cost\n#print(dist)\nfor xi,yi in zip(x,y):\n print(dist[xi] + dist[yi])", "\nN = int(input())\nedge = [[] for _ in range(N)]\nfor _ in range(N-1):\n ai,bi,ci = map(int, input().split())\n edge[ai-1].append((bi-1, ci))\n edge[bi-1].append((ai-1, ci))\nQ,K = map(int, input().split())\nK = K-1\nx,y = [],[]\nfor _ in range(Q):\n xi,yi = map(int, input().split())\n x.append(xi-1)\n y.append(yi-1)\n\n\ndist = [float('inf') for _ in range(N)]\nimport heapq\ndef dijkstra(start:int):\n \n global dist \n global edge \n dist[start] = 0\n q = [(0,start)] \n while q:\n d_cur,cur = heapq.heappop(q)\n if dist[cur] < d_cur:\n continue\n for nex,cost in edge[cur]:\n if dist[nex] > dist[cur]+cost:\n dist[nex] = dist[cur]+cost\n heapq.heappush(q, (dist[nex], nex))\n\n\ndijkstra(K)\nfor xi,yi in zip(x,y):\n print(dist[xi] + dist[yi])"]
['Runtime Error', 'Accepted']
['s820657278', 's538656599']
[37040.0, 54188.0]
[493.0, 1109.0]
[661, 949]
p03634
u007550226
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['n= int(input())\nbranchdict = {}\nfor i in range(n-1):\n a,b,c= map(int,input().split())\n branchdict[a-1] = branchdict.get(a-1,[]) + [(b-1,c)]\n branchdict[b-1] = branchdict.get(b-1,[]) + [(a-1,c)]\nq,k= map(int,input().split())\ncost = [0] * n\ndef dfs(curnode,pre,addcost):\n cost[curnode]=addcost\n passedf[curnode]=True\n if curnode in branchdict.keys():\n for abr in branchdict[curnode]:\n if abr[0]!=pre:\n dfs(abr[0],curnode,addcost+abr[1])\ndfs(k-1,-1,0)\nfor i in range(q):\n x,y= map(int,input().split())\n print(cost[x-1]+cost[y-1])', 'import sys\nsys.setrecursionlimit(1000000000)\ninput = sys.stdin.readline\nn= int(input())\nbd = [[] for _ in range(n)]\nfor i in range(n-1):\n a,b,c= map(int,input().split())\n bd[a-1].append((b-1,c))\n bd[b-1].append((a-1,c))\nq,k= map(int,input().split())\npassedf = [False] * n\ncost = [0] * n\ndef dfs(curnode,addcost):\n for abr in bd[curnode]:\n if not passedf[abr[0]]:\n cost[abr[0]]=addcost+abr[1]\n passedf[abr[0]]=True\n dfs(abr[0],addcost+abr[1])\ndfs(k-1,0)\nfor i in range(q):\n x,y= map(int,input().split())\n print(cost[x-1]+cost[y-1])', 'import sys\nsys.setrecursionlimit(1000000000)\ninput = sys.stdin.readline\nn= int(input())\nbd = [[] for _ in range(n)]\nfor i in range(n-1):\n a,b,c= map(int,input().split())\n bd[a-1].append((b-1,c))\n bd[b-1].append((a-1,c))\nq,k= map(int,input().split())\ncost = [0] * n\ndef dfs(curnode,pre,addcost):\n for abr in bd[curnode]:\n if abr[0]!=pre:\n cost[abr[0]]=addcost+abr[1]\n dfs(abr[0],curnode,addcost+abr[1])\ndfs(k-1,-1,0)\nfor i in range(q):\n x,y= map(int,input().split())\n print(cost[x-1]+cost[y-1])']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s583981719', 's709435413', 's008879740']
[44948.0, 136496.0, 135728.0]
[2104.0, 686.0, 702.0]
[583, 588, 540]
p03634
u067729694
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N, M, R = map(int, input().split())\nR_LIST = list(map(int, input().split()))\nABC = []\nfor _ in range(M):\n a,b,c = map(int, input().split())\n ABC.append((a,b,c))\n\nedges = ABC[:]\n\n\ndef warshall_floyd(d, n):\n \n \n \n for k in range(n):\n for i in range(n):\n for j in range(n):\n d[i][j] = min(d[i][j],d[i][k] + d[k][j])\n return d\n\n\ngraph = [[float("inf") for i in range(N)] for i in range(N)] \nfor x,y,z in edges:\n graph[x-1][y-1] = z\n graph[y-1][x-1] = z\nfor i in range(N):\n graph[i][i] = 0 \n\n\nshortest = warshall_floyd(graph, N)\n \n\nimport sys\nINT_MAX = sys.maxsize # 9223372036854775807\nans = INT_MAX\n\nimport itertools\nline = R_LIST\nfor l in itertools.permutations(line):\n #print(l)\n tmp_len = 0\n for a,b in zip(l[:-1], l[1:]):\n tmp_len += shortest[a-1][b-1]\n\n #print(tmp_len)\n ans = min(ans, tmp_len)\nprint(ans)', 'N = int(input())\nABC = []\nfor _ in range(N-1):\n a,b,c = map(int, input().split())\n ABC.append((a,b,c))\n\nQ, K = map(int, input().split())\nXY = []\nfor _ in range(Q):\n x,y = map(int, input().split())\n XY.append((x,y))\n \nedges = ABC[:]\n\ngraph = {}\nfor a,b,c in edges:\n if not a in graph:\n graph[a] = {}\n if not b in graph:\n graph[b] = {}\n graph[a][b] = c\n graph[b][a] = c\n\n\nfrom heapq import heappush, heappop\n\ndef dijkstra(graph, start):\n A = [None] * (N+1)\n queue = [(0, start)]\n while queue:\n path_len, v = heappop(queue)\n if A[v] is None: # v is unvisited\n A[v] = path_len\n for w, edge_len in graph[v].items():\n if A[w] is None:\n heappush(queue, (path_len + edge_len, w))\n\n # to give same result as original, assign zero distance to unreachable vertices \n return [0 if x is None else x for x in A]\n\nshortest = dijkstra(graph, K)\n\n\nquestions = XY\n\nfor x,y in questions:\n ans = shortest[x] + shortest[y]\n print(ans)']
['Runtime Error', 'Accepted']
['s656699334', 's344897469']
[3192.0, 85856.0]
[18.0, 1122.0]
[1093, 1073]
p03634
u067983636
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import queue\n\nN = int(input())\nE = {n: set() for n in range(N)}\n\nfor _ in range(N - 1):\n a, b, c = map(int, input().split())\n a -= 1\n b -= 1\n E[a].add((b, c))\n E[b].add((a, c))\n\ndef m():\n Q, K = map(int, input().split())\n K -= 1\n dist = [-1] * N\n already = set()\n que = queue.Queue()\n dist[K] = 0\n que.put(K)\n while not que.empty():\n now = que.get()\n out = E[now]\n for n, c in out:\n if dist[n] != -1:\n continue\n dist[n] = dist[now] + c \n que.put(n)\n \n res = ""\n for _ in range(Q):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n res += str(dist[x] + dist[y]) + "\\n"\n \n print(res)\n\n', 'import queue\nimport sys\ninput = sys.stdin.readline\n\nN = int(input())\nE = {n: set() for n in range(N)}\n\nfor _ in range(N - 1):\n a, b, c = map(int, input().split())\n a -= 1\n b -= 1\n E[a].add((b, c))\n E[b].add((a, c))\n\ndef m():\n Q, K = map(int, input().split())\n K -= 1\n dist = [-1] * N\n already = set()\n que = queue.Queue()\n dist[K] = 0\n que.put(K)\n while not que.empty():\n now = que.get()\n out = E[now]\n for n, c in out:\n if dist[n] != -1:\n continue\n dist[n] = dist[now] + c \n que.put(n)\n \n for _ in range(Q):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n print(dist[x] + dist[y])\n\nif __name__ == "__main__":\n m()\n']
['Wrong Answer', 'Accepted']
['s351902116', 's006989207']
[61272.0, 65628.0]
[568.0, 1274.0]
[742, 770]
p03634
u089142196
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque\n\nN=int(input())\na=[0]*(N-1)\nb=[0]*(N-1)\nc=[0]*(N-1)\nL=[ [] for _ in range(N)]\nfor i in range(N-1):\n a[i],b[i],c[i]= map(int,input().split())\n L[a[i]-1].append((b[i]-1,c[i]))\n L[b[i]-1].append((a[i]-1,c[i]))\nQ,K= map(int,input().split())\n \n\n\nd=[ -1 for i in range(N)]\n\ndef BFS(x):\n v=deque([x])\n d[x]=0\n \n while len(v)>0:\n s=v.popleft() \n for item in L[s]:\n if d[item[0]]==-1:\n d[item[0]]=d[s]+item[1]\n v.append(item[0])\nBFS(K-1)\n\nx=[0]*Q\ny=[0]*Q\nfor j in range(Q):\n x[i],y[i] = map(int,input().split())\n print(d[x[i]-1]+d[y[i]-1])', 'from collections import deque\nfrom sys import stdin\ninput=stdin.readline\n\nN=int(input())\na=[0]*(N-1)\nb=[0]*(N-1)\nc=[0]*(N-1)\nL=[ [] for _ in range(N)]\nfor i in range(N-1):\n a[i],b[i],c[i]= map(int,input().split())\n L[a[i]-1].append((b[i]-1,c[i]))\n L[b[i]-1].append((a[i]-1,c[i]))\nQ,K= map(int,input().split())\n \n\n\nd=[ -1 for i in range(N)]\n\ndef BFS(x):\n v=deque([x])\n d[x]=0\n \n while len(v)>0:\n s=v.popleft() \n for item in L[s]:\n if d[item[0]]==-1:\n d[item[0]]=d[s]+item[1]\n v.append(item[0])\nBFS(K-1)\n\nx=[0]*Q\ny=[0]*Q\nfor i in range(Q):\n x[i],y[i] = map(int,input().split())\n print(d[x[i]-1]+d[y[i]-1])']
['Runtime Error', 'Accepted']
['s198186541', 's374591768']
[54068.0, 60320.0]
[1495.0, 771.0]
[654, 697]
p03634
u102461423
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from scipy.sparse import csc_matrix\nimport sys\ninput = sys.stdin.readline\n\nN = int(input())\nABC = [[int(x) for x in input().split()] for _ in range(N-1)]\nrow,col,val = zip(*ABC)\n\nedge = csc_matrix((val,(row,col)),(N+1,N+1))\n', 'from scipy.sparse import lil_matrix\nimport sys\ninput = sys.stdin.readline\n\nprint(scipy.__version__())\nN = int(input())\nedge = lil_matrix((N+1,N+1))\n \nfor _ in range(N-1):\n a,b,c = map(int,input().split())\n edge[a,b] = c\n \nQ,K = map(int,input().split())\n \nfrom scipy.sparse.csgraph import dijkstra\ndist = dijkstra(edge,directed = False, indices = K).astype(int)\n \nfor _ in range(Q):\n x,y = map(int,input().split())\n print(dist[x] + dist[y])', 'import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**6)\n\nN = int(input())\nedge = [[] for _ in range(N+1)]\n \nfor _ in range(N-1):\n a,b,c = map(int,input().split())\n edge[a].append((b,c))\n edge[b].append((a,c))\n\nQ,K = map(int,input().split())\n\ndist = [None]*(N+1)\n\ndef set_dist(x,d):\n dist[x] = d\n for y,dd in edge[x]:\n if dist[y] is not None:\n continue\n set_dist(y,d+dd)\n\nset_dist(K,0)\n\nfor _ in range(Q):\n x,y = map(int,input().split())\n print(dist[x] + dist[y])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s660628181', 's999425583', 's669420511']
[44468.0, 13676.0, 131756.0]
[404.0, 171.0, 632.0]
[224, 443, 491]
p03634
u111497285
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['# http://wakabame.hatenablog.com/entry/2017/09/03/213522\n\nimport sys\ninput = sys.stdin.readline\n\n\nN = int(input())\n\n\nedges = [list(map(int, input().split())) for i in range(N)]\n\n\nQ, K = map(int, input().split())\n\n\nxy = [list(map(int, input().split())) for i in range(Q)]\n\n\n\ndef BFS(K, edges, N):\n \n \n roots = [ [] for i in range(N) ]\n for a, b, c in edges:\n roots[a-1] += [(b-1, c)]\n roots[b-1] += [(a-1, c)]\n # memo\n dist = [-1] * N\n \n stack = []\n stack.append(K)\n dist[K] = 0\n while stack:\n label = stack.pop(-1)\n for i, c roots[label]:\n \n \n if dist[i] == -1:\n dist[i] = dist[label] + c\n stack += [i]\n return dist\n\ndistance = BFS(K - 1, edges, N)\n\nfor i in range(Q):\n print(distance[xy[i][0] - 1] + distance[xy[i][1] - 1])\n \n\n\n', '# http://wakabame.hatenablog.com/entry/2017/09/03/213522\n\nimport sys\ninput = sys.stdin.readline\n\n\nN = int(input())\n\n\nedges = [list(map(int, input().split())) for i in range(N)]\n\n\nQ, K = map(int, input().split())\n\n\nxy = [list(map(int, input().split())) for i in range(Q)]\n\n\n\ndef BFS(K, edges, N):\n \n \n roots = [ [] for i in range(N) ]\n for a, b, c in edges:\n roots[a-1] += [(b-1, c)]\n roots[b-1] += [(a-1, c)]\n # memo\n dist = [-1] * N\n \n stack = []\n stack.append(K)\n dist[K] = 0\n while stack:\n label = stack.pop(-1)\n for i, c in roots[label]:\n \n \n if dist[i] == -1:\n dist[i] = dist[label] + c\n stack += [i]\n return dist\n\ndistance = BFS(K - 1, edges, N)\n\nfor i in range(Q):\n print(distance[xy[i][0] - 1] + distance[xy[i][1] - 1])\n \n\n\n', '# http://wakabame.hatenablog.com/entry/2017/09/03/213522\n\nimport sys\ninput = sys.stdin.readline\n\n\nN = int(input())\n\n\nedges = [list(map(int, input().split())) for i in range(N - 1)]\n\n\nQ, K = map(int, input().split())\n\n\nxy = [list(map(int, input().split())) for i in range(Q)]\n\n\n\ndef BFS(K, edges, N):\n \n \n roots = [ [] for i in range(N) ]\n for a, b, c in edges:\n roots[a-1] += [(b-1, c)]\n roots[b-1] += [(a-1, c)]\n # memo\n dist = [-1] * N\n \n stack = []\n stack.append(K)\n dist[K] = 0\n while stack:\n label = stack.pop(-1)\n for i, c in roots[label]:\n \n \n if dist[i] == -1:\n dist[i] = dist[label] + c\n stack += [i]\n return dist\n\ndistance = BFS(K - 1, edges, N)\n\nfor i in range(Q):\n print(distance[xy[i][0] - 1] + distance[xy[i][1] - 1])\n \n\n\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s720701785', 's808018813', 's263566018']
[3064.0, 81208.0, 85984.0]
[17.0, 546.0, 806.0]
[1509, 1512, 1516]
p03634
u114920558
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque\n\nN = int(input())\ngraph = [[] for _ in range(N+1)] \nlong = [0] * (N+1) \n\nfor i in range(N-1):\n x, y, z = map(int, input().split())\n graph[x].append([y, z])\n graph[y].append([x, z])\n \nQ, K = map(int, input().split())\nx = list()\ny = list()\n\nfor i in range(Q):\n x_i, y_i = map(int, input().split())\n x.append(x_i)\n y.append(y_i)\n\n \nfor i in range(1,N+1): を求める\n q = deque([K])\n while q:\n t = q.popleft()\n for i in range(len(graph[t])):\n next_t = graph[t][i][0]\n if(long[next_t] > 0):\n continue\n \n else:\n q.append(next_t)\n long[next_t] = long[t] + graph[t][i][1]\n \n\nfor i in range(Q):\n ans = long[x[i]] + long[y[i]]\n print(ans)', 'from collections import deque\n\nN = int(input())\ngraph = [[] for _ in range(N+1)] \nlong = [0] * (N+1) \n\nfor i in range(N-1):\n x, y, z = map(int, input().split())\n graph[x].append([y, z])\n graph[y].append([x, z])\n \nQ, K = map(int, input().split())\nx = [0] * Q\ny = [0] * Q\n\nfor i in range(Q):\n x_i, y_i = map(int, input().split())\n x[i] = x_i\n y[i] = y_i\n \nfor i in range(1,N+1): を求める\n q = deque([K])\n while q:\n t = q.popleft()\n tlen = len(graph[t])\n for i in range(tlen):\n next_t = graph[t][i][0]\n if(long[next_t] > 0):\n continue\n q.append(next_t)\n long[next_t] = long[t] + graph[t][i][1]\n \n\nfor i in range(Q):\n print(long[x[i]] + long[y[i]])', 'import sys\nsys.setrecursionlimit(500000)\n \nN = int(input())\nABC = [list(map(int, input().split())) for i in range(N-1)]\nQ, K = map(int, input().split())\nD = [0] * (N+1)\nL = [[] for i in range(N+1)]\nfor a, b, c in ABC:\n L[a].append([b, c])\n L[b].append([a, c])\n \n \ndef dfs(n, np):\n for nc in L[n]:\n if nc[0] == np:\n continue\n else:\n D[nc[0]] = D[n] + nc[1]\n dfs(nc[0], n)\n \n \ndfs(K, 0)\nfor i in range(Q):\n x, y = map(int, input().split())\n print(D[x] + D[y])\n']
['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s774645311', 's847691102', 's661866830']
[58108.0, 57848.0, 152280.0]
[2107.0, 2107.0, 1649.0]
[838, 812, 520]
p03634
u119714109
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\nn = ni()\ng = []\nfor i in range(n+1): g.append([])\n\nfor i in range(n-1):\n a, b, c = na()\n g[a].append((b,c))\n g[b].append((a,c))\n\nq,k = na()\n\ndef dfs(cur, pre, g, par, dw, w):\n dw[cur] = w\n par[cur] = pre\n for e in g[cur]:\n if e[0] != pre:\n dfs(e[0], cur, g, par, dw, w + e[1])\n\npar = [-1] * (n+2)\ndw = [-1] * (n+2)\nfrom asyncio import Queue\nqs = Queue()\nqs.put(k)\ndw[k] = 0\n\nwhile not qs.empty():\n cur = qs.get()\n for e in g[cur]:\n if e[0] != par[cur]:\n par[e[0]] = cur\n dw[e[0]] = dw[cur] + e[1]\n qs.put(e[0])\n\n\n\n\nfor z in range(q):\n x, y = na()\n print(dw[x] + dw[y])\n\n', 'import sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\nn = ni()\ng = []\nfor i in range(n+1): g.append([])\n\nfor i in range(n-1):\n a, b, c = na()\n g[a].append((b,c))\n g[b].append((a,c))\n\nq,k = na()\n\ndef dfs(cur, pre, g, par, dw, w):\n dw[cur] = w\n par[cur] = pre\n for e in g[cur]:\n if e[0] != pre:\n dfs(e[0], cur, g, par, dw, w + e[1])\n\npar = [-1] * (n+2)\ndw = [-1] * (n+2)\nfrom asyncio import Queue\nqs = Queue()\nqs.put_nowait(k)\ndw[k] = 0\n\nwhile not qs.empty():\n cur = qs.get_nowait()\n for e in g[cur]:\n if e[0] != par[cur]:\n par[e[0]] = cur\n dw[e[0]] = dw[cur] + e[1]\n qs.put_nowait(e[0])\n\n\n\n\nfor z in range(q):\n x, y = na()\n print(dw[x] + dw[y])']
['Wrong Answer', 'Accepted']
['s232729023', 's325046446']
[49916.0, 54588.0]
[688.0, 1050.0]
[824, 843]
p03634
u123756661
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["from collections import deque\n\ndef main()\n n=int(input())\n l=[0]*n\n d={}\n for i in range(n-1):\n a,b,c=map(int,input().split())\n a-=1\n b-=1\n if a in d:\n d[a].add((b,c))\n else:\n d[a]={(b,c)}\n if b in d:\n d[b].add((a,c))\n else:\n d[b]={(a,c)}\n q,k=map(int,input().split())\n k-=1\n p=deque([k])\n while len(p):\n w=p.popleft()\n for i in d[w]:\n if (l[i[0]]==0 and i[0]!=k) or (l[i[0]]!=0 and l[i[0]]>l[w]+i[1]):\n l[i[0]]=l[w]+i[1]\n p.append(i[0])\n\n for i in range(q):\n x,y=map(int,input().split())\n print(l[x-1]+l[y-1])\nif __name__ == '__main__':\n main()\n", "def main()\n n=int(input())\n l=[0]*n\n d={}\n for i in range(n-1):\n a,b,c=map(int,input().split())\n a-=1\n b-=1\n if a in d:\n d[a].add((b,c))\n else:\n d[a]={(b,c)}\n if b in d:\n d[b].add((a,c))\n else:\n d[b]={(a,c)}\n q,k=map(int,input().split())\n k-=1\n p=deque([k])\n while len(p):\n w=p.popleft()\n for i in d[w]:\n if (l[i[0]]==0 and i[0]!=k) or (l[i[0]]!=0 and l[i[0]]>l[w]+i[1]):\n l[i[0]]=l[w]+i[1]\n p.append(i[0])\n\n for i in range(q):\n x,y=map(int,input().split())\n print(l[x-1]+l[y-1])\nif __name__ == '__main__':\n main()\n", "from collections import deque\n\ndef main():\n n=int(input())\n l=[0]*n\n d={}\n for i in range(n-1):\n a,b,c=map(int,input().split())\n a-=1\n b-=1\n if a in d:\n d[a].add((b,c))\n else:\n d[a]={(b,c)}\n if b in d:\n d[b].add((a,c))\n else:\n d[b]={(a,c)}\n q,k=map(int,input().split())\n k-=1\n p=deque([k])\n while len(p):\n w=p.popleft()\n for i in d[w]:\n if (l[i[0]]==0 and i[0]!=k) or (l[i[0]]!=0 and l[i[0]]>l[w]+i[1]):\n l[i[0]]=l[w]+i[1]\n p.append(i[0])\n\n for i in range(q):\n x,y=map(int,input().split())\n print(l[x-1]+l[y-1])\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s287143624', 's756435033', 's627477292']
[2940.0, 2940.0, 61732.0]
[17.0, 17.0, 1451.0]
[738, 707, 738]
p03634
u129836004
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(10**6)\nn=int(input())\nG=[[]for i in range(n+1)]\nfor i in range(n-1):\n a, b, c = map(int,input().split())\n G[a] += (b,c)\n G[b] += (a,c)\nq, k = map(int,input().split())\nd = [0]*(n+1) \ndef f(v,p,u): \n d[v] = u\n for t, c in G[v]:\n if p != t:\n f(t,v,u+c)\nf(k,0,0)\nfor i in range(q):\n x, y = map(int,input().split())\n print(d[x]+d[y])', 'import sys\nsys.setrecursionlimit(2*10**5)\nn=int(input())\nG=[[]for i in range(n+1)]\nfor i in range(n-1):\n a, b, c = map(int,input().split())\n G[a] += (b,c),\n G[b] += (a,c),\nq, k = map(int,input().split())\nd = [0]*(n+1) \ndef f(v,p,u): \n d[v] = u\n for t, c in G[v]:\n if p != t:\n f(t,v,u+c)\nf(k,0,0)\nfor i in range(q):\n x, y = map(int,input().split())\n print(d[x]+d[y])']
['Runtime Error', 'Accepted']
['s064909144', 's925308527']
[26156.0, 132400.0]
[459.0, 1407.0]
[496, 500]
p03634
u170183831
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque\n\ndef solve(n, ABC, q, k, XY):\n graph = [[] for _ in range(n)]\n for a, b, c in ABC:\n graph[a - 1].append((b - 1, c))\n graph[b - 1].append((a - 1, c))\n\n q = deque(maxlen=n)\n q.append((k - 1, 0))\n used = {k - 1}\n l = [] * n\n while len(q) > 0:\n node, length = q.popleft()\n l[node] = length\n for next, next_length in graph[node]:\n if next in used:\n continue\n q.append((next, length + next_length))\n used.add(next)\n return l\n', "from collections import deque\n\ndef solve(n, ABC, q, k, XY):\n graph = [[] for _ in range(n)]\n for a, b, c in ABC:\n graph[a - 1].append((b - 1, c))\n graph[b - 1].append((a - 1, c))\n\n q = deque(maxlen=n)\n q.append((k - 1, 0))\n used = {k - 1}\n l = [0] * n\n while len(q) > 0:\n node, length = q.popleft()\n l[node] = length\n for next, next_length in graph[node]:\n if next in used:\n continue\n q.append((next, length + next_length))\n used.add(next)\n\n return [l[x - 1] + l[y - 1] for x, y in XY]\n\n_n = int(input())\n_ABC = [list(map(int, input().split())) for _ in range(_n - 1)]\n_q, _k = map(int, input().split())\n_XY = [list(map(int, input().split())) for _ in range(_q)]\nprint(*solve(_n, _ABC, _q, _k, _XY), sep='\\n')"]
['Wrong Answer', 'Accepted']
['s114202645', 's449977985']
[3316.0, 95204.0]
[20.0, 1049.0]
[556, 816]
p03634
u170201762
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from scipy.sparse.csgraph import dijkstra\nimport numpy as np\n\nN = int(input())\nedge = [[np.inf for i in range(N+1)] for i in range(N+1)]\nfor i in range(N-1):\n a,b,c = map(int,input().split())\n edge[a][b] = c\n edge[b][a] = c\ncost = dijkstra(edge)\nQ,K = map(int,input().split())\nfor i in range(Q):\n x,y = map(int,input().split())\n print(cost[x][K]+cost[y][K])', "N = int(input())\ngraph = [[] for i in range(N)]\nfor i in range(N-1):\n a,b,c = map(int,input().split())\n graph[a-1].append((c,b-1))\n graph[b-1].append((c,a-1))\nQ,K = map(int,input().split())\n\nfrom heapq import heappush, heappop\ndef dijkstra(graph:list, node:int, start:int) -> list:\n # graph[node] = [(cost, to)]\n inf = float('inf')\n dist = [inf]*node\n\n dist[start] = 0\n heap = [(0,start)]\n while heap:\n cost,thisNode = heappop(heap)\n for NextCost,NextNode in graph[thisNode]:\n dist_cand = dist[thisNode]+NextCost\n if dist_cand < dist[NextNode]:\n dist[NextNode] = dist_cand\n heappush(heap,(dist[NextNode],NextNode))\n return dist\n # dist = [costs to nodes]\n\ncost = dijkstra(graph,N,K-1)\nfor i in range(Q):\n x,y = map(int,input().split())\n print(int(cost[x-1]+cost[y-1]))"]
['Wrong Answer', 'Accepted']
['s267106196', 's021984254']
[261296.0, 48288.0]
[2126.0, 1521.0]
[372, 873]
p03634
u179169725
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(1000000)\n\nN = int(input())\nX, Y = [], []\n\ntree = {key+1: [] for key in range(N)} \n\n\n\nfor n in range(N - 1):\n a, b, c = list(map(int, input().split()))\n tree[a].append((b, c))\n tree[b].append((a, c)) \n\n# for n in tree.keys():\n\n\n\nQ, K = list(map(int, input().split()))\n\ncost = {} \n\n\ndef dfs(v, p, d):\n \n cost[v] = d\n for i, co in tree[v]:\n if i == p:\n continue\n dfs(i, v, d + co)\n\n\ndfs(K, -1, 0)\n\nprint(cost)\nans = []\nfor q in range(Q):\n x, y = list(map(int, input().split()))\n ans.append(cost[x] + cost[y])\n\nfor a in ans:\n print(a)\n', 'import sys\nsys.setrecursionlimit(1000000)\n\nN = int(input())\nX, Y = [], []\n\ntree = {key+1: [] for key in range(N)} \n\n\n\nfor n in range(N - 1):\n a, b, c = list(map(int, input().split()))\n tree[a].append((b, c))\n tree[b].append((a, c)) \n\n# for n in tree.keys():\n\n\n\nQ, K = list(map(int, input().split()))\n\ncost = {} \n\n\ndef dfs(v, p, d):\n \n cost[v] = d\n for i, co in tree[v]:\n if i == p:\n continue\n dfs(i, v, d + co)\n\n\ndfs(K, -1, 0)\n\n# print(cost)\nans = []\nfor q in range(Q):\n x, y = list(map(int, input().split()))\n ans.append(cost[x] + cost[y])\n\nfor a in ans:\n print(a)\n']
['Wrong Answer', 'Accepted']
['s925365727', 's413141247']
[157276.0, 151636.0]
[1142.0, 1136.0]
[1159, 1161]
p03634
u195608881
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['n = int(input())\n\npath = [None]*(n + 1)\nadjacent_list = [[] for i in range(n+1)]\n\nfor i in range(n - 1):\n a, b, c = list(map(int,input().split()))\n adjacent_list[a].append([b,c])\n adjacent_list[b].append([a,c])\n\ndef dfs(node_n ,distance,finished):\n \n finished.add(node_n)\n \n path[node_n] = distance\n \n for i in adjacent_list[node_n]:\n next = i[0]\n if next not in finished:\n \n dfs(next, distance + i[1],finished)\n\nq,k = list(map(int, input().split()))\ndfs(k, 0, set())\n\nfor i in range(q):\n s, g = list(map(int, input().split()))\n is path[s] is not None and path[g] is not None:\n print(path[s] + path[g])\n\n', 'import sys\n\nsys.setrecursionlimit(200000)\n\nn = int(input())\n\npath = [None]*(n + 1)\nadjacent_list = [[] for i in range(n+1)]\n\nfor i in range(n - 1):\n a, b, c = list(map(int, input().split()))\n adjacent_list[a].append([b, c])\n adjacent_list[b].append([a, c])\n\n\n\ndef dfs(node_n, distance, finished):\n \n finished.add(node_n)\n \n path[node_n] = distance\n \n for i in adjacent_list[node_n]:\n next = i[0]\n if next not in finished:\n \n dfs(next, distance + i[1], finished)\n\n\nq, k = list(map(int, input().split()))\ndfs(k, 0, set())\n\nfor i in range(q):\n s, g = list(map(int, input().split()))\n print(path[s] + path[g])\n']
['Runtime Error', 'Accepted']
['s194925882', 's618027117']
[3064.0, 140580.0]
[17.0, 1705.0]
[1039, 1041]
p03634
u200030766
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["import sys\n\nsys.setrecursionlimit(100000)\n\n\nfileobj=open('subtask_1_28.txt','rt')\n\nV=int(fileobj.readline().strip())\nE=V-1\ninf=3*10**15\nG=[]\ndist=[inf]*V\nvisited=[False]*V\n\nfor i in range(V):\n G.append([])\nfor i in range(E):\n at,bt,ct=map(int,fileobj.readline().strip().split(' '))\n G[at-1].append([ct,bt-1])\n G[bt-1].append([ct,at-1])\n\ndef dfs(v,p,d):\n \n dist[v]=d\n visited[v]=True\n for q in G[v]:\n if q[1]==p:\n continue\n elif visited[q[1]]!=True:\n dfs(q[1],v,d+q[0])\n\nQ, K=map(int,fileobj.readline().strip().split(' '))\nK-=1 \n\ndfs(K,-1,0)\n\nx=[]\ny=[]\n\nfor i in range(Q):\n xt, yt=map(int,fileobj.readline().strip().split(' '))\n x.append(xt-1)\n y.append(yt-1)\nfor i in range(Q):\n print(dist[x[i]]+dist[y[i]])\n", "import sys\n\nsys.setrecursionlimit(10000000)\n\n\nV=int(input().strip())\nE=V-1\ninf=3*10**15\nG=[]\ndist=[inf]*V\n\nfor i in range(V):\n G.append([])\nfor i in range(E):\n at,bt,ct=map(int,input().strip().split(' '))\n G[at-1].append([ct,bt-1])\n G[bt-1].append([ct,at-1])\n\nvisited=[False]*V\ndef dfs(v,p,d):\n \n dist[v]=d\n for q in G[v]:\n if q[1]==p:\n continue\n dfs(q[1],v,d+q[0])\n\nQ, K=map(int,input().strip().split(' '))\nK-=1 \n\ndfs(K,-1,0)\n\nx=[]\ny=[]\n\nfor i in range(Q):\n xt, yt=map(int,input().strip().split(' '))\n x.append(xt-1)\n y.append(yt-1)\nfor i in range(Q):\n print(dist[x[i]]+dist[y[i]])\n\n\n\n"]
['Runtime Error', 'Accepted']
['s521156381', 's315196159']
[3064.0, 140456.0]
[17.0, 1428.0]
[934, 798]
p03634
u201802797
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\ninput = sys.stdin.readline\n\ndata = int(input())\nE = [[] for _ in range(data)]\nfor _ in range(data-1):\n a, b, c = list(map(int, input().split()))\n E[a-1].append((b-1,c))\n E[b-1].append((a-1,c))\n\nnim, mike = list(map(int, input().split()))\n\nqueue = [mike-1]\ndist = [None]*data\ndist[K-1] = 0\nwhile queue:\n queue_new = []\n for q in queue:\n for e in E[q]:\n if dist[e[0]] is not None: continue\n dist[e[0]] = dist[q] + e[1]\n queue_new.append(e[0])\n queue = queue_new\n\nfor _ in range(nim):\n x, y = list(map(int, input().split()))\n print(dist[x-1]+dist[y-1])', '# solution\n\ndata=int(input())\n\nabc=[list(map(int,input().split())) for _ in [0]*(data-1)]\n\nq,k=map(int,input().split())\n\narray1=[list(map(int,input().split())) for _ in [0]*q]\n\nk-=1\n\ntree=[[] for _ in [0]*data]\n\ndist=[-1]*data\n\ndist[k]=0\n\n[tree[a-1].append([b-1,c]) for a,b,c in abc]\n\n[tree[b-1].append([a-1,c]) for a,b,c in abc]\n\nq=[k]\n\nwhile(q):\n\tqq=[]\n\tfor i in q:\n\t\tfor j,k in tree[i]:\n\t\t\tif dist[j]<0:\n\t\t\t\tdist[j]=dist[i]+k\n\t\t\t\tqq.append(j)\n\tq=qq\n\nfor x,y in array1:\n\tprint(dist[x-1]+dist[y-1])']
['Runtime Error', 'Accepted']
['s775118870', 's240603741']
[42828.0, 91044.0]
[376.0, 1348.0]
[586, 499]
p03634
u223904637
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['fron collections import deque\nn=int(input())\ng=[[] for i in range(n)]\nfor i in range(n-1):\n a,b,c=map(int,input().split())\n g[a-1].append([b-1,c])\n g[b-1].append([a-1,c])\nq,k=map(int,input().split())\nqu=deque([[k-1,0]])\nv=[0]*n\nd=[0]*n\nwhile len(qu)>0:\n s=qu.popleft()\n v[s[0]]=1\n for j in g[s[0]]:\n if not v[j[0]]:\n v[j[0]]=1\n d[j[0]]=s[1]+j[1]\n qu+=[[j[0],d[j[0]]]]\nfor i in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])\n', 'from collections import deque\nn=int(input())\ng=[[] for i in range(n)]\nfor i in range(n-1):\n a,b,c=map(int,input().split())\n g[a-1].append([b-1,c])\n g[b-1].append([a-1,c])\nq,k=map(int,input().split())\nqu=deque([[k-1,0]])\nv=[0]*n\nd=[0]*n\nwhile len(qu)>0:\n s=qu.popleft()\n v[s[0]]=1\n for j in g[s[0]]:\n if not v[j[0]]:\n v[j[0]]=1\n d[j[0]]=s[1]+j[1]\n qu+=[[j[0],d[j[0]]]]\nfor i in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])\n']
['Runtime Error', 'Accepted']
['s769623703', 's304634627']
[2940.0, 58452.0]
[17.0, 1604.0]
[503, 503]
p03634
u225388820
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from heapq import heappush,heapify,heappop\nINF = 10**10\n\nn = int(input())\n\ncost = [[INF]*n for _ in range(n)] \nes=[[] for _ in range(n)] \nd = [INF]*n \n\n\nfor i in range(n-1):\n a,b,c = map(int,input().split())\n a,b = a-1, b-1\n es[a].append((b,c))\n es[b].append((a,c))\n cost[a][b], cost[b][a] = c, c\n\n\ndef dijkstra(s):\n v = -1\n que = [(0,s)]\n heapify(que)\n d[s] = 0\n while que:\n p = heappop(que)\n v = p[1]\n if d[v] < p[0]:\n continue\n for e in es[v]:\n if d[e[0]] > d[v] + e[1]:\n d[e[0]] = d[v] + e[1]\n heappush(que, (d[e[0]], e[0])) \nq,k=map(int,input().split())\ndijkstra(k-1)\nprint(d)\nfor i in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])', 'n = int(input())\n\nes=[[] for _ in range(n)] \nd = [0]*n \nused=[True]*n\n\nfor i in range(n-1):\n a,b,c = map(int,input().split())\n a,b = a-1, b-1\n es[a].append((b,c))\n es[b].append((a,c))\n\n\ndef dfs(s,dist):\n used[s]=False\n for v,x in es[s]:\n if used[v]:\n d[v]=dist+x\n dfs(v,dist+x)\nq,k=map(int,input().split())\ndfs(k-1,0)\nprint(d)\nfor i in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])', 'from heapq import heappush,heapify,heappop\nimport sys\ninput = sys.stdin.readline\nINF = 10**18\n\nn = int(input())\n\nes=[[] for _ in range(n)] \nd = [INF]*n \n\n\nfor i in range(n-1):\n a,b,c = map(int,input().split())\n a,b = a-1, b-1\n es[a].append((b,c))\n es[b].append((a,c))\n\n\ndef dijkstra(s):\n v = -1\n que = [(0,s)]\n heapify(que)\n d[s] = 0\n while que:\n p = heappop(que)\n v = p[1]\n if d[v] < p[0]:\n continue\n for e in es[v]:\n if d[e[0]] > d[v] + e[1]:\n d[e[0]] = d[v] + e[1]\n heappush(que, (d[e[0]], e[0])) \nq,k=map(int,input().split())\ndijkstra(k-1)\nfor i in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s400769850', 's450798519', 's396049923']
[1947872.0, 47212.0, 46284.0]
[2228.0, 1500.0, 774.0]
[930, 546, 823]
p03634
u266874640
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N = int(input())\nedge = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n a,b,c = map(int,input().split())\n edge[a].append((b,c))\n edge[b].append((a,c))\nQ,K = map(int,input().split())\ndistance = [-1] * (N+1)\ndef dfs(v1,d):\n distance[v1] = d\n for v2,dd in edge[v1]:\n if distance[v2] is not -1:\n continue\n dfs(v2,d+dd)\n\ndfs(K,0)\nprint(distance)\nans = [0] * Q\nfor i in range(Q):\n x,y = map(int,input().split())\n ans[i] = distance[x]+distance[y]\nfor a in ans:\n print(a)\n', 'import sys\nsys.setrecursionlimit(10**6)\nN = int(input())\nedge = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n a,b,c = map(int,input().split())\n edge[a].append((b,c))\n edge[b].append((a,c))\nQ,K = map(int,input().split())\ndistance = [None] * (N+1)\ndef dfs(v1,d):\n distance[v1] = d\n for v2,dd in edge[v1]:\n if distance[v2] is not None:\n continue\n dfs(v2,d+dd)\n\ndfs(K,0)\n\nans = [0] * Q\nfor i in range(Q):\n x,y = map(int,input().split())\n ans[i] = distance[x]+distance[y]\nfor a in ans:\n print(a)\n']
['Runtime Error', 'Accepted']
['s785279221', 's402411456']
[49732.0, 132712.0]
[960.0, 994.0]
[512, 541]
p03634
u268210555
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['n=int(input())\ng=[[] for _ in range(n)]\nfor _ in range(n-1):\n a,b,c=map(int,input().split())\n g[a-1].append((b-1,c))\n g[b-1].append((a-1,c))\nq,k=map(int,input().split())\nd=[-1]*n\ndef f(k,c):\n d[k]=c\n for i,v in g[k]:\n if d[i]==-1:\n f(i,c+v)\nf(k-1,0)\nprint(d)\nfor _ in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])', 'import sys\nsys.setrecusionlimit(100000)\nn=int(input())\ng=[[] for _ in range(n)]\nfor _ in range(n-1):\n a,b,c=map(int,input().split())\n g[a-1].append((b-1,c))\n g[b-1].append((a-1,c))\nq,k=map(int,input().split())\nd=[-1]*n\ndef f(k,c):\n d[k]=c\n for i,v in g[k]:\n if d[i]==-1:\n f(i,c+v)\nf(k-1,0)\nfor _ in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])', 'import sys\nsys.setrecursionlimit(1000000)\nn=int(input())\ng=[[] for _ in range(n)]\nfor _ in range(n-1):\n a,b,c=map(int,input().split())\n g[a-1].append((b-1,c))\n g[b-1].append((a-1,c))\nq,k=map(int,input().split())\nd=[-1]*n\ndef f(k,c):\n d[k]=c\n for i,v in g[k]:\n if d[i]==-1:\n f(i,c+v)\nf(k-1,0)\nfor _ in range(q):\n x,y=map(int,input().split())\n print(d[x-1]+d[y-1])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s390618214', 's627141266', 's092474144']
[46492.0, 3064.0, 131632.0]
[1388.0, 17.0, 1436.0]
[368, 399, 401]
p03634
u273084112
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nimport collections\n\nsys.setrecursionlimit(1e7)\n\ndef dfs(node, parent, distance):\n depth[node] = distance\n for next_node, cost in Tree[node]:\n if next_node != parent:\n dfs(next_node, node, distance + cost)\n\nN = int(input())\n\nTree = collections.defaultdict(list)\n\nfor i in range(N - 1):\n a, b, c = map(int, input().split())\n Tree[a].append((b, c))\n Tree[b].append((a, c))\n\nq, k = map(int, input().split())\n\ndepth = {}\ndfs(k, -1, 0)\n\nfor i in range(q):\n x, y = map(int, input().split())\n print(depth[x] + depth[y])\n', 'import collections\n\ndef bfs(tree, s, distance):\n queue = collections.deque([s])\n distance[s] = 0\n\n while queue:\n v = queue.popleft()\n v_c = distance[v]\n for node, cost in tree[v]:\n if distance[node] == -1:\n distance[node] = v_c + cost\n queue.append(node)\n\nN = int(input())\n\nTree = collections.defaultdict(list)\n\nfor i in range(N - 1):\n a, b, c = map(int, input().split())\n Tree[a].append((b, c))\n Tree[b].append((a, c))\n\nq, k = map(int, input().split())\n\ndistance = collections.defaultdict(lambda : -1)\nbfs(Tree, k, distance)\n\nfor i in range(q):\n x, y = map(int, input().split())\n print(distance[x] + distance[y])\n']
['Runtime Error', 'Accepted']
['s839945412', 's609541905']
[3316.0, 58528.0]
[20.0, 1531.0]
[562, 700]
p03634
u278868910
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(1000000000)\n\nN = int(input())\nG = [[] for _ in range(N)]\nfor i in range(N - 1):\n a, b, c = list(map(int, input().split()))\n a = a - 1\n b = b - 1\n G[a].append((b, c))\n G[b].append((a, c))\n \nprint (G)\nQ, K = list(map(int,input().split()))\n\nD = [0] * N\ndef dfs(pos, pre, dis):\n D[pos] = dis\n for (to, cost) in G[pos]:\n if to == pre:\n continue\n dfs(to, pos, dis + cost)\n\n\ndfs(K - 1, -1, 0)\n\nwhile Q:\n Q = Q - 1\n x, y = list(map(lambda a:int(a) - 1, input().split()))\n ans = D[x] + D[y]\n print (ans)\n', 'import sys\nsys.setrecursionlimit(1000000000)\n\nN = int(input())\nG = [[] for _ in range(N)]\nfor i in range(N - 1):\n a, b, c = list(map(int, input().split()))\n a = a - 1\n b = b - 1\n G[a].append((b, c))\n G[b].append((a, c))\n \nQ, K = list(map(int,input().split()))\n\nD = [0] * N\ndef dfs(pos, pre, dis):\n D[pos] = dis\n for (to, cost) in G[pos]:\n if to == pre:\n continue\n dfs(to, pos, dis + cost)\n\n\ndfs(K - 1, -1, 0)\n\nwhile Q:\n Q = Q - 1\n x, y = list(map(lambda a:int(a) - 1, input().split()))\n ans = D[x] + D[y]\n print (ans)\n']
['Wrong Answer', 'Accepted']
['s996343116', 's797575861']
[142944.0, 136780.0]
[1810.0, 1638.0]
[589, 579]
p03634
u281303342
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(1000000)\n\nN = int(input())\nX = [[] for _ in range(N)]\n\nfor i in range(N-1):\n a,b,c = map(int,input().split())\n X[a-1].append((b-1,c))\n X[b-1].append((a-1,c))\n\ncost = [-1]*N\ndef calc(i,c):\n \n cost[i] = c\n \n for ni,nc in X[i]:\n \n if cost[ni] == -1:\n calc(ni,c+nc)\n\nQ,K = map(int,input().split())\n\ncalc(K-1,0)\n\nfor i in range(Q):\n x,y = map(int,input().split())\n #print(cost[x-1]+cost[y-1])\n\n', 'import sys\nsys.setrecursionlimit(1000000)\n\ndef dfs(n,p,d):\n visited[n] = True\n dist[n] = d\n for (i,c) in A[n]:\n if i != p and not visited[i]:\n dfs(i,n,d+c)\n\nN = int(input())\nA = [[] for _ in range(N)]\nfor _ in range(N-1):\n a,b,c = map(int,input().split())\n A[a-1].append((b-1,c))\n A[b-1].append((a-1,c))\nQ,K = map(int,input().split())\nB = []\nfor _ in range(Q):\n x,y = map(int,input().split())\n B.append((x,y))\n\ndist = [-1]*N\nvisited = [False]*N\ndfs(K-1,N,0)\n\nfor (x,y) in B:\n print(dist[x-1]+dist[y-1])\n\n']
['Wrong Answer', 'Accepted']
['s292144085', 's064556406']
[130096.0, 146028.0]
[838.0, 1080.0]
[614, 549]
p03634
u318127926
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['n = int(input())\ngraph = [[] for _ in range(n)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a-=1\n b-=1\n graph[a].append((b, c))\n graph[b].append((a, c))\nq, k = map(int, input().split())\nk-=1\nseen = [False]*n\nl = [0]*n\n\nfor _ in range(q):\n x, y = map(int, input().split())\n print(l[x-1]+l[y-1])', 'import sys\nn = int(input())\ngraph = [[] for _ in range(n)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a-=1\n b-=1\n graph[a].append((b, c))\n graph[b].append((a, c))\nq, k = map(int, input().split())\nk -= 1\nxy = []\nfor _ in range(q):\n x, y = map(int, input().split())\n x-=1\n y-=1\n xy.append((x, y))\n\ndef DFS(node, p_node, length):\n l[node] = length\n for i, j in graph[node]:\n if i==p_node:\n continue\n DFS(i, node, length+j)\nsys.setrecursionlimit(2 * N)\nl = [0]*n\nDFS(k, -1, 0)\nfor x, y in xy:\n print(l[x]+l[y])\n', 'n = int(input())\ngraph = [[] for _ in range(n+1)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n graph[a].append((b, c))\n graph[b].append((a, c))\nq, k = map(int, input().split())\nxy = []\nfor _ in range(q):\n x, y = map(int, input().split())\n xy.append((x, y))\n\nl = [0]*(n+1)\ndef DFS(node, p_node, length):\n l[node] = length\n for i, j in graph[node]:\n if i==p_node:\n continue\n DFS(i, node, length+j)\nDFS(k, -1, 0)\nfor x, y in xy:\n print(0)', 'import sys\nn = int(input())\ngraph = [[] for _ in range(n)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a-=1\n b-=1\n graph[a].append((b, c))\n graph[b].append((a, c))\nq, k = map(int, input().split())\nk -= 1\nxy = []\nfor _ in range(q):\n x, y = map(int, input().split())\n x-=1\n y-=1\n xy.append((x, y))\n\ndef DFS(node, p_node, length):\n l[node] = length\n for i, j in graph[node]:\n if i==p_node:\n continue\n DFS(i, node, length+j)\nsys.setrecursionlimit(2 * n)\nl = [0]*n\nDFS(k, -1, 0)\nfor x, y in xy:\n print(l[x]+l[y])\n']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s284125998', 's693210220', 's782001988', 's703108143']
[38832.0, 50736.0, 56756.0, 145140.0]
[1284.0, 819.0, 892.0, 1035.0]
[315, 584, 468, 584]
p03634
u341926204
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque\n\nN = int(input())\nedges = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n ai, bi, ci = map(int, input().split())\n edges[ai].append((bi, ci))\n edges[bi].append((ai, ci))\nQ, K = map(int, input().split())\n\ndistance = [-1]*(N+1)\n# def add_weight(k, pre):\n# for v in edges[k]:\n# d, w = v\n\n# distance[d] = w + distance[k]\n# add_weight(d, k)\n\nque = deque()\nque.append(K); distance[K] = 0\nwhile len(que):\n a = que.popleft()\n for b, c in edges[a]:\n if distance[b] == -1:\n distance[b] = c + distance[a]\n que.append(b)\n\nprint(distance)\n\nfor _ in range(Q):\n s, e = map(int, input().split())\n print(distance[s] + distance[e])', 'from collections import deque\n\nN = int(input())\nedges = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n ai, bi, ci = map(int, input().split())\n edges[ai].append((bi, ci))\n edges[bi].append((ai, ci))\nQ, K = map(int, input().split())\n\ndistance = [-1]*(N+1)\n# def add_weight(k, pre):\n# for v in edges[k]:\n# d, w = v\n\n# distance[d] = w + distance[k]\n# add_weight(d, k)\n\nque = deque()\nque.append(edges[K]); distance[K] = 0\nwhile len(que):\n a = que.popleft()\n for b, c in a:\n if distance[b] == -1:\n distance[b] = c\n que.append(edges[b])\n\nfor _ in range(Q):\n s, e = map(int, input().split())\n print(distance[s] + distance[e])', 'N = int(input())\nedges = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n ai, bi, ci = map(int, input().split())\n edges[ai].append((bi, ci))\n edges[bi].append((ai, ci))\nQ, K = map(int, input().split())\n\ndistance = [-1]*(N+1)\n# def add_weight(k, pre):\n# for v in edges[k]:\n# d, w = v\n\n# distance[d] = w + distance[k]\n# add_weight(d, k)\n\nque = deque()\nque.append(edges[K]); distance[K] = 0\nwhile len(que):\n a = que.popleft()\n for b, c in a:\n if distance[b] == -1:\n distance[b] = c\n que.append(edges[b])\n\nfor _ in range(Q):\n s, e = map(int, input().split())\n print(distance[s] + distance[e])', 'N = int(input())\nedges = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n ai, bi, ci = map(int, input().split())\n edges[ai].append((bi, ci))\n edges[bi].append((ai, ci))\nQ, K = map(int, input().split())\n\nweighted_nodes = [0]*(N+1)\ndef add_weight(k, pre):\n for v in edges[k]:\n d, w = v\n if d != pre:\n weighted_nodes[d] = w + weighted_nodes[k]\n add_weight(d, k)\nadd_weight(K, -1)\n\nfor _ in range(Q):\n s, e = map(int, input().split()))\n print(weighted_nodes[s] + weighted_nodes[e])', 'from collections import deque\n\nN = int(input())\nedges = [[] for _ in range(N+1)]\nfor _ in range(N-1):\n ai, bi, ci = map(int, input().split())\n edges[ai].append((bi, ci))\n edges[bi].append((ai, ci))\nQ, K = map(int, input().split())\n\ndistance = [-1]*(N+1)\n# def add_weight(k, pre):\n# for v in edges[k]:\n# d, w = v\n\n# distance[d] = w + distance[k]\n# add_weight(d, k)\n\nque = deque()\nque.append(K); distance[K] = 0\nwhile len(que):\n a = que.popleft()\n for b, c in edges[a]:\n if distance[b] == -1:\n distance[b] = c + distance[a]\n que.append(b)\n\n# print(distance)\n\nfor _ in range(Q):\n s, e = map(int, input().split())\n print(distance[s] + distance[e])']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s488309758', 's894970193', 's906059423', 's920215264', 's436158899']
[46740.0, 39192.0, 37812.0, 3064.0, 44568.0]
[1361.0, 1383.0, 454.0, 17.0, 1352.0]
[768, 744, 713, 529, 770]
p03634
u346222974
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int N = 100005;\n\nlong long d[N];\nvector<pair<int, int>> g[N];\n\nvoid dfs(int u, int f, long long w) {\n d[u] = w;\n for (auto &go : g[u]) {\n if (go.first != f) {\n dfs(go.first, u, w + go.second);\n }\n }\n}\n\nint main() {\n int n;\n scanf("%d", &n);\n for (int i = 1; i < n; ++i) {\n int u, v, w;\n scanf("%d %d %d", &u, &v, &w);\n g[u].push_back({v, w});\n g[v].push_back({u, w});\n }\n int q, k;\n scanf("%d %d", &q, &k);\n dfs(k, k, 0);\n while (q--) {\n int u, v;\n scanf("%d %d", &u, &v);\n cout << d[u] + d[v] << endl;\n }\n return 0;\n}\n', 'n = int(input())\ng = []\nd = [0] * (n + 1)\nfor i in range(n + 1):\n g.append([]);\nfor i in range(n - 1):\n u, v, w = map(int, input().split())\n g[u].append([v, w])\n g[v].append([u, w])\nq, k = map(int, input().split())\ndef bfs(u):\n s = []\n s.append(u)\n while s:\n v = s[-1]\n s.pop()\n for go in g[v]:\n if not d[go[0]] and go[0] != u:\n d[go[0]] = d[v] + go[1]\n s.append(go[0])\nbfs(k)\nwhile q > 0:\n u, v = map(int, input().split())\n print(d[u] + d[v])\n q -= 1\n']
['Runtime Error', 'Accepted']
['s443639790', 's266715716']
[2940.0, 51408.0]
[17.0, 1641.0]
[618, 544]
p03634
u360515075
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import numpy as np\nfrom scipy.sparse.csgraph import floyd_warshall\nfrom scipy.sparse import csr_matrix\nN = int(input())\nL = np.full((N, N), np.inf)\nfor i in range(N-1):\n a, b, c = map(int, input().split())\n L[a-1][b-1] = c\n L[b-1][a-1] = c\nL = csr_matrix(L)\nL = floyd_warshall(L, 0)\nprint (L)\nQ, K = map(int, input().split())\nK -= 1\nfor i in range(Q):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n print (int(L[x][K] + L[K][y]))', 'from collections import defaultdict as dd\nfrom collections import deque\nN = int(input())\nD =dd(list)\nfor i in range(N-1):\n a, b, c = map(int, input().split())\n D[a-1].append((b-1, c))\n D[b-1].append((a-1, c))\n\nQ, K = map(int, input().split())\nK -= 1\nL = [0 for _ in range(N)]\nq = deque([])\nq.append(K)\nwhile len(q) > 0:\n a = q.pop()\n for b, c in D[a]:\n if L[b] == 0:\n L[b] = L[a] + c\n q.append(b)\n\nfor i in range(Q):\n x, y = map(int, input().split())\n print (L[x-1] + L[y-1])']
['Runtime Error', 'Accepted']
['s296157798', 's415657171']
[1830356.0, 53280.0]
[2114.0, 1526.0]
[440, 495]
p03634
u367130284
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['#from numpy import*\nfrom scipy.sparse.csgraph import shortest_path\nfrom scipy.sparse import csr_matrix\n\nfrom collections import* \nfrom fractions import gcd\nfrom functools import* #reduce\nfrom itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate\nfrom operator import mul\nfrom bisect import* \nfrom heapq import* \nfrom math import factorial,pi\nfrom copy import deepcopy\nimport sys\n\nsys.setrecursionlimit(10**6)\n\ndef main():\n n=int(input())\n graph=[[0]*n for i in range(n)]\n for i in range(n-1):\n a,b,c=map(int,input().split())\n graph[a-1][b-1]=c\n graph[b-1][a-1]=c\n graph=csr_matrix(graph)\n d = shortest_path(csgraph=graph)\n q,k=map(int,input().split())\n for i in range(q):\n a,b=map(int,input().split())\n print(int(d[a-1][k-1]+d[k-1][b-1]))\nif __name__ == \'__main__\':\n main()\n', 'from collections import*\nfrom heapq import*\nimport sys\ninput=sys.stdin.readline\n \ndef BFS(point,d):\n cost=[1e18]*(n+1)\n cost[point]=0\n Q=deque()\n Q.appendleft((0,point))\n \n while Q:\n c,p=Q.pop()\n for np,co in d[p]:\n if cost[np]==1e18:\n cost[np]=c+co\n Q.appendleft((c+co,np))\n return cost\n\nn=int(input())\nd=[[]for i in range(n+1)]\nfor i in range(n-1):\n a,b,c=map(int,input().split())\n d[a].append([b,c])\n d[b].append([a,c])\n#print(d)\nq,k=map(int,input().split())\ny=BFS(k,d)\n \nfor i in range(q):\n a,b=map(int,input().split())\n print(y[a]+y[b])\n']
['Runtime Error', 'Accepted']
['s939846541', 's990992120']
[1980956.0, 56308.0]
[2249.0, 807.0]
[1033, 633]
p03634
u368780724
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import defaultdict\ndef inpl(): return [int(i) for i in input().split()]\n\npath = defaultdict(lambda: [])\nN = int(input())\nfor _ in range(N-1):\n a, b, c = inpl()\n path[a].append((b,c))\n path[b].append((a,c))\n\nctr = 1\nQ, K = inpl()\nnow = [K]\ndist = [0 for _ in range(N+1)]\nwhile True:\n for na in now.copy():\n na = now.pop()\n for nb, nc in path[na]:\n dist[nb] = dist[na] + nc\n path[nb].remove((na,nc))\n now.add(nb)\n ctr += 1\n if ctr >= N:\n break\nfor i in range(Q):\n x, y = inpl()\n print(dist[x]+dist[y])', 'from collections import defaultdict\ndef inpl(): return [int(i) for i in input().split()]\n\npath = defaultdict(lambda: [])\nN = int(input())\nfor _ in range(N-1):\n a, b, c = inpl()\n path[a].append((b,c))\n path[b].append((a,c))\n\nctr = 1\nQ, K = inpl()\nnow = {K}\ndist = [0 for _ in range(N+1)]\nwhile True:\n for na in now.copy():\n na = now.pop()\n for nb, nc in path[na]:\n dist[nb] = dist[na] + nc\n path[nb].remove((na,nc))\n now.add(nb)\n ctr += 1\n if ctr >= N:\n break\nfor i in range(Q):\n x, y = inpl()\n print(dist[x]+dist[y])']
['Runtime Error', 'Accepted']
['s796438769', 's399354819']
[43544.0, 52372.0]
[610.0, 1587.0]
[603, 603]
p03634
u373047809
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input()):s=[0for _ in[0]*n];j=[[]for _ in[0]*n]\nfor _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])\ndef f(v,p,d):\n s[v]=d\n for i,c in j[v]:\n if i==p:\n continue\n f(i,v,d+c)\nq,k=l()\ndfs(k-1,-1,0)\nfor _ in [0]*q:x,y=l();print(s[x-1]+s[y-1])', 'import sys\nsys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input());s=[0for _ in[0]*n];j=[[]for _ in[0]*n]\nfor _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])\ndef f(v,p,d):\n s[v]=d\n for i,c in j[v]:\n if i==p:\n continue\n f(i,v,d+c)\nq,k=l()\ndfs(k-1,-1,0)\nfor _ in [0]*q:x,y=l();print(s[x-1]+s[y-1])', 'import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**6)\n\nn = int(input())\n\ndis = [ 0 for _ in range(n)] \nadj = [[] for _ in range(n)] \n\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a -= 1;b-= 1\n adj[a].append([b, c])\n adj[b].append([a, c])\n\n\n\n\ndef dfs(v, p, d):\n dis[v] = d\n for i, c in adj[v]:\n if i == p:\n continue\n dfs(i, v, d+c)\n\nq, k = map(int, input().split())\nk -= 1\n\ndfs(k, -1, 0)\n\nfor _ in range(q):\n x, y = map(int, input().split())\n x -= 1;y -= 1\n print(dis[x] + dis[y])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s372820946', 's790370305', 's071444952']
[2940.0, 44104.0, 137984.0]
[17.0, 693.0, 816.0]
[346, 346, 636]
p03634
u429843511
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N = int(input())\nedges = []\nconnected = [[] for i in range(N+1)]\nfor i in range(N-1):\n x=list(map(int, input().split()))\n x[0] -= 1\n x[1] -= 1\n edges.append(x)\n connected[x[0]].append([x[1], x[2]])\n connected[x[1]].append([x[0], x[2]])\n\nQ,K = map(int, input().split())\ndepth = [0]*N\ndef DFS(v, p, d):\n depth[v] = d\n for child in connected[v]:\n if child[0] == p:\n continue\n DFS(child[0], v, d+child[1])\n\nDFS(K,-1,0)\nfor i in range(Q):\n xi, yi = map(int, input().split())\n print(depth[xi-1]+depth[yi-1])\n\n \n', 'import sys\nsys.setrecursionlimit(200000)\n\nN = int(input())\nedges = []\nconnected = [[] for i in range(100010)]\nfor i in range(N-1):\n x=list(map(int, input().split()))\n x[0] -= 1\n x[1] -= 1\n edges.append(x)\n connected[x[0]].append([x[1], x[2]])\n connected[x[1]].append([x[0], x[2]])\n\nQ,K = map(int, input().split())\nK -= 1\ndepth = [0]*100010\ndef DFS(v, p, d):\n depth[v] = d\n for child in connected[v]:\n if child[0] == p:\n continue\n DFS(child[0], v, d+child[1])\n\nDFS(K,-1,0)\nfor i in range(Q):\n xi, yi = map(int, input().split())\n print(depth[xi-1]+depth[yi-1])\n']
['Runtime Error', 'Accepted']
['s382949222', 's590129915']
[63656.0, 151232.0]
[1727.0, 1750.0]
[563, 614]
p03634
u477977638
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import defaultdict\n\nn=int(input())\ndct=defaultdict(list)\n\nfor i in range(n-1):\n a,b,c=map(int,input().split())\n dct[a]+=[[b,c]]\n dct[b]+=[[a,c]]\nprint(dct)\n\nq,k=map(int,input().split())\nlk=[0]*(n)\n\ndef dfs(v,p,d):\n lk[v-1]=d\n print(k,v,p,d,lk)\n for l in dct[v]:\n if l[0]==p:\n continue\n else:\n dfs(l[0],v,d+l[1])\n return\n\ndfs(k,-1,0)\n\nprint(lk)\n\nfor i in range(q):\n x,y=map(int,input().split())\n print(lk[x-1]+lk[y-1])\n \n \n \n \n \n ', 'from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**9)\n\nn=int(input())\ndct=defaultdict(list)\n\nfor i in range(n-1):\n a,b,c=map(int,input().split())\n dct[a]+=[[b,c]]\n dct[b]+=[[a,c]]\n\n\nq,k=map(int,input().split())\nlk=[0]*(n)\n\ndef dfs(v,p,d):\n lk[v-1]=d\n\n for l in dct[v]:\n if l[0]==p or lk[l[0]-1]!=0:\n continue\n else:\n dfs(l[0],v,d+l[1])\n return\n\ndfs(k,-1,0)\n\n\n\nfor i in range(q):\n x,y=map(int,input().split())\n print(lk[x-1]+lk[y-1])\n']
['Runtime Error', 'Accepted']
['s958896386', 's006010686']
[138884.0, 143648.0]
[2107.0, 1652.0]
[477, 479]
p03634
u496687522
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["import heapq\nN = int(input())\nedges = []\nfor i in range(N-1):\n a, b, c = map(int, input().split())\n edges.append([a-1, b-1, c])\n edges.append([b-1, a-1, c])\nQ, K = map(int, input().split())\nK -= 1\n\n\nans_list = []\ndef dijkstra(edges, num_v, start):\n dist = [float('inf')] * num_v\n dist[start] = 0\n q = []\n heapq.heappush(q, [0, start])\n\n while len(q) > 0:\n _, u = heapq.heappop(q)\n for edge in edges:\n if dist[edge[0]] > dist[u] + edge[1]:\n dist[edge[0]] = dist[u] + edge[1]\n heapq.heappush(q, [dist[u] + edge[1], edge[0]])\n return dist\nfor i in range(Q):\n x, y = map(lambda n: int(n) - 1, input().split())\n x_K = dijkstra(edges, N, x)[K]\n K_y = dijkstra(edges, N, K)[y]\n ans_list.append(x_K + K_y)\n\nfor i in ans_list:\n print(i)", "import heapq\nN = int(input())\nedges = [[] for _ in range(N)]\nfor i in range(N-1):\n a, b, c = map(int, input().split())\n edges[a-1].append([b-1, c])\n edges[b-1].append([a-1, c])\nQ, K = map(int, input().split())\nK -= 1\n\n\nans_list = []\ndef dijkstra(edges, num_v, start):\n dist = [float('inf')] * num_v\n dist[start] = 0\n q = []\n heapq.heappush(q, [0, start])\n\n while len(q) > 0:\n _, u = heapq.heappop(q)\n for edge in edges[u]:\n if dist[edge[0]] > dist[u] + edge[1]:\n dist[edge[0]] = dist[u] + edge[1]\n heapq.heappush(q, [dist[u] + edge[1], edge[0]])\n return dist\nbase = dijkstra(edges, N, K)\nfor i in range(Q):\n x, y = map(lambda n: int(n) - 1, input().split())\n x_K = base[x]\n K_y = base[y]\n ans_list.append(x_K + K_y)\n\nfor i in ans_list:\n print(i)"]
['Wrong Answer', 'Accepted']
['s423485423', 's181521105']
[63816.0, 58396.0]
[2107.0, 1294.0]
[824, 843]
p03634
u498620941
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N = int(input())\n\nclass Edge:\n def __init__(self,to,cost):\n self.to = to\n self.cost = cost\n\ngraph = [[] for i in range(N)]\nfor i in range(N-1):\n a,b,c = map(int,input().split())\n graph[a-1].append(Edge(b-1,c))\n graph[b-1].append(Edge(a-1,c))\ndp = [0 for i in range(N)]\n\ndef dfs(s,pare):\n for i in graph[s]:\n if i.to != pare :\n dp[i.to] = dp[s] + i.cost\n dfs(i.to,s)\n\n\nQ,K = map(int,input().split())\ndfs(K-1,-1)\nprint(dp)\nfor i in range(Q):\n x,y = map(int,input().split())\n print("{}".format(dp[x-1]+dp[y-1]))', 'import sys\nsys.setrecursionlimit(10**9)\nN = int(input())\n\nclass Edge:\n def __init__(self,to,cost):\n self.to = to\n self.cost = cost\n\ngraph = [[] for i in range(N)]\nfor i in range(N-1):\n a,b,c = map(int,input().split())\n graph[a-1].append(Edge(b-1,c))\n graph[b-1].append(Edge(a-1,c))\ndp = [0 for i in range(N)]\n\ndef dfs(s,pare):\n for i in graph[s]:\n if i.to != pare :\n dp[i.to] = dp[s] + i.cost\n dfs(i.to,s)\n else:\n continue \n\n\nQ,K = map(int,input().split())\ndfs(K-1,-1)\nfor i in range(Q):\n x,y = map(int,input().split())\n print("{}".format(dp[x-1]+dp[y-1]))\n']
['Runtime Error', 'Accepted']
['s851340336', 's259890974']
[67008.0, 152208.0]
[1868.0, 1856.0]
[572, 655]
p03634
u551909378
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N = int(input())\nT = [{} for i in range(N+1)]\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n T[a][b] = c\n T[b][a] = c\n\nQ, K = map(int, input().split())\nshortest_path = [0 for _ in range(N+1)]\nqueue = [[v, T[K][v], K] for v in T[K].keys()]\n\nfor _ in range(N-1):\n v = queue.pop(0)\n shortest_path[v[0]] = v[1]\n queue += [[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]]', 'N = int(input())\nT = [{} for i in range(N+1)]\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n T[a][b] = c\n T[b][a] = c\n\nQ, K = map(int, input().split())\nshortest_path = [0 for _ in range(N+1)]\nqueue = [[v, T[K][v], K] for v in T[K].keys()]\nfor _ in range(N-1):\n v, c, p = iter(queue.pop(0))\n shortest_path[v] = c\n queue += [[u, T[v][u] + c, v] for u in T[v].keys() if u != p]', 'from collections import deque\n\nN = int(input())\nT = [{} for i in range(N+1)]\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n T[a][b] = c\n T[b][a] = c\n\nQ, K = map(int, input().split())\nshortest_path = [0 for _ in range(N+1)]\nqueue = deque([[v, T[K][v], K] for v in T[K].keys()])\nfor _ in range(N-1):\n v = queue.popleft()\n shortest_path[v[0]] = v[1]\n queue.extend([[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]])\n\nfor _ in range(Q):\n x, y = map(int, input().split())\n print(shortest_path[x] + shortest_path[y])']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s418127108', 's720423658', 's600911120']
[61024.0, 61024.0, 62432.0]
[1982.0, 2000.0, 1432.0]
[414, 404, 563]
p03634
u577170763
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['10\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 1000000000\n8 9 1000000000\n9 10 1000000000\n1 1\n9 10', 'sys.setrecursionlimit(10**5 + 5)\n\nN = int(input())\n\ng = {i: [] for i in range(1, N+1)}\n\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n g[a].append((b, c))\n g[b].append((a, c))\n\nQ, K = map(int, input().split())\nxy = []\nfor _ in range(Q):\n xy.append(tuple(map(int, input().split())))\n\nd = [-1 for _ in range(N+1)]\n\n\ndef dfs(s: int):\n for v, c in g[s]:\n if d[v] == -1:\n d[v] = d[s] + c\n dfs(v)\n\n\nd[K] = 0\ndfs(K)\n\nfor x, y in xy:\n print(d[x]+d[y])\n', 'sys.setrecursionlimit(10000)\n\nN = int(input())\n\nedges = {n: [] for n in range(N+1)}\n\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n\n edges[a].append((b, c))\n edges[b].append((a, c))\n\nQ, K = map(int, input().split())\nxy = []\nfor _ in range(Q):\n xy.append(tuple(map(int, input().split())))\n\n\nd = [-1] * (N+1)\nd[K] = 0\n\n\ndef dfs(n: int):\n for m, c in edges[n]:\n if d[m] == -1:\n d[m] = d[n] + c\n dfs(m)\n\n\ndfs(K)\n\nfor x, y in xy:\n print(d[x] + d[y])\n', 'import sys\nsys.setrecursionlimit(10**5 + 5)\n\nN = int(input())\n\ng = {i: [] for i in range(1, N+1)}\n\nfor _ in range(N-1):\n a, b, c = map(int, input().split())\n g[a].append((b, c))\n g[b].append((a, c))\n\nQ, K = map(int, input().split())\nxy = []\nfor _ in range(Q):\n xy.append(tuple(map(int, input().split())))\n\nd = [-1 for _ in range(N+1)]\n\n\ndef dfs(s: int):\n for v, c in g[s]:\n if d[v] == -1:\n d[v] = d[s] + c\n dfs(v)\n\n\nd[K] = 0\ndfs(K)\n\nfor x, y in xy:\n print(d[x]+d[y])']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s326365287', 's332974670', 's529325913', 's808453418']
[2940.0, 3064.0, 3064.0, 153648.0]
[19.0, 18.0, 18.0, 1031.0]
[147, 503, 504, 513]
p03634
u620868411
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['# coding=utf-8\n\nN = int(input())\ntree = [[]for x in range(N)]\ndepth = [0 for x in range(N)]\nfor _ in range(N-1):\n line = input().split(" ")\n a = int(line[0])-1\n b = int(line[1])-1\n c = int(line[2])\n tree[a].append((b, c))\n tree[b].append((a, c))\n\nline = input().split(" ")\nQ = int(line[0])\nK = int(line[1])-1\n\ndef dfs(v, p, d):\n depth[v] = d\n for e in tree[v]:\n if e[0]==p:\n continue\n dfs(e[0], v, d+e[1])\n\ndfs(K, -1, 0)\n\nfor _ in range(Q):\n line = input(" ").split(" ")\n x = int(line[0])-1\n y = int(line[1])-1\n print(str(depth[x]+depth[y]))\n', '# -*- coding: utf-8 -*-\ninf = 10**16\nn = int(input())\nedge = [[] for _ in range(n)]\nfor _ in range(n-1):\n a,b,c = map(int, input().split())\n a -= 1\n b -= 1\n edge[a].append((b,c))\n edge[b].append((a,c))\n\nq,k = map(int, input().split())\nk -= 1\n\nd = [inf for _ in range(n)]\nd[k] = 0\nstack = [k]\nwhile len(stack)>0:\n v = stack.pop()\n for u,c in edge[v]:\n if d[u]==inf:\n d[u] = d[v]+c\n stack.append(u)\n\nres = []\nfor _ in range(q):\n x,y = map(int, input().split())\n x -= 1\n y -= 1\n res.append(d[x]+d[y])\n\nfor c in res:\n print(c)\n']
['Runtime Error', 'Accepted']
['s981846262', 's230006320']
[43792.0, 48196.0]
[1378.0, 1004.0]
[603, 588]
p03634
u634208461
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["import sys\nsys.setrecursionlimit(10 ** 10)\n\n\nclass Solve():\n def __init__(self):\n self.N = int(input())\n self.route = [dict() for _ in range(self.N)]\n for _ in range(self.N - 1):\n a, b, c = map(int, input().split())\n self.route[a - 1][b - 1] = c\n self.route[b - 1][a - 1] = c\n self.Q, self.K = map(int, input().split())\n self.K -= 1\n self.query = []\n for _ in range(self.Q):\n x, y = map(int, input().split())\n self.query.append([x - 1, y - 1])\n self.depth = [0 for _ in range(self.N)]\n\n def DFS(self, v, p, d):\n self.depth[v] = d\n for dest, cost in self.route[v].items():\n if dest == p:\n continue\n self.DFS(dest, v, d + cost)\n\n def execute(self):\n self.DFS(self.K, -1, 0)\n for x, y in self.query:\n print(self.depth[x] + self.depth[y])\n\n\nif __name__ == '__main__':\n Solve().execute()", "import sys\nsys.setrecursionlimit(10 ** 8)\n\n\nclass Solve():\n def __init__(self):\n self.N = int(input())\n self.route = [dict() for _ in range(self.N)]\n for _ in range(self.N - 1):\n a, b, c = map(int, input().split())\n self.route[a - 1][b - 1] = c\n self.route[b - 1][a - 1] = c\n self.Q, self.K = map(int, input().split())\n self.K -= 1\n self.query = []\n for _ in range(self.Q):\n x, y = map(int, input().split())\n self.query.append([x - 1, y - 1])\n self.depth = [0 for _ in range(self.N)]\n\n def DFS(self, v, p, d):\n self.depth[v] = d\n for dest, cost in self.route[v].items():\n if dest == p:\n continue\n self.DFS(dest, v, d + cost)\n\n def execute(self):\n self.DFS(self.K, -1, 0)\n for x, y in self.query:\n print(self.depth[x] + self.depth[y])\n\n\nif __name__ == '__main__':\n Solve().execute()"]
['Runtime Error', 'Accepted']
['s064769811', 's488389193']
[3064.0, 163100.0]
[19.0, 991.0]
[981, 980]
p03634
u642905089
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque \n\nn = int(input())\n\npreroots = []\npreroots_appd = preroots.append\n\nfor i in range(n-1):\n preroots_appd(list(map(int,input().split())))\n \nroots = [[] for x in range(n+1)]\n\nfor i in preroots:\n roots[i[0]].append((i[1],i[2])) \n roots[i[1]].append((i[0],i[2])) \n \nQK = list(map(int,input().split())) \nquery = []\n\nquery_appd = query.append\nfor i in range(QK[0]):\n query_appd(list(map(int,input().split())))\n \n \ndistfrom_K = [-1 for x in range(n+1)]\ndistfrom_K[QK[1]] = 0 \n\nq = deque()\nq.append(QK[1])\n\nwhile(len(q)):\n currentNode = q.popleft()\n for i in roots[currentNode]:\n if distfrom_K[i[0]] != -1:continue\n q.append(i[0])\n distfrom_K[i[0]] = distfrom_K[currentNode] + i[0]\n\nfor i in query:\n print(distfrom_K[i[0]]+distfrom_K[i[1]])', 'from collections import deque\n\nn = int(input())\npreroots = []\nfor i in range(n-1): \n preroots.append(list(map(int,input().split())))\n\nroots = [[] for i in range(n+1)]\n\nfor i in range(n-1):\n roots[preroots[i][0]].append([preroots[i][1],preroots[i][2]])\n roots[preroots[i][1]].append([preroots[i][0],preroots[i][2]])\n\n\n\nQK = list(map(int,input().split()))\ndist = [-1 for i in range(n+1)]\ndist[QK[1]] = 0\nquery = []\nfor i in range(QK[0]):\n query.append(list(map(int,input().split())))\n\nq = deque()\nq.append(QK[1])\n\nwhile(len(q)):\n curr = q.popleft()\n for i in roots[curr]:\n if dist[i[0]] != -1:continue\n dist[i[0]] = dist[curr] + i[1]\n q.append(i[0])\n \nfor i in query:\n print(dist[i[0]] + dist[i[1]])']
['Wrong Answer', 'Accepted']
['s741396666', 's645528498']
[81024.0, 88720.0]
[1112.0, 1389.0]
[852, 750]
p03634
u653807637
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["# encoding:utf-8\n\nimport sys\nsys.setrecursionlimit(100000)\n\ndef main():\n\tn = int(input())\n\tvers = [list(map(int, input().split())) for _ in range(n - 1)]\n\tq, k = list(map(int, input().split()))\n\tqueries = [list(map(int, input().split())) for _ in range(q)]\n\n\tn = 10 ** 5\n\tvers = [[i + 1, i + 2, 10 ** 9] for i in range(n - 1)]\n\tprint(vers)\n\n\tnew_vers = mapping(n, vers)\n\tdist = calcMinDist(n, new_vers, k, queries)\n\tprint(dist)\n\tcalcQueries(dist, queries, k)\n\t\ndef mapping(n, vers):\n\tnew_vers = {i :[] for i in range(n)}\n\tfor ver in vers:\n\t\tnew_vers[ver[0] - 1].append((ver[1], ver[2]))\n\t\tnew_vers[ver[1] - 1].append((ver[0], ver[2]))\n\treturn new_vers\n\ndef calcMinDist(n, new_vers, k, queries):\n\tdist = [- 1 for _ in range(n)]\n\tflag = [False for _ in range(n)]\n\tdist[k - 1] = 0\n\tflag[k - 1] = True\n\tdfs(new_vers, dist, flag, k)\n\treturn dist\n\ndef dfs(new_vers, dist, flag, frm):\n\tflag[frm - 1] = True\n\tvs = new_vers[frm - 1]\n\tfor v in vs:\n\t\tif flag[v[0] - 1] == False:\n\t\t\tdist[v[0] - 1] = dist[frm - 1] + v[1]\n\t\t\tnew_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0])\n\n\treturn [new_vers, dist, flag, frm]\n\ndef calcQuery(dist, query, k):\n\tprint(dist[query[0] - 1] + dist[query[1] - 1])\n\ndef calcQueries(dist, queries, k):\n\tfor query in queries:\n\t\tcalcQuery(dist, query, k)\n\nif __name__ == '__main__':\n\tmain()", "# encoding:utf-8\nimport sys\n \ndef main():\n\tn = int(input())\n\tvers = [list(map(int, input().split())) for _ in range(n - 1)]\n\tq, k = list(map(int, input().split()))\n\tqueries = [list(map(int, input().split())) for _ in range(q)]\n \n\t#n = 10 ** 5\n\t\n \n\tnew_vers = mapping(n, vers)\n\tdist = calcMinDist(n, new_vers, k, queries)\n\tcalcQueries(dist, queries, k)\n\t\ndef mapping(n, vers):\n\tnew_vers = {i :[] for i in range(n)}\n\tfor ver in vers:\n\t\tnew_vers[ver[0] - 1].append((ver[1], ver[2]))\n\t\tnew_vers[ver[1] - 1].append((ver[0], ver[2]))\n\treturn new_vers\n \ndef calcMinDist(n, new_vers, k, queries):\n\tdist = [- 1 for _ in range(n)]\n\tflag = [False for _ in range(n)]\n\tdist[k - 1] = 0\n\tflag[k - 1] = True\n\tdfs(new_vers, dist, flag, k)\n\treturn dist\n \ndef dfs(new_vers, dist, flag, frm):\n\tflag[frm - 1] = True\n\tvs = new_vers[frm - 1]\n\tfor v in vs:\n\t\tif flag[v[0] - 1] == False:\n\t\t\tdist[v[0] - 1] = dist[frm - 1] + v[1]\n\t\t\tnew_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0])\n \n\treturn [new_vers, dist, flag, frm]\n \ndef calcQuery(dist, query, k):\n\tprint(dist[query[0] - 1] + dist[query[1] - 1])\n \ndef calcQueries(dist, queries, k):\n\tfor query in queries:\n\t\tcalcQuery(dist, query, k)\n \nif __name__ == '__main__':\n\tsys.setrecursionlimit(1000000)\n\tmain()"]
['Runtime Error', 'Accepted']
['s231295136', 's229285926']
[180748.0, 181772.0]
[1274.0, 1214.0]
[1308, 1294]
p03634
u665038048
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import numpy as np\nfrom scipy.sparse.csgraph import floyd_warshall\n\n\n\nn = int(input())\nmatrix = np.zeros((n, n))\nfor i in range(n-1):\n a, b, c = map(int, input().split())\n matrix[a-1][b-1] = c\n matrix[b-1][a-1] = c\nmin_span_matrix = floyd_warshall(matrix, directed=False,\n return_predecessors=False)\nq, k = map(int, input().split())\nfor i in range(q):\n x, y = map(int, input().split())\n print(min_span_matrix[x-1][k-1] + min_span_matrix[k-1][y-1])\n', 'from collections import deque\nimport sys\nsys.setrecursionlimit(10 ** 9)\n\n\nn = int(input())\nquery = [[] for i in range(n)]\nfor i in range(n-1):\n a, b, c = map(int, input().split())\n query[a-1].append((b-1, c))\n query[b-1].append((a-1, c))\nq, k = map(int, input().split())\nstack = deque([(k-1, 0, -1)])\ndist = [0] * n\nwhile stack:\n now, cnt, per = stack.pop()\n lis = query[now]\n dist[now] = cnt\n for nx, c in lis:\n if nx == per:\n continue\n if c != 0:\n stack.append((nx, cnt+c, now))\nfor i in range(q):\n x, y = map(int, input().split())\n print(dist[x-1] + dist[y-1])\n']
['Runtime Error', 'Accepted']
['s396572704', 's491947330']
[1466888.0, 50528.0]
[2212.0, 868.0]
[495, 627]
p03634
u667084803
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['def BFS(K,edges,N):\n roots=[ [] for i in range(N)]\n for a,b,c in edges:\n roots[a-1]+=[(b-1,c)]\n roots[b-1]+=[(a-1,c)]\n dist=[-1]*N\n stack=[]\n stack.append(K)\n dist[K]=0\n while stack:\n label=stack.pop(-1)\n for i,c in edges[label]:\n if dist[i]==-1:\n dist[i]=dist[label]+c\n stack+=[i]\n return dist\n \nN=int(input())\nedges=[]\nfor i in range(N-1):\n edges+=[list(map(int,input().split()))]\nQ,K=map(int,input().split())\nxy=[list(map(int,input().split())) for i in range(Q)]\ndistance=BFS(K-1,edges,N)\nfor i in range(Q):\n print(distance[xy[i][0]-1]+distance[xy[i][1]-1])', 'def BFS(K,edges,N):\n roots=[ [] for i in range(N)]\n for a,b,c in edges:\n roots[a-1]+=[(b-1,c)]\n roots[b-1]+=[(a-1,c)]\n dist=[-1]*N\n stack=[]\n stack.append(K)\n dist[K]=0\n while stack:\n label=stack.pop(-1)\n for i,c in roots[label]:\n if dist[i]==-1:\n dist[i]=dist[label]+c\n stack+=[i]\n return dist\n \nN=int(input())\nedges=[]\nfor i in range(N-1):\n edges+=[list(map(int,input().split()))]\nQ,K=map(int,input().split())\nxy=[list(map(int,input().split())) for i in range(Q)]\ndistance=BFS(K-1,edges,N)\nfor i in range(Q):\n print(distance[xy[i][0]-1]+distance[xy[i][1]-1])']
['Runtime Error', 'Accepted']
['s476885866', 's422334567']
[82044.0, 86008.0]
[917.0, 1163.0]
[601, 601]
p03634
u682985065
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["import heapq\nn = int(f.readline())\ncost = [[float('inf') for _ in range(n+1)] for _ in range(n+1)]\nfor _ in range(n-1):\n From, To, d = map(int, f.readline().split())\n cost[From][To] = d\n cost[To][From] = d\n\nq, k = map(int, f.readline().split())\ndist = [[float('inf') for _ in range(n+1)] for _ in range(n+1)]\nused = [False]*(n+1)\n\nfor i in range(n+1):\n dist[i][i] = 0\n \ndef dijkstra(s, dist):\n next_v = [[0, s]]\n \n while len(next_v):\n v = next_v[0][1]\n for i in range(n+1):\n if dist[s][i] > dist[s][v] + cost[v][i]:\n dist[s][i] = dist[s][v] + cost[v][i]\n heapq.heappush(next_v, [dist[s][i], i])\n heapq.heappop(next_v)\n \n return dist\ndist = dijkstra(k, dist)\n\nfor _ in range(q):\n x, y = map(int, f.readline().split())\n if used[x] == False:\n dist = dijkstra(x, dist)\n used[x] = True\n print(dist[x][k]+dist[k][y])", "def dijkstra(n, edges, s):\n min_dist = [float('inf')] * n\n min_dist[s] = 0\n next_v = []\n heapq.heappush(next_v, (0, s))\n path = [-1] * n\n \n while True:\n if len(next_v) == 0: break\n d, v = heapq.heappop(next_v)\n \n for u, d in edges[v]:\n if min_dist[u] > min_dist[v] + d:\n min_dist[u] = min_dist[v] + d\n heapq.heappush(next_v, (min_dist[u], u))\n path[u] = v\n \n return min_dist, path\n\nn = int(input())\nedges = [[] for _ in range(n)]\n\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n edges[a-1].append((b-1, c))\n edges[b-1].append((a-1, c))\n\ndist = [None] * n\nfor i in range(n):\n dist[i], _ = dijkstra(n, edges, i)\n\nq, k = map(int, input().split())\nfor _ in range(q):\n x, y = map(int, input().split())\n print(dist[x-1][k-1] + dist[k-1][y-1])", "import heapq\nn = int(input())\ncost = [[float('inf') for _ in range(n+1)] for _ in range(n+1)]\nfor _ in range(n-1):\n From, To, d = map(int, input().split())\n cost[From][To] = d\n cost[To][From] = d\n\nq, k = map(int, input().split())\ndist = [[float('inf') for _ in range(n+1)] for _ in range(n+1)]\nused = [False]*(n+1)\n\nfor i in range(n+1):\n dist[i][i] = 0\n \ndef dijkstra(s, dist):\n next_v = [[0, s]]\n \n while len(next_v):\n v = next_v[0][1]\n for i in range(n+1):\n if dist[s][i] > dist[s][v] + cost[v][i]:\n dist[s][i] = dist[s][v] + cost[v][i]\n heapq.heappush(next_v, [dist[s][i], i])\n heapq.heappop(next_v)\n \n return dist\ndist = dijkstra(k, dist)\n\nfor _ in range(q):\n x, y = map(int, f.readline().split())\n if used[x] == False:\n dist = dijkstra(x, dist)\n used[x] = True\n print(dist[x][k]+dist[k][y])", "import heapq\ndef dijkstra(n, edges, s):\n min_dist = [float('inf')] * n\n min_dist[s] = 0\n next_v = []\n heapq.heappush(next_v, (0, s))\n path = [-1] * n\n \n while True:\n if len(next_v) == 0: break\n d, v = heapq.heappop(next_v)\n \n for u, d in edges[v]:\n if min_dist[u] > min_dist[v] + d:\n min_dist[u] = min_dist[v] + d\n heapq.heappush(next_v, (min_dist[u], u))\n path[u] = v\n \n return min_dist, path\n\nn = int(input())\nedges = [[] for _ in range(n)]\n\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n edges[a-1].append((b-1, c))\n edges[b-1].append((a-1, c))\n\n\nq, k = map(int, input().split())\ndist, _ = dijkstra(n, edges, k-1)\n\nfor _ in range(q):\n x, y = map(int, input().split())\n print(dist[x-1] + dist[y-1])"]
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s611877562', 's626221995', 's710137775', 's167186461']
[3188.0, 38704.0, 357452.0, 47884.0]
[18.0, 491.0, 2127.0, 1506.0]
[933, 888, 918, 850]
p03634
u690536347
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import defaultdict\nimport sys\n\nsys.setrecursionlimit(1000000)\nd=defaultdict(list)\n\nN=int(input())\nfor _ in range(N-1):\n a,b,c=map(int,input().split())\n d[a].append((b,c))\n d[b].append((a,c))\n\nQ,K=map(int,input().split())\n\n\ndists=[None]*(N+1)\nisused=[False]*(N+1)\ndists[K]=0\nisused[K]=True\n\ndef dfs(n):\n for i,j in d[n]:\n if isused[i]:continue\n isused[i]=True\n print(i,j)\n dists[i]=dists[n]+j\n dfs(i)\n\ndfs(K)\nfor _ in range(Q):\n x,y=map(int,input().split())\n print(dists[x]+dists[y])', 'from collections import defaultdict\nimport sys\n\nsys.setrecursionlimit(1000000)\nd=defaultdict(list)\n\nN=int(input())\nfor _ in range(N-1):\n a,b,c=map(int,input().split())\n d[a].append((b,c))\n d[b].append((a,c))\n\nQ,K=map(int,input().split())\n\n\ndists=[None]*(N+1)\nisused=[False]*(N+1)\ndists[K]=0\nisused[K]=True\n\ndef dfs(n):\n for i,j in d[n]:\n if isused[i]:continue\n isused[i]=True\n dists[i]=dists[n]+j\n dfs(i)\n\ndfs(K)\nfor _ in range(Q):\n x,y=map(int,input().split())\n print(dists[x]+dists[y])']
['Wrong Answer', 'Accepted']
['s638960303', 's764328980']
[139988.0, 138144.0]
[1721.0, 1562.0]
[591, 572]
p03634
u784022244
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['\nfrom collections import deque\nN=int(input())\nT=[[] for _ in range(N)]\nfor i in range(N-1):\n a,b,c=map(int, input().split())\n T[a-1].append((b-1,c))\n T[b-1].append((a-1,c))\n\nQ,K=map(int, input().split())\nque=[(K-1,0)\ndone=[-1]*N\nwhile que:\n t=que.pop(0)\n now,nowd=t\n done[now]=nowd\n for nex in T[now]:\n nexnode,nexd=nex\n if done[nexnode]!=-1:\n continue\n else:\n que.append((nexnode, nowd+nexd))\n\n#print(done)\nfor i in range(Q):\n x,y=map(int, input().split())\n print(done[x-1]+done[y-1])', '\nfrom collections import deque\nN=int(input())\nT=[[] for _ in range(N)]\nfor i in range(N-1):\n a,b,c=map(int, input().split())\n T[a-1].append((b-1,c))\n T[b-1].append((a-1,c))\n\nQ,K=map(int, input().split())\nque=deque([(K-1,0)])\ndone=[-1]*N\nwhile que:\n t=que.popleft()\n now,nowd=t\n done[now]=nowd\n for nex in T[now]:\n nexnode,nexd=nex\n if done[nexnode]!=-1:\n continue\n else:\n que.append((nexnode, nowd+nexd))\n\n#print(done)\nfor i in range(Q):\n x,y=map(int, input().split())\n print(done[x-1]+done[y-1])']
['Runtime Error', 'Accepted']
['s030427272', 's014572252']
[2940.0, 47120.0]
[17.0, 1446.0]
[555, 566]
p03634
u786020649
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["\nfrom collections import defaultdict,deque\nimport sys\nfinput=lambda: sys.stdin.readline().strip()\n\ndef main():\n n=int(finput())\n edges=[tuple(map(int,finput().split())) for _ in range(n-1)]\n q,k=map(int,finput().split())\n xy=[tuple(map(int,finput().split())) for _ in range(q)]\n ed=defaultdict(deque)\n wt=defaultdict(int)\n for e in edges:\n ed[e[0]].append(e[1])\n ed[e[1]].append(e[0])\n wt[(e[0],e[1])]=e[2]\n wt[(e[1],e[0])]=e[2]\n stack=deque([k])\n cv=stack[0]\n dist=defaultdict(int)\n while stack:\n while ed[cv]:\n if cv!=k:\n if ed[cv][-1]==stack[-1]:\n ed[cv].pop()\n if not ed[cv]:\n break\n stack.append(cv)\n cv=ed[cv].pop()\n dist[cv]=dist[stack[-1]]+wt[(stack[-1],cv)]\n cv=stack.pop()\n print(dist)\n for que in xy:\n print(dist[que[0]]+dist[que[1]])\n\nif __name__=='__main__':\n main()\n", "from collections import defaultdict,deque\nimport sys\nfinput=lambda: sys.stdin.readline().strip()\n\ndef main():\n n=int(finput())\n edges=[tuple(map(int,finput().split())) for _ in range(n-1)]\n q,k=map(int,finput().split())\n xy=[tuple(map(int,finput().split())) for _ in range(q)]\n ed=defaultdict(deque)\n wt=defaultdict(int)\n for e in edges:\n ed[e[0]].append(e[1])\n ed[e[1]].append(e[0])\n wt[(e[0],e[1])]=e[2]\n wt[(e[1],e[0])]=e[2]\n stack=deque([k])\n cv=stack[0]\n dist=defaultdict(int)\n while stack:\n while ed[cv]:\n if cv!=k:\n if ed[cv][-1]==stack[-1]:\n ed[cv].pop()\n if not ed[cv]:\n break\n stack.append(cv)\n cv=ed[cv].pop()\n dist[cv]=dist[stack[-1]]+wt[(stack[-1],cv)]\n cv=stack.pop()\n for que in xy:\n print(dist[que[0]]+dist[que[1]])\n\nif __name__=='__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s980885183', 's327647374']
[147012.0, 144868.0]
[686.0, 661.0]
[873, 858]
p03634
u790710233
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
["import sys\nfrom collections import deque\ninput = sys.stdin.readline\nn = int(input())\nedges = [[]for _ in range(n)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a -= 1\n b -= 1\n edges[a].append((c, b))\n edges[b].append((c, a))\nINF = float('inf')\n\n\ndef bfs(init_v):\n dist = [INF]*n\n dist[init_v] = 0\n tasks = deque([(0, init_v)])\n while tasks:\n print(tasks)\n d, v = tasks.popleft()\n for d2, v2 in edges[v]:\n if dist[v2] <= dist[v]+d2:\n continue\n dist[v2] = dist[v]+d2\n tasks.append((dist[v2], v2))\n return dist\n\n\nq, k = map(int, input().split())\ndist = bfs(k-1)\nfor _ in range(q):\n x, y = map(lambda x: int(x)-1, input().split())\n print(dist[x]+dist[y])", "import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**7)\nn = int(input())\nedges = [[]for _ in range(n)]\nfor _ in range(n-1):\n a, b, c = map(int, input().split())\n a -= 1\n b -= 1\n edges[a].append((c, b))\n edges[b].append((c, a))\nINF = float('inf')\n\n\ndef dfs(v, parent, distance):\n dist[v] = distance\n for d, v2 in edges[v]:\n if parent == v2:\n continue\n dfs(v2, v, distance+d)\n\n\nq, k = map(int, input().split())\ndist = [INF]*n\ndfs(k-1, -1, 0)\nfor _ in range(q):\n x, y = map(lambda x: int(x)-1, input().split())\n print(dist[x]+dist[y])"]
['Wrong Answer', 'Accepted']
['s704627664', 's682557398']
[138520.0, 131772.0]
[2107.0, 703.0]
[769, 594]
p03634
u814986259
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['N=int(input())\nabc=[tuple(map(int,input().split())) for i in range(N-1)]\ng=[set() for i in range(N)]\nfor a,b,c in abc:\n g[a-1].add((b-1,c))\n g[b-1].add((a-1,c))\nmemo=[0]*N\nmemo[K-1]=0\nQ,K=map(int,input().split())\nimport collections\nq=collections.deque([(K-1,0)])\nwhile(q):\n x,w = q.popleft()\n for a,b in g[x]:\n if memo[a]==-1:\n memo[a]=w+b\n q.append((a,w+b))\n \nfor i in range(Q):\n x,y=map(int,input().split())\n print(memo[a-1]+memo[b-1])', 'N=int(input())\nabc=[tuple(map(int,input().split())) for i in range(N-1)]\ng=[set() for i in range(N)]\nfor a,b,c in abc:\n g[a-1].add((b-1,c))\n g[b-1].add((a-1,c))\nmemo=[-1]*N\n\nQ,K=map(int,input().split())\nimport collections\nq=collections.deque([(K-1,0)])\nmemo[K-1]=0\nwhile(q):\n \n x,w = q.popleft()\n for a,b in g[x]:\n if memo[a]==-1:\n memo[a]=w+b\n q.append((a,w+b))\n \nfor i in range(Q):\n x,y=map(int,input().split())\n print(memo[x-1]+memo[y-1])\n']
['Runtime Error', 'Accepted']
['s583622723', 's818599889']
[63468.0, 76884.0]
[550.0, 1495.0]
[457, 463]
p03634
u858994158
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['n=int(input())-1\n\nedges = {}\nlens = {}\nfor _ in range(n):\n [a, b, c] = map(int, input().split())\n if a > b:\n a,b=b,a\n edges.setdefault(a, []).append(b)\n edges.setdefault(b, []).append(a)\n lens[(a,b)] = c\n\nq, k = map(int, input().split())\n\nused = set()\ndists = {}\ndef build(x, d=0):\n dists[x] = d\n for c in edges[x]:\n if c not in used:\n used.add(c)\n build(c, d + lens[(min(x,c), max(x,c))])\n\nbuild(k)\n\n\nfor _ in range(q):\n [x, y] = map(int, input().split())\n print(dists[x] + dists[y])', 'n=int(input())-1\n\nedges = {}\nlens = {}\nfor _ in range(n):\n [a, b, c] = map(int, input().split())\n if a > b:\n a,b=b,a\n edges.setdefault(a, []).append(b)\n edges.setdefault(b, []).append(a)\n lens[(a,b)] = c\n\nq, k = map(int, input().split())\n\ndists = {}\ndef build(x, d=0):\n ss = [(x, 0)]\n while ss:\n x, d = ss.pop()\n if x not in dists:\n dists[x] = d\n for c in edges.get(x, []):\n ss.append((c, d + lens[(min(x,c), max(x,c))]))\n\nbuild(k)\n\nfor _ in range(q):\n [x, y] = map(int, input().split())\n print(dists[x] + dists[y])']
['Runtime Error', 'Accepted']
['s187980498', 's965310369']
[65724.0, 71212.0]
[1607.0, 1645.0]
[547, 600]
p03634
u860002137
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from heapq import heappush, heappop\nfrom collections import defaultdict\n\nn = int(input())\ngraph = defaultdict(list)\n\n\nfor _ in range(n - 1):\n a, b, c = map(int, input().split())\n graph[a].append((b, c))\n graph[b].append((a, c))\n\nq, k = map(int, input().split())\n\n\n\nINF = 1 << 60\ndist = [INF] * (n + 1)\ndist[k] = 0\n\n\nq = [(0, k)]\n\n\nwhile q:\n cost, curr = heappop(q)\n if cost > dist[curr]:\n continue\n for after, nc in graph[curr]:\n if cost + nc < dist[after]:\n dist[after] = cost + nc\n heappush(q, (cost + nc, after))\n\nprint("\\n".join(map(str, (dist[x] + dist[y]\n for x, y in (map(int, input().split()) for _ in range(q))))))', 'from heapq import heappush, heappop\nfrom collections import defaultdict\n\nn = int(input())\ngraph = defaultdict(list)\n\n\nfor _ in range(n - 1):\n a, b, c = map(int, input().split())\n graph[a].append((b, c))\n graph[b].append((a, c))\n\nq, k = map(int, input().split())\n\n\n\nINF = 1 << 60\ndist = [INF] * (n + 1)\ndist[k] = 0\n\n\nque = [(0, k)]\n\n\nwhile que:\n cost, curr = heappop(que)\n if cost > dist[curr]:\n continue\n for after, nc in graph[curr]:\n if cost + nc < dist[after]:\n dist[after] = cost + nc\n heappush(que, (cost + nc, after))\n \nprint(*([dist[x] + dist[y] for x, y in (map(int, input().split()) for _ in range(q))]), sep="\\n")']
['Runtime Error', 'Accepted']
['s920581700', 's699584540']
[57988.0, 60704.0]
[581.0, 780.0]
[799, 785]
p03634
u879870653
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(10**9)\n\ninput = sys.stdin.readline\n\nN = int(input())\nT = [[] for _ in range(N+1)]\n\nfor _ in range(N-1) :\n a,b,c = map(int,input().split())\n T[a].append([b,c])\n T[b].append([a,c])\n\nQ,K = map(int,input().split())\n\ndist = [None]*(N+1)\n\ndef dfs(now,d) :\n dist[now] = d\n for to,c in T[now] :\n if dist[to] is not None :\n continue\n dfs(to,d+c)\n\ndfs(K,0)\n\nans = [0]*Q\n\nfor _ in range(Q) :\n u,v = map(int,input().split())\n ans[i] = dist[u]+dist[v]\n\nprint(*ans,sep="\\n")\n', 'import sys\nsys.setrecursionlimit(10**9)\n\ninput = sys.stdin.readline\n\nN = int(input())\n\nT = [[] for _ in range(N+1)]\n\nfor _ in range(N-1) :\n a,b,c = map(int,input().split())\n T[a].append([b,c])\n T[b].append([a,c])\n\nQ,K = map(int,input().split())\n\ndist = [None]*(N+1)\n\ndef dfs(now,d) :\n dist[now] = d\n for to,c in T[now] :\n if dist[to] is not None :\n continue\n dfs(to,d+c)\n\ndfs(K,0)\n\nans = [0]*Q\n\nfor i in range(Q) :\n u,v = map(int,input().split())\n ans[i] = dist[u]+dist[v]\n\nprint(*ans,sep="\\n")\n\n']
['Runtime Error', 'Accepted']
['s810954990', 's332595378']
[137164.0, 140492.0]
[566.0, 752.0]
[540, 542]
p03634
u893209854
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['tree = dict()\ncost = dict()\n\nN = int(input())\nfor i in range(N - 1):\n a, b, c = map(int, input().split())\n if a in tree:\n tree[a].append(b)\n else:\n tree[a] = []\n tree[a].append(b)\n if b in tree:\n tree[b].append(a)\n else:\n tree[b] = []\n tree[b].append(a)\n cost[(a, b)] = c\n cost[(b, a)] = c\nstarts = []\nends = []\nQ, K = map(int, input().split())\nfor i in range(Q):\n x, y = map(int, input().split())\n starts.append(x)\n ends.append(y)\n\ndepth = [False for i in range(N)]\n\ndef dps(position, total_cost):\n if depth[position - 1] > total_cost:\n depth[position - 1] = total_cost\n for next_position in tree[position]:\n if depth[next_position - 1] == False:\n dps(next_position, depth[position - 1] + cost[(position, next_position)])\n\ndepth[K-1] = 0\ndps(K, 0)\n\nfor start, end in zip(starts, ends):\n print(depth[start - 1] + depth[end - 1])', 'import sys\nsys.setrecursionlimit(10000000000000000)\n\ntree = dict()\ncost = dict()\n\nN = int(input())\nfor i in range(N - 1):\n a, b, c = map(int, input().split())\n if a in tree:\n tree[a].append(b)\n else:\n tree[a] = []\n tree[a].append(b)\n if b in tree:\n tree[b].append(a)\n else:\n tree[b] = []\n tree[b].append(a)\n cost[(a, b)] = c\n cost[(b, a)] = c\nstarts = []\nends = []\nQ, K = map(int, input().split())\nfor i in range(Q):\n x, y = map(int, input().split())\n starts.append(x)\n ends.append(y)\n\ndepth = [10000000000000000 for i in range(N)]\n\ndef dps(position, total_cost):\n if depth[position - 1] > total_cost:\n depth[position - 1] = total_cost\n for next_position in tree[position]:\n if depth[next_position - 1] == 10000000000000000:\n dps(next_position, depth[position - 1] + cost[(position, next_position)])\n\ndepth[K-1] = 0\ndps(K, 0)\n\nfor start, end in zip(starts, ends):\n print(depth[start - 1] + depth[end - 1])', 'import sys\nsys.setrecursionlimit(1000000)\n\ntree = dict()\ncost = dict()\n\nN = int(input())\nfor i in range(N - 1):\n a, b, c = map(int, input().split())\n if a in tree:\n tree[a].append(b)\n else:\n tree[a] = []\n tree[a].append(b)\n if b in tree:\n tree[b].append(a)\n else:\n tree[b] = []\n tree[b].append(a)\n cost[(a, b)] = c\n cost[(b, a)] = c\nstarts = []\nends = []\nQ, K = map(int, input().split())\nfor i in range(Q):\n x, y = map(int, input().split())\n starts.append(x)\n ends.append(y)\n\ndepth = [1000000000000000 for i in range(N)]\n\ndef dps(position, total_cost):\n if depth[position - 1] > total_cost:\n depth[position - 1] = total_cost\n for next_position in tree[position]:\n if depth[next_position - 1] == 1000000000000000:\n dps(next_position, depth[position - 1] + cost[(position, next_position)])\n\ndepth[K-1] = 0\ndps(K, 0)\n\nfor start, end in zip(starts, ends):\n print(depth[start - 1] + depth[end - 1])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s018749553', 's633276901', 's626550986']
[65188.0, 3192.0, 157784.0]
[1102.0, 18.0, 1343.0]
[934, 1011, 999]
p03634
u921773161
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['#%%\nn = int(input())\na, b, c = [0] * n, [0] * n, [0] * n\nfor i in range(n-1):\n a[i], b[i], c[i] = map(int, input().split())\n\nq, k = map(int, input().split())\nx, y = [0] * q, [0] * q\nfor i in range(q):\n x[i], y[i] = map(int, input().split())\n\nl = [[] for _ in range(n+1)]\nfor i in range(n-1):\n l[a[i]].append((b[i],c[i]))\n l[b[i]].append((a[i],c[i]))\n\nd = [0] * (n+1)\ncheck = False * (n+1)\ncheck[k] = 1\nque = [k]\n\nwhile len(que) > 0:\n tmp = que.pop(0)\n for i in l[tmp]:\n if check[i[0]] :\n que.append(i[0])\n check[i[0]] = True\n d[i[0]] = d[tmp] + i[1]\n else:\n pass\n\nfor i in range(q):\n ans = d[x[i]] + d[y[i]]\n print(ans)', '#%%\nn = int(input())\na, b, c = [0] * n, [0] * n, [0] * n\nfor i in range(n-1):\n a[i], b[i], c[i] = map(int, input().split())\n\nq, k = map(int, input().split())\nx, y = [0] * q, [0] * q\nfor i in range(q):\n x[i], y[i] = map(int, input().split())\n\nl = [[] for _ in range(n+1)]\nfor i in range(n-1):\n l[a[i]].append((b[i],c[i]))\n l[b[i]].append((a[i],c[i]))\n\nd = [0] * (n+1)\ncheck = False * (n+1)\ncheck[k] = True\nque = [k]\n\nwhile len(que) > 0:\n tmp = que.pop(0)\n for i in l[tmp]:\n if check[i[0]] :\n que.append(i[0])\n check[i[0]] = True\n d[i[0]] = d[tmp] + i[1]\n else:\n pass\n\nfor i in range(q):\n ans = d[x[i]] + d[y[i]]\n print(ans)', '#%%\nn = int(input())\na, b, c = [0] * n, [0] * n, [0] * n\nfor i in range(n-1):\n a[i], b[i], c[i] = map(int, input().split())\n\nq, k = map(int, input().split())\n\nl = [[] for _ in range(n+1)]\nfor i in range(n-1):\n l[a[i]].append([b[i],c[i]])\n l[b[i]].append([a[i],c[i]])\n\nd = [0] * (n+1)\ncheck = [0] * (n+1)\ncheck[k] = 1\nque = [k]\ncount = 1\n\nwhile len(que) > 0:\n tmp = que.pop(0)\n for i in l[tmp]:\n if check[i[0]] == 0:\n que.append(i[0])\n check[i[0]] = 1\n d[i[0]] = d[tmp] + i[1]\n count += 1\n else:\n pass\n if count >= n:\n break\n\nx, y = [0] * q, [0] * q\nfor i in range(q):\n x[i], y[i] = map(int, input().split())\n print(d[x[i]] + d[y[i]])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s177319149', 's436377280', 's747633057']
[48052.0, 48052.0, 60484.0]
[784.0, 768.0, 1711.0]
[701, 704, 733]
p03634
u932465688
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['from collections import deque\n\nN = int(input())\ngraph = [[] for _ in range(N+1)] \nlong = [0] * (N+1) \n\nfor i in range(N-1):\n x, y, z = map(int, input().split())\n graph[x].append([y, z])\n graph[y].append([x, z])\n \nQ, K = map(int, input().split())\nx = list()\ny = list()\n \nfor i in range(1,N+1): を求める\n q = deque([K])\n while q:\n t = q.popleft()\n for i in range(len(graph[t])):\n next_t = graph[t][i][0]\n if(long[next_t] > 0):\n continue\n \n else:\n q.append(next_t)\n long[next_t] = long[t] + graph[t][i][1]\n \n\nfor i in range(Q):\n x_i, y_i = map(int, input().split())\n ans = long[x_i] + long[y_i]\n print(ans)\n', 'import heapq\ndef dijkstra_heap(s):\n d = [float("inf")]*n\n used = [True] * n\n d[s] = 0\n used[s] = False\n edgelist = []\n for e in edge[s]:\n heapq.heappush(edgelist,e)\n while len(edgelist):\n minedge = heapq.heappop(edgelist)\n if not used[minedge[1]]:\n continue\n v = minedge[1]\n d[v] = minedge[0]\n used[v] = False\n for e in edge[v]:\n if used[e[1]]:\n heapq.heappush(edgelist,[e[0]+d[v],e[1]])\n return d\nn = int(input())\nedge = [[] for i in range(n)]\nfor i in range(n-1):\n x,y,z = map(int,input().split())\n edge[x-1].append([z,y-1])\n edge[y-1].append([z,x-1])\nQ,K = map(int,input().split())\nL = dijkstra_heap(K-1)\nquery = []\nfor i in range(Q):\n query.append(list(map(int,input().split())))\nfor i in range(Q):\n print(L[query[i][0]-1]+L[query[i][1]-1])']
['Time Limit Exceeded', 'Accepted']
['s259356283', 's045458038']
[49908.0, 74124.0]
[2106.0, 1654.0]
[784, 865]
p03634
u947883560
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['#!/usr/bin/env python3\nimport sys\nimport math\nfrom collections import defaultdict\nsys.setrecursionlimit(10**6)\nINF = float("inf")\n\n\nclass Graph(object):\n \n\n def __init__(self, N):\n self.N = N\n self.edges = defaultdict(list)\n pass\n\n def add_edges(self, from_, to_, weight):\n \n self.edges[from_].append([to_, weight])\n self.edges[to_].append([from_, weight])\n pass\n\n\ndef solve(N: int,\n a: "List[int]",\n b: "List[int]",\n c: "List[int]",\n Q: int,\n K: int,\n x: "List[int]",\n y: "List[int]"):\n\n g = Graph(N)\n for aa, bb, cc in zip(a, b, c):\n g.add_edges(aa-1, bb-1, cc)\n\n N = g.N\n\n depth = [INF]*N\n\n def dfs(curr, pre, dep): \n depth[curr] = dep\n for n, w in g.edges[curr]:\n if n != pre:\n dfs(n, curr, dep+w)\n dfs(K, None, 0)\n\n for i in range(Q):\n print(depth[x[i]-1]+depth[y[i]-1])\n\n return\n\n\ndef main():\n\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n a = [int()] * (N-1) # type: "List[int]"\n b = [int()] * (N-1) # type: "List[int]"\n c = [int()] * (N-1) # type: "List[int]"\n for i in range(N-1):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n Q = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n x = [int()] * (Q) # type: "List[int]"\n y = [int()] * (Q) # type: "List[int]"\n for i in range(Q):\n x[i] = int(next(tokens))\n y[i] = int(next(tokens))\n solve(N, a, b, c, Q, K, x, y)\n\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nimport math\nfrom collections import defaultdict\nINF = float("inf")\n\n\nclass Graph(object):\n \n\n def __init__(self, N):\n self.N = N\n self.edges = defaultdict(list)\n pass\n\n def add_edges(self, from_, to_, weight):\n \n self.edges[from_].append([to_, weight])\n self.edges[to_].append([from_, weight])\n pass\n\n\ndef solve(N: int,\n a: "List[int]",\n b: "List[int]",\n c: "List[int]",\n Q: int,\n K: int,\n x: "List[int]",\n y: "List[int]"):\n\n g = Graph(N)\n for aa, bb, cc in zip(a, b, c):\n g.add_edges(*[aa-1, bb-1, cc])\n\n N = g.N\n\n par = [INF]*N\n depth = [INF]*N\n\n def dfs(curr, pre, dep): \n par[curr] = pre\n depth[curr] = dep\n for n, w in g.edges[curr]:\n if n != pre:\n dfs(n, curr, dep+w)\n dfs(K, None, 0)\n\n \n # print(depth[x[i]-1]+depth[y[i]-1])\n\n return\n\n\ndef main():\n\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n a = [int()] * (N-1) # type: "List[int]"\n b = [int()] * (N-1) # type: "List[int]"\n c = [int()] * (N-1) # type: "List[int]"\n for i in range(N-1):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n Q = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n x = [int()] * (Q) # type: "List[int]"\n y = [int()] * (Q) # type: "List[int]"\n for i in range(Q):\n x[i] = int(next(tokens))\n y[i] = int(next(tokens))\n solve(N, a, b, c, Q, K, x, y)\n\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nsys.setrecursionlimit(10**6)\nINF = float("inf")\n\n\nclass Graph(object):\n \n\n def __init__(self, N):\n self.N = N\n self.edges = defaultdict(list)\n pass\n\n def add_edges(self, from_, to_, weight):\n \n self.edges[from_].append([to_, weight])\n self.edges[to_].append([from_, weight])\n pass\n\n\ndef LCA_constract(g: Graph, root=0):\n \n N = g.N\n LN = int(math.log2(g.N))\n\n ###\n \n ###\n par = [INF]*N\n depth = [INF]*N\n\n que = deque()\n que.append([root, 0, None])\n while len(que) > 0:\n curr, dep, pre = que.popleft()\n par[curr] = pre\n depth[curr] = dep\n for n, w in g.edges[curr]:\n if n != pre:\n que.append([n, dep+w, curr])\n\n ###\n \n ###\n\n anc = [par]\n\n for i in range(LN):\n buf = [None]*N\n for j in range(N):\n if anc[i][j] == None:\n continue\n buf[j] = anc[i][anc[i][j]]\n anc.append(buf)\n return anc, depth\n\n\ndef LCA_query(anc, depth, u: int, v: int):\n ###\n \n ###\n N = len(depth)\n LN = int(math.log2(g.N))\n\n dd = depth[v] - depth[u]\n if dd < 0:\n u, v = v, u\n dd = -dd\n\n \n for k in range(LN):\n if dd & 1:\n v = anc[k][v]\n dd >>= 1\n\n \n if u == v:\n return u\n\n for k in range(LN-1, -1, -1):\n pu = anc[k][u]\n pv = anc[k][v]\n if pu != pv:\n u = pu\n v = pv\n\n \n return anc[0][u]\n\n\ndef solve(N: int,\n a: "List[int]",\n b: "List[int]",\n c: "List[int]",\n Q: int,\n K: int,\n x: "List[int]",\n y: "List[int]"):\n\n g = Graph(N)\n for aa, bb, cc in zip(a, b, c):\n g.add_edges(*[aa-1, bb-1, cc])\n\n anc, depth = LCA_constract(g, root=K-1)\n\n for i in range(Q):\n print(depth[x[i]-1]+depth[y[i]-1])\n\n return\n\n\ndef main():\n\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n a = [int()] * (N-1) # type: "List[int]"\n b = [int()] * (N-1) # type: "List[int]"\n c = [int()] * (N-1) # type: "List[int]"\n for i in range(N-1):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n Q = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n x = [int()] * (Q) # type: "List[int]"\n y = [int()] * (Q) # type: "List[int]"\n for i in range(Q):\n x[i] = int(next(tokens))\n y[i] = int(next(tokens))\n solve(N, a, b, c, Q, K, x, y)\n\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s463848695', 's567522051', 's173795998']
[180360.0, 72044.0, 85280.0]
[828.0, 802.0, 1149.0]
[1917, 1937, 3367]
p03634
u950708010
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['\nimport sys \ninput = sys.stdin.readline\nfrom collections import deque\ndef solve():\n n = int(input())\n d = [[]*n for _ in range(n)]\n for i in range(n-1):\n a,b,c = (int(i) for i in input().split())\n d[a-1].append((b-1,c))\n d[b-1].append((a-1,c))\n q,k = (int(i) for i in input().split())\n \n d2 = [10**10]*n\n visit = [0]*n\n query = deque([(k-1,0)]) \n while query:\n place,dist = query.pop()\n if visit[place] >= 2:\n continue\n else:\n visit[place] += 1\n d2[place] = min(dist,d2[place])\n for i in range(len(d[place])):\n np,nc = d[place][i]\n if not visit[np] >= 2:\n query.append((np,nc+dist))\n for i in range(q):\n x,y = (int(i) for i in input().split())\n print(int(d2[x-1] + d2[y-1]))\n\nsolve()', '\nimport sys \ninput = sys.stdin.readline\nfrom collections import deque\ndef solve():\n n = int(input())\n d = [[]*n for _ in range(n)]\n for i in range(n-1):\n a,b,c = (int(i) for i in input().split())\n d[a-1].append((b-1,c))\n d[b-1].append((a-1,c))\n q,k = (int(i) for i in input().split())\n \n d2 = [10**10]*n\n visit = [False]*n\n query = deque([(k-1,0)]) \n while query:\n place,dist = query.pop()\n if visit[place]:\n continue\n else:\n visit[place] = visit\n d2[place] = dist\n for i in range(len(d[place])):\n np,nc = d[place][i]\n if not visit[np]:\n query.append((np,nc+dist))\n for i in range(q):\n x,y = (int(i) for i in input().split())\n print(int(d2[x-1] + d2[y-1]))\n\nsolve()']
['Wrong Answer', 'Accepted']
['s940961173', 's966924179']
[58124.0, 47948.0]
[920.0, 702.0]
[808, 790]
p03634
u969708690
2,000
262,144
You are given a tree with N vertices. Here, a _tree_ is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
['import sys\nsys.setrecursionlimit(10 ** 7)\ndef input() : return sys.stdin.readline().strip()\ndef INT() : return int(input())\ndef MAP() : return map(int,input().split())\ndef LIST() : return list(MAP())\ndef NIJIGEN(H): return [list(input()) for i in range(H)]\ndef bfs(place,dis):\n for i in tree[place]:\n a,b=i\n if a not in finish:\n finish.add(a)\n disli[a]=dis+b\n bfs(a,dis+b)\nN=INT()\ntree=[[] for _ in range(N)]\nfor i in range(N-1):\n a,b,c=MAP()\n tree[a-1].append([b-1,c])\n tree[b-1].append([a-1,c])\nQ,K=MAP()\ndisli=[0 for i in range(N)]\nfinish=set()\nbfs(K-1,0)\n\nfor i in range(Q):\n a,b=MAP()\n print(disli[a-1]+disli[b-1])', 'import sys\nsys.setrecursionlimit(10 ** 7)\ndef input() : return sys.stdin.readline().strip()\ndef INT() : return int(input())\ndef MAP() : return map(int,input().split())\ndef LIST() : return list(MAP())\ndef NIJIGEN(H): return [list(input()) for i in range(H)]\ndef bfs(place,dis):\n for i in tree[place]:\n a,b=i\n if a not in finish:\n finish.add(a)\n disli[a]=dis+b\n bfs(a,dis+b)\nN=INT()\ntree=[[] for _ in range(N)]\nfor i in range(N-1):\n a,b,c=MAP()\n tree[a-1].append([b-1,c])\n tree[b-1].append([a-1,c])\nQ,K=MAP()\ndisli=[0 for i in range(N)]\nfinish=set([K-1])\nbfs(K-1,0)\nfor i in range(Q):\n a,b=MAP()\n print(disli[a-1]+disli[b-1])']
['Wrong Answer', 'Accepted']
['s513663824', 's919138716']
[147896.0, 147884.0]
[672.0, 646.0]
[658, 662]
p03639
u048176319
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input())\nl = list(map(int, input().split()))\n\nfor i in range(n):\n if l[i] % 4 == 0:\n l[i] = 2\n elif l[i] % 4 == 2:\n l[i] = 1\n else:\n l[i] = 0\n\nprint(l)\n\nif n - (l.count(2)*2 + 1) <= 0:\n print("Yes")\nelif n - (l.count(2)*2 + 1) < l.count(1):\n print("Yes")\nelse:\n print("No")', 'n = int(input())\nl = list(map(int, input().split()))\n\nfor i in range(n):\n if l[i] % 4 == 0:\n l[i] = 2\n elif l[i] % 4 == 2:\n l[i] = 1\n else:\n l[i] = 0\n\nif n - (l.count(2)*2 + 1) <= 0:\n print("Yes")\nelif n - (l.count(2)*2 + 1) < l.count(1):\n print("Yes")\nelse:\n print("No")']
['Wrong Answer', 'Accepted']
['s074135688', 's376257447']
[14252.0, 14252.0]
[82.0, 78.0]
[320, 310]
p03639
u054106284
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['H, W = (int(i) for i in input().split())\nN = int(input())\nA = [int(i) for i in input().split()]\nC = []\nfor i in range(N):\n for j in range(A[i]):\n C.append(i+1)\nans = [[0]*W for i in range(H)]\nfor i in range(H*W):\n y = i // W\n if y%2==0:\n x = i%W\n else:\n x = W-1-i%W\n ans[x][y] = C[i]\nfor i in range(H):\n ans[i] = [str(a) for a in ans[i]]\n print(" ".join(ans[i]))', 'N = int(input())\nA = [int(i) for i in input().split()]\nc4=0\nc2=0\nfor i in range(N):\n if A[i]%4==0:\n c4+=1\n elif A[i]%2==0:\n c2+=1\nif c4:\n a = c4*2+1\nelse:\n a = 0\nif c2>1:\n b = c2\n if a:\n a -= 1\nelse:\n b = 0\nif a+b>=N:\n print("Yes")\nelse:\n print("No")']
['Runtime Error', 'Accepted']
['s182790772', 's710826656']
[3064.0, 14228.0]
[17.0, 76.0]
[378, 268]
p03639
u057993957
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['import numpy as np\nn = int(input())\na = np.array(list(map(int, input().split())))\n\na4 = len(a[a % 4 == 0])\na2 = len(a[a % 2 == 0 and a % 4 != 0])\na4n = len(a[a % 4 != 0]) - a2 \n\nif a2 != 0:\n print("Yes" if a4 + 1 >= a4n+1 else "No")\n\nelse:\n print("Yes" if a4 + 1 >= a4n else "No")', 'n = int(input())\na = list(map(int, input().split()))\n\na4, a4n, a2 = 0, 0, 0\nfor ai in a:\n if ai % 4 == 0:\n a4 += 1\n elif ai % 2 == 0:\n a2 += 1\n else:\n a4n += 1\n\nif a2 != 0:\n print("Yes" if a4 + 1 >= a4n+1 else "No")\n\nelse:\n print("Yes" if a4 + 1 >= a4n else "No")\n\n\n']
['Runtime Error', 'Accepted']
['s919462204', 's724474699']
[23120.0, 14252.0]
[186.0, 64.0]
[282, 280]
p03639
u101225820
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['import sys\nN=int(input())\nl=map(int,input().split())\na,b,c=0,0,True\nfor i in l:\n if i%4==0:b+=1\n else:\n if i%2!=0:a+=1\n else:c=False\n\nprint(c)\nif a==0:\n print("Yes")\n sys.exit()\nif c:\n if b==0:\n print("No")\n sys.exit()\n if b>=a-1:print("Yes")\n else:print("No")\nelse:\n if b>=a:print("Yes")\n else:print("No")', 'import sys\nN=int(input())\nl=map(int,input().split())\na,b,c=0,0,True\nfor i in l:\n if i%4==0:b+=1\n else:\n if i%2!=0:a+=1\n else:c=False\n\nif a==0:\n print("Yes")\n sys.exit()\nif c:\n if b==0:\n print("No")\n sys.exit()\n if b>=a-1:print("Yes")\n else:print("No")\nelse:\n if b>=a:print("Yes")\n else:print("No")']
['Wrong Answer', 'Accepted']
['s966533889', 's025812729']
[11100.0, 11096.0]
[65.0, 66.0]
[361, 352]
p03639
u130900604
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['\n\nn=int(input())\namod4=[i%4 for i in map(int,input().split())]\nprint(amod4)\nfrom collections import Counter\ns=Counter(amod4)\nnum4=s[0]\nnum2=s[2]\n\n#print(num4,num2,another)\n\ndef ok():print("Yes");exit()\ndef ng():print("No");exit()\n\nif num2==n:\n ok()\n \nif num4>=(n-(num2-1)*(n>num2>0))//2:ok()\n\nelse:\n ng()\n\n', '\n\nn=int(input())\namod4=[i%4 for i in map(int,input().split())]\n#print(amod4)\nfrom collections import Counter\ns=Counter(amod4)\nnum4=s[0]\nnum2=s[2]\n\n#print(num4,num2,another)\n\ndef ok():print("Yes");exit()\ndef ng():print("No");exit()\n\nif num2==n:\n ok()\n \nif num4>=(n-(num2-1)*(n>num2>0))//2:ok()\n\nelse:\n ng()\n\n']
['Wrong Answer', 'Accepted']
['s598307096', 's563798872']
[11096.0, 11096.0]
[66.0, 58.0]
[340, 341]
p03639
u131464432
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N = int(input())\na = list(map(int,input().split()))\nzero,one,two = 0,0,0\nfor i in a:\n if i%4 == 0:\n two += 1\n elif i%2 == 0:\n one += 1\n else:\n zero += 1\nif one = N:\n print("Yes")\n exit()\nprint("Yes" if two+int(two>0) >= zero+int(one>0) else "No")', 'N = int(input())\na = list(map(int,input().split()))\nzero,one,two = 0,0,0\nfor i in a:\n if i%4 == 0:\n two += 1\n elif i%2 == 0:\n one += 1\n else:\n zero += 1\nif one == N:\n print("Yes")\n exit()\nprint("Yes" if two+int(two>0) >= zero+int(one>0) else "No")']
['Runtime Error', 'Accepted']
['s805044134', 's310327829']
[9032.0, 20104.0]
[26.0, 63.0]
[282, 283]
p03639
u131881594
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input)\na=list(map(int,input().split()))\ncnt,cnt2,cnt4=0,0,0\nfor val in a:\n if val%4==0:\n cnt4+=1\n elif val%2==0:\n cnt2+=1\n else:\n cnt+=1\nif cnt2==n: print("Yes")\nelse:\n if cnt4>=cnt: print("Yes")\n else: print("No")', 'h,w=map(int,input().split())\nn=int(input())\na=list(map(int,input().split()))\ncolors=[]\nfor i in range(n):\n for _ in range(a[i]):\n colors.append(i+1)\nans=[[0 for _ in range(w)] for _ in range(h)]\ntemp=0\nfor i in range(h):\n for j in range(w):\n if i%2!=0:\n j = w-j-1\n ans[i][j]=colors[temp]\n temp+=1\n\nfor i in range(h):\n for j in range(w):\n print(ans[i][j], end="")\n print()', 'n = int(input())\na=list(map(int,input().split()))\ncnt,cnt2,cnt4=0,0,0\nfor val in a:\n if val%4==0:\n cnt4+=1\n elif val%2==0:\n cnt2+=1\n else:\n cnt+=1\nif cnt2==0:\n if cnt4>=cnt-1: print("Yes")\n else: print("No")\nelse:\n if cnt4>=cnt: print("Yes")\n else: print("No")']
['Runtime Error', 'Runtime Error', 'Accepted']
['s091486243', 's136184415', 's063162573']
[3064.0, 3064.0, 14252.0]
[18.0, 17.0, 65.0]
[258, 429, 302]
p03639
u166340293
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N=int(input())\na=list(map(int,input().split()))\nodd=0\nfour=0\nfor i in range(N):\n if a[i]%4==0:\n four+=1\n elif a[i]%2!=0:\n odd+=1\nif four>=odd or four+odd=N:\n print("Yes")\nelse:\n print("No")', 'N=int(input())\na=list(map(int,input().split()))\nodd=0\nfour=0\nfor i in range(N):\n if a[i]%4==0:\n four+=1\n elif a[i]%2!=0:\n odd+=1\nif four>=odd:\n print("Yes")\nelse:\n if odd==four+1 and odd+four==N:\n print("Yes")\n else:\n print("No")']
['Runtime Error', 'Accepted']
['s745814547', 's902911832']
[2940.0, 15020.0]
[18.0, 72.0]
[199, 246]
p03639
u167681750
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input())\na = list(map(int, input().split()))\naa = [2 if i % 4 == 0 else 1 if i % 2 == 0 else 0 for i in a]\na4, a2, a0 = aa.count(2),aa.count(1), aa.count(0)\n\nif a2 == 0:\n a4 += 1\n\nprint("YES" if a4 >= a0 else "NO")', 'n = int(input())\na = list(map(int, input().split()))\naa = [2 if i % 4 == 0 else 1 if i % 2 == 0 else 0 for i in a]\na4, a2, a0 = aa.count(2),aa.count(1), aa.count(0)\n\nif a2 == 0:\n a4 += 1\n\nprint("Yes" if a4 >= a0 else "No")']
['Wrong Answer', 'Accepted']
['s888890328', 's966573212']
[14252.0, 15020.0]
[61.0, 60.0]
[225, 225]
p03639
u197457087
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N = int(input())\n\na=0;b=0;c=0\nL = list(map(int,input().split()))\nfor i in range(N):\n if L[i]%4 == 0:\n c += 1\n elif L[i]%2 == 0:\n b += 1\n else:\n a += 1\nt = a+b+c\nprint(a,b,c)\nans = "No"\nif a == 0:\n ans = "Yes"\nelif c >= a:\n ans = "Yes"\nelif b == 0 and a == c+1:\n ans ="Yes"\nprint(ans)', 'N = int(input())\n\na=0;b=0;c=0\nL = list(map(int,input().split()))\nfor i in range(N):\n if L[i]%4 == 0:\n c += 1\n elif L[i]%2 == 0:\n b += 1\n else:\n a += 1\nt = a+b+c\n#print(a,b,c)\nans = "No"\nif a == 0:\n ans = "Yes"\nelif c >= a:\n ans = "Yes"\nelif b == 0 and a == c+1:\n ans ="Yes"\nprint(ans)']
['Wrong Answer', 'Accepted']
['s984093469', 's867565749']
[14480.0, 14480.0]
[71.0, 80.0]
[298, 299]
p03639
u243492642
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['# coding: utf-8\nINF = 10 ** 20\nMOD = 10 ** 9 + 7\n\n\ndef II(): return int(input())\ndef ILI(): return list(map(int, input().split()))\n\n\ndef read():\n N = II()\n a = ILI()\n return N, a\n\n\ndef solve(N, a):\n n_odd = 0\n n_div_2 = 0\n n_div_4 = 0\n for _a in a:\n if _a % 2 == 1:\n n_odd += 1\n else:\n if _a % 4 == 0:\n n_div_4 += 1\n else:\n n_div_2 += 1\n\n ans = ""\n if n_div_2 == 1:\n if n_div_4 > n_odd:\n ans = "Yes"\n else:\n ans = "No"\n else:\n if n_div_4 > n_odd + 1:\n ans = "Yes"\n else:\n ans = "No"\n\n return ans\n\n\ndef main():\n params = read()\n print(solve(*params))\n\n\nif __name__ == "__main__":\n main()\n', '6\n2 7 1 8 2 8', '# coding: utf-8\nINF = 10 ** 20\nMOD = 10 ** 9 + 7\n\n\ndef II(): return int(input())\ndef ILI(): return list(map(int, input().split()))\n\n\ndef read():\n N = II()\n a = ILI()\n return N, a\n\n\ndef solve(N, a):\n n_odd = 0\n n_div_2 = 0\n n_div_4 = 0\n for _a in a:\n if _a % 2 == 1:\n n_odd += 1\n else:\n if _a % 4 == 0:\n n_div_4 += 1\n else:\n n_div_2 += 1\n print(n_odd)\n print(n_div_2)\n print(n_div_4)\n\n ans = ""\n if n_div_2 == 0:\n if n_div_4 >= n_odd - 1:\n ans = "Yes"\n else:\n ans = "No"\n else:\n if n_div_4 >= n_odd:\n ans = "Yes"\n else:\n ans = "No"\n\n return ans\n\n\ndef main():\n params = read()\n print(solve(*params))\n\n\nif __name__ == "__main__":\n main()\n', '# coding: utf-8\nINF = 10 ** 20\nMOD = 10 ** 9 + 7\n\n\ndef II(): return int(input())\ndef ILI(): return list(map(int, input().split()))\n\n\ndef read():\n N = II()\n a = ILI()\n return N, a\n\n\ndef solve(N, a):\n n_odd = 0\n n_div_2 = 0\n n_div_4 = 0\n for _a in a:\n if _a % 2 == 1:\n n_odd += 1\n else:\n if _a % 4 == 0:\n n_div_4 += 1\n else:\n n_div_2 += 1\n\n ans = ""\n if n_div_2 == 0:\n if n_div_4 >= n_odd - 1:\n ans = "Yes"\n else:\n ans = "No"\n else:\n if n_div_4 >= n_odd:\n ans = "Yes"\n else:\n ans = "No"\n\n return ans\n\n\ndef main():\n params = read()\n print(solve(*params))\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s029406198', 's200333336', 's349481277', 's286823625']
[14480.0, 3064.0, 14480.0, 14480.0]
[59.0, 18.0, 59.0, 59.0]
[778, 13, 835, 780]
p03639
u247554097
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["\n\nn = int(input())\narr = list(map(int, input().split()))\ndividable_four = 0\nodds = 0\nfor a in arr:\n if a % 4 == 0:\n dividable_four += 1\n elif a % 2 == 1:\n odds += 1\nif dividable_four >= odds:\n print('YES')\nelif odds - dividable_four == 1 and odds + dividable_four == n:\n print('YES')\nelse:\n print('NO')\n", "\n\nn = int(input())\narr = list(map(int, input().split()))\ndividable_four = 0\nodds = 0\nfor a in arr:\n if a % 4 == 0:\n dividable_four += 1\n elif a % 2 == 1:\n odds += 1\nif dividable_four >= odds:\n print('Yes')\nelif odds - dividable_four == 1 and odds + dividable_four == n:\n print('Yes')\nelse:\n print('No')\n"]
['Wrong Answer', 'Accepted']
['s012347533', 's389501800']
[14252.0, 14252.0]
[63.0, 64.0]
[480, 480]
p03639
u249447366
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["N = int(input())\nA = list(map(int, input().split()))\nmaru = len([a for a in A if a % 4 == 0])\nsankaku = len([a for a in A if a == 2])\nbatu = len(A) - maru - sankaku\n\nif sankaku:\n if batu <= maru + 1:\n print('Yes')\n else:\n print('No')\nelse:\n if batu <= maru:\n print('Yes')\n else:\n print('No')\n", "N = int(input())\nA = list(map(int, input().split()))\nmaru = len([a for a in A if a % 4 == 0])\nbatu = len([a for a in A if a % 2 == 1])\nsankaku = N - maru - batu\n\nif sankaku:\n if batu <= maru:\n print('Yes')\n else:\n print('No')\nelse:\n if batu <= maru + 1:\n print('Yes')\n else:\n print('No')\n"]
['Wrong Answer', 'Accepted']
['s491574035', 's844168222']
[15020.0, 15020.0]
[53.0, 58.0]
[332, 328]
p03639
u278356323
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input())\na = list(map(int, input().split()))\n\nfor i in range(n):\n if a[i] % 4 == 0:\n a[i] = 2\n elif a[i] % 2 == 0:\n a[i] = 1\n else:\n a[i] = 0\nprint(a)\n', "n = int(input())\na = list(map(int, input().split()))\n\nfor i in range(n):\n if a[i] % 4 == 0:\n a[i] = 2\n elif a[i] % 2 == 0:\n a[i] = 1\n else:\n a[i] = 0\n# print(a)\n\nif a.count(0)+(1 if 1 in a else 0) <= a.count(2)+1:\n print('Yes')\n exit(0)\nprint('No')\n"]
['Wrong Answer', 'Accepted']
['s248797732', 's363051197']
[14224.0, 14224.0]
[80.0, 73.0]
[189, 285]
p03639
u278670845
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n=int(input())\na=list(map(int,input().split()))\na1=0\na2=0\na3=0\nfor i in a:\n if a%4==0:\n a1+=1\n elif a%4==2:\n a2+=1\n else:\n a3+=1\n \nif a3==0:\n print("Yes")\nelse:\n if a2==0:\n if a1>=a3-1:\n print("Yes")\n else:\n print("No")\n else:\n if a1>=a3:\n print("Yes")\n else:\n print("No")', 'n=int(input())\na=list(map(int,input().split()))\na1=0\na2=0\na3=0\nfor i in a:\n if i%4==0:\n a1+=1\n elif i%4==2:\n a2+=1\n else:\n a3+=1\n \nif a3==0:\n print("Yes")\nelse:\n if a2==0:\n if a1>=a3-1:\n print("Yes")\n else:\n print("No")\n else:\n if a1>=a3:\n print("Yes")\n else:\n print("No")']
['Runtime Error', 'Accepted']
['s780463064', 's286495859']
[14252.0, 14252.0]
[43.0, 65.0]
[322, 322]
p03639
u278886389
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['from collections import Counter\n\ndef a():\n N = int(input())\n A = map(int,input().split(" "))\n c = Counter(map(lambda x:(x%4 and 1)+x%2,A))\n if c[1]:\n return c[2] <= c[0]\n else:\n return c[2] <= c[0] + 1\n\nprint([\'NO\',\'YES\'][a()])', 'from collections import Counter\n\ndef a():\n N = int(input())\n A = map(int,input().split(" "))\n c = Counter(map(lambda x:(x%4 and 1)+x%2,A))\n if c[1]:\n return c[2] <= c[0]\n else:\n return c[2] <= c[0] + 1\n\nprint([\'No\',\'Yes\'][a()])']
['Wrong Answer', 'Accepted']
['s167588506', 's129581932']
[11436.0, 11436.0]
[79.0, 72.0]
[256, 256]
p03639
u280512618
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["from collections import Counter\nn=int(input())\ncounter=Counter(1 if x % 2 else 2 if x % 4 else 4 for x in (int(s) for s in input().split()))\nprint('Yes' if counter[1] < counter[4] else 'No')\n", "from collections import Counter\nn=int(input())\ncounter=Counter(1 if x % 2 else 2 if x % 4 else 4 for x in (int(s) for s in input().split()))\nprint('Yes' if counter[1] <= counter[4] or counter[2] == 0 and counter[1] == counter[4] + 1 else 'No')"]
['Wrong Answer', 'Accepted']
['s839845995', 's945467292']
[11436.0, 11436.0]
[71.0, 72.0]
[191, 243]
p03639
u306412379
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n = int(input())\naa = list(map(int, input().split()))\nc2 = 0\nc4 = 0\n\nfor a in aa:\n if a % 4 == 0:\n c4 += 1\n elif a % 2 == 0:\n c2 += 1\n else:\n print('No')\n exit()\n\nif c4 + c2 == n:\n print('Yes')\n\nelif n/2 -1 < c4 < n/2 + 1:\n print('Yes')\n \nelif n % 4 == 2:\n if c4 == n / 2 - 1 and c2 == 2:\n print('Yes')\nelse:\n print('No')", "n = int(input())\naa = list(map(int, input().split()))\nc1 = 0 \nc2 = 0 \nc4 = 0\nla = len(aa)\n\nfor a in aa:\n if a % 4 == 0:\n c4 += 1\n elif a % 2 == 0:\n c2 += 1\n else:\n c1 += 1\n \nif c1 == 0:\n print('Yes')\n exit()\n\nelif c4 >= c1:\n print('Yes')\n exit()\n \nelif c4 == c1 - 1 and c2 == 0:\n print('Yes')\n exit()\n \nprint('No')"]
['Wrong Answer', 'Accepted']
['s912316414', 's331646024']
[20096.0, 20172.0]
[64.0, 66.0]
[344, 343]
p03639
u306950978
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input())\na = list(map(lambda x: int(x)%4 , input().split()))\nprint(a)\np = a.count(0)\nq = a.count(2)\nr = n-p-q\n\nif r > p:\n print("No")\nelse:\n print("Yes")', 'n = int(input())\na = list(map(lambda x: int(x)%4 , input().split()))\n\np = a.count(0)\nq = a.count(2)\nr = n-p-q\n\nif r > p:\n if r -p == 1 and q == 0:\n print("Yes")\n else:\n print("No")\nelse:\n print("Yes")']
['Wrong Answer', 'Accepted']
['s835117345', 's162523495']
[11096.0, 11096.0]
[67.0, 58.0]
[167, 223]
p03639
u311636831
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['a = list(map(int, input().split()))\nfor i in range(N):\n A += [i + 1] * a[i]\n \nL = [[0 for i in range(W)] for j in range(H)]\nfor i in range(H * W):\n if int((i // W)) % 2 == 0:\n L[int((i // W))][i % W] = A[i]\n else:\n L[int((i // W))][-1 - i % W] = A[i]\n \nfor i in range(H):\n L[i] = list(map(str, L[i]))\n \n \nfor i in range(H):\n print(" ".join(L[i]))', 'N=int(input())\nA = list(map(int, input().split()))\n\nodd=0\neven=0\neven2=0\n\nfor num in A:\n if(num%2==1):\n odd+=1\n elif(num%4==0):\n even2+=1\n else:\n even+=1\n\nif(even2>=odd):\n print("Yes")\nelif((even==0)&(even2==(odd-1))):\n print("Yes")\nelse:\n print("No")']
['Runtime Error', 'Accepted']
['s843053313', 's172351705']
[3064.0, 15020.0]
[18.0, 68.0]
[375, 290]
p03639
u329407311
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N = int(input())\nList=list(map(int,input().split()))\n\ncnt4 = 0\nfor i in range(N):\n a = List[i]\n if a%4 == 0:\n cnt4 += 1\n\ncnt2 = 0\nfor i in range(N):\n a = List[i]\n if a%2 == 0:\n cnt2 += 1\ncnt2 = int(cnt2 - cnt4)\n\nif cnt2 == 0:\n if cnt4 > N -cnt4:\n print("Yes")\n else:\n print("No")\nelse:\n if cnt4-1 > (N-cnt4) -cnt4:\n print("Yes")\n else:\n print("No")', 'N = int(input())\nList=list(map(int,input().split()))\n\ncnt4 = 0\nfor i in range(N):\n a = List[i]\n if a%4 == 0:\n cnt4 += 1\n\ncnt2 = 0\nfor i in range(N):\n a = List[i]\n if a%2 == 0:\n cnt2 += 1\ncnt2 = cnt2 - cnt4\n\nif int(N - cnt4*3 - cnt2//2) >= 0:\n print("No")\nelse:\n print("Yes")', 'N = int(input())\nList=list(map(int,input().split()))\n\ncnt4 = 0\nfor i in range(N):\n a = List[i]\n if a%4 == 0:\n cnt4 += 1\n\ncnt2 = 0\nfor i in range(N):\n a = List[i]\n if a%2 == 0:\n cnt2 += 1\ncnt2 = int(cnt2 - cnt4)\n\nif cnt2 == 0:\n if cnt4 >= N -cnt4 -1:\n print("Yes")\n else:\n print("No")\nelse:\n if cnt4-1 >= (N-cnt2) -cnt4-1:\n print("Yes")\n else:\n print("No")']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s050045192', 's967633798', 's257791457']
[14224.0, 14252.0, 14252.0]
[86.0, 86.0, 87.0]
[374, 286, 381]
p03639
u330205771
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["N = int(input())\np = list(map(int, input().split()))\n\nq = []\nsummation = [p[i] + p[i + 1] for i in range(N - 1)]\nfor i in range(int(N / 2)):\n if len(p) == 2:\n q = p + q\n else:\n index = summation.index(max(summation))\n q = p[index:index + 2] + q\n p = p[:index] + p[index + 2:]\n if index == 0:\n summation = summation[2:]\n elif index == len(summation):\n summation = summation[:index - 1]\n else:\n summation = summation[:index - 1] + [p[index - 1] + p[index]] + summation[index + 2:]\n\n[print(i, end=' ') for i in q]\n", "N = int(input())\np = list(map(int, input().split()))\n\nq = []\nsummation = [p[i] + p[i + 1] for i in range(N - 1)]\nfor i in range(int(N / 2)):\n if len(p) == 2:\n q = p + q\n else:\n index = summation.index(max(summation))\n q = p[index:index + 2] + q\n p = p[:index] + p[index + 2:]\n if index == 0:\n summation = summation[2:]\n elif index == len(summation) - 1:\n summation = summation[:index - 1]\n else:\n summation = summation[:index - 1] + [p[index - 1] + p[index]] + summation[index + 2:]\n\n[print(i, end=' ') for i in q]", "N = int(input())\np = list(map(int, input().split()))\n\nq = []\nsummation = [p[i] + p[i + 1] for i in range(N - 1)]\nfor i in range(int(N / 2)):\n if len(p) == 2:\n q = p + q\n else:\n index = summation.index(max(summation))\n q = p[index:index + 2] + q\n p = p[:index] + p[index + 2:]\n print(index, summation)\n if index == 0:\n summation = summation[2:]\n elif index == len(summation):\n summation = summation[:index - 1]\n else:\n summation = summation[:index - 1] + [p[index - 1] + p[index]] + summation[index + 2:]\n\n[print(i, end=' ') for i in q]", "N = int(input())\np = list(map(int, input().split()))\n\nq = []\nsummation = [p[i] + p[i + 1] for i in range(N - 1)]\nfor i in range(int(N / 2)):\n if len(p) == 2:\n q = p + q\n else:\n index = summation.index(max(summation))\n q = p[index:index + 2] + q\n p = p[:index] + p[index + 2:]\n if index == 0:\n summation = summation[2:]\n elif index == len(summation) - 1:\n summation = summation[:index - 1]\n else:\n summation = summation[:index - 1] + [p[index - 1] + p[index]] + summation[index + 2:]\n\n[print(i, end=' ') for i in q]", "N = int(input())\na = list(map(int, input().split()))\n\ncount1 = 0\ncount2 = 0\ncount4 = 0\nfor i in range(N):\n value = a[i] % 4\n if value == 0:\n count4 += 1\n elif value == 2:\n count2 += 1\n else:\n count1 += 1\n\nif count1 <= count4 or (count1 - count4 == 1 and count2 == 0):\n print('Yes')\nelse:\n print('No')"]
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s241316552', 's379912471', 's735713522', 's967998946', 's104644717']
[14660.0, 15712.0, 147612.0, 14624.0, 14252.0]
[2104.0, 2104.0, 1910.0, 2104.0, 69.0]
[599, 602, 630, 602, 339]
p03639
u337626942
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n=int(input())\na=list(map(int, input().split()))\ncnt_2=0\ncnt_1=0\ncnt_0=0\n\nfor num in a:\n if num%4==0:\n cnt_2+=1\n elif num%2==0:\n cnt_1+=1\n else:\n cnt_0+=1\n\nif cnt_1=0:\n if cnt_2+1>=cnt_0:\n print("Yes")\n else:\n print("No")\n\nelse:\n if cnt_2>=cnt_0:\n print("Yes")\n else:\n print("No")', 'n=int(input())\na=list(map(int, input().split()))\ncnt_2=0\ncnt_1=0\ncnt_0=0\n\nfor num in a:\n if num%4==0:\n cnt_2+=1\n elif num%2==0:\n cnt_1+=1\n else:\n cnt_0+=1\n\nif cnt_1==0:\n if cnt_2+1>=cnt_0:\n print("Yes")\n else:\n print("No")\n\nelse:\n if cnt_2>=cnt_0:\n print("Yes")\n else:\n print("No")']
['Runtime Error', 'Accepted']
['s712060016', 's213968216']
[2940.0, 14252.0]
[17.0, 64.0]
[350, 351]
p03639
u419645731
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["h, w = map(int,input().split())\nn = int(input())\na = list(map(int,input().split()))\ngrid = [[' ']*w for i in range(h)]\n\nci = 0\nfor i in range(h):\n for j in range(w):\n if not a[ci]: ci+= 1\n if i%2==0: grid[i][j] = ci+1\n else: grid[i][~j] = ci+1\n a[ci]-= 1\nfor row in grid: print(*row)", 'h, w = map(int,input().split())\nn = int(input())\na = list(map(int,input().split()))', '# one -> four\n# two -> two, four\n# four -> one, two, four\n\nn = int(input())\none = 0\ntwo = 0\nfour = 0\n\nfor a in map(int,input().split()):\n if a%2 != 0: one+= 1\n elif a%4 != 0: two+= 1\n else: four+= 1\n\ndef no():\n print("No")\n exit()\n\nif two == 0:\n #1414141\n print("Yes" if four >= one-1 else "No")\nelse:\n #222222241414141\n print("Yes" if four >= one else "No")']
['Runtime Error', 'Runtime Error', 'Accepted']
['s047804105', 's083681859', 's059608979']
[3064.0, 3060.0, 11480.0]
[17.0, 18.0, 69.0]
[314, 83, 385]
p03639
u440975163
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n = int(input())\nb = list(map(int, input().split()))\nln = []\nln2 = []\nfor i in b:\n if i % 4 == 0:\n ln.append(i)\n if i % 2 == 0 and i % 4 != 0:\n ln2.append(i)\nif n % 2 == 0:\n if len(ln) >= n//2:\n print('Yes')\nif n % 2 == 1:\n if len(ln) >= (n + 1)//2:\n print('Yes')\nelif n - len(ln) * 2 == len(ln2):\n print('Yes')\nelse:\n print('No')", "n = int(input())\nb = list(map(int, input().split()))\nln = []\nln2 = []\nfor i in b:\n if i % 4 == 0:\n ln.append(i)\n if i % 2 == 0 and i % 4 != 0:\n ln2.append(i)\nif n % 2 == 0:\n if len(ln) >= n//2:\n print('Yes')\n else:\n if n - len(ln) * 2 == len(ln2):\n print('Yes')\n \n else:\n print('No')\nif n % 2 == 1:\n if len(ln) >= (n - 1)//2:\n print('Yes')\n else:\n if n - len(ln) * 2 == len(ln2):\n print('Yes')\n else:\n if n == 3 and len(ln) == 1:\n print('Yes')\n else:\n print('No')"]
['Wrong Answer', 'Accepted']
['s202082201', 's988029596']
[14252.0, 14480.0]
[74.0, 74.0]
[377, 643]
p03639
u485319545
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n=int(input())\na=list(map(int,input().split()))\n\nborder_4 = n//2\nborder_2 = n\n\ncnt_4=0\ncnt_2=0\n\nfor i in range(n):\n if a[i]%4==0:\n cnt_4+=1\n cnt_2+=1\n elif a[i]%2==0:\n cnt_2+=1\n else:\n continue\n\n\nif cnt_4>=border_4:\n print('YES')\nelif n-cnt_4*2<=(cnt_2-cnt_4):\n print('YES')\nelse:\n print('NO')", "n=int(input())\na=list(map(int,input().split()))\n\nborder_4 = n//2\nborder_2 = n\n\ncnt_4=0\ncnt_2=0\n\nfor i in range(n):\n if a[i]%4==0:\n cnt_4+=1\n elif a[i]%4!=0 and a[i]%2==0:\n cnt_2+=1\n else:\n continue\n\n\nif cnt_4>=border_4:\n print('YES')\nelif n-cnt_4*2<=cnt_2:\n print('YES')\nelse:\n print('NO')", "n=int(input())\na=list(map(int,input().split()))\n\nborder_4 = n//2\nborder_2 = n\n\ncnt_4=0\ncnt_2=0\n\nfor i in range(n):\n if a[i]%4==0:\n cnt_4+=1\n cnt_2+=1\n elif a[i]%2==0:\n cnt_2+=1\n else:\n continue\n\n\nif cnt_4>=border_4:\n print('Yes')\nelif n-cnt_4*2<=(cnt_2-cnt_4):\n print('Yes')\nelse:\n print('No')\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s740337146', 's800233353', 's676740477']
[14252.0, 14252.0, 14252.0]
[71.0, 81.0, 70.0]
[339, 328, 340]
p03639
u488884575
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n = int(input())\nA = list(map(int, input().split()))\nf2 = 0\nf4 = 0\nfor a in A:\n \n if a%4 == 0:\n f4 += 1\n elif a%2 == 0:\n f2 += 1\nif n -f2//2 *2 -f4 *2 <= 0:\n print('Yes')\nelse:\n print('No')", "n = int(input())\nA = list(map(int, input().split()))\nf2 = 0\nf4 = 0\nf_another = 0\nfor a in A:\n \n if a%4 == 0:\n f4 += 1\n elif a%2 == 0:\n f2 += 1\n else:\n f_another +=1\nif n%2 == 0 and (n -f2//2 *2 -f4 *2 <= 0):\n print('Yes')\nelif n%2 == 1 and (n -f2//2 *2 -f4 *2 <= 1):\n print('Yes')\nelse:\n print('No')"]
['Wrong Answer', 'Accepted']
['s821816986', 's741827398']
[15020.0, 14252.0]
[63.0, 67.0]
[262, 385]
p03639
u509739538
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['from collections import defaultdict\nfrom collections import deque\nimport itertools\nimport math\n\ndef readInt():\n\treturn int(input())\ndef readInts():\n\treturn list(map(int, input().split()))\ndef readChar():\n\treturn input()\ndef readChars():\n\treturn input().split()\n\nn = readInt()\nd = {"2":0,"4":0,"other":0}\nfor i in readInts():\n\tif i%4==0:\n\t\td["4"]+=1\n\telif i%2==0:\n\t\td["2"]+=1\n\telse:\n\t\td["other"]+=1\nif d["2"]>1:\n\tif d["4"]>=d["other"]:\n\t\tprint("Yes")\n\telse:\n\t\tprint("No")\nelif d["2"]==1:\n\tif d["4"]>=d["other"]+d["2"]:\n\t\tprint("Yes")\n\telse:\n\t\tprint("No")\nelse:\n\tif d["4"]+1>=d["other"]:\n\t\tprint("Yes")\n\telse:\n\t\tprint("No")', 'from collections import defaultdict\nfrom collections import deque\nimport itertools\nimport math\n\ndef readInt():\n\treturn int(input())\ndef readInts():\n\treturn list(map(int, input().split()))\ndef readChar():\n\treturn input()\ndef readChars():\n\treturn input().split()\n\nn = readInt()\nd = {"2":0,"4":0,"other":0}\nfor i in readInts():\n\tif i%4==0:\n\t\td["4"]+=1\n\telif i%2==0:\n\t\td["2"]+=1\n\telse:\n\t\td["other"]+=1\n\nif d["4"]>=d["other"]+min(0,d["2"]-1):\n\tprint("Yes")\nelse:\n\tprint("No")']
['Wrong Answer', 'Accepted']
['s296055413', 's777294142']
[20428.0, 20804.0]
[72.0, 70.0]
[621, 470]
p03639
u524922893
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n=int(input())\na=list(map(int,input().split()))\nb=0\nc=0\nfor i in range(n):\n if a[i]%2==0:\n if a[i]%4==0:\n c+=1\n else:\n b+=1\nif b==0:\n print("Yes") if n<=3*c else print("No")\nelse:\n print("Yes") if n<=3c+b-1 else print("No")', 'n=int(input())\na=list(map(int,input().split()))\nb=0\nc=0\nfor i in range(n):\n if a[i]%2==0:\n if a[i]%4==0:\n c+=1\n else:\n b+=1\nif c==0:\n print("Yes") if n==b else print("No")\nelif b==0:\n print("Yes") if n<=2*c+1 else print("No")\nelse:\n print("Yes") if n<=2*c+b else print("No")']
['Runtime Error', 'Accepted']
['s616513109', 's601544600']
[3064.0, 14252.0]
[17.0, 72.0]
[242, 294]
p03639
u545368057
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['n = int(input())\nAs = list(map(int, input().split()))\n\n# four = sum([1 for a in As if a%4 == 0])\n# odd = sum([1 for a in As if a%2 == 1])\n# two = sum([1 for a in As if a%2 == 0 and a%4 != 0])\nfour = 0\nodd = 0\ntwo = 0\nfor a in As:\n if a % 2 == 1:\n odd += 1\n elif a % 4 == 0:\n four += 1\n else:\n two += 1\n\n\nif four < two%2 + odd - 1:\n print("No")\nelse:\n print("Yes")\n\n\nfields @timestamp, @message\n| sort @timestamp desc\n| filter \n| limit 20', 'n = int(input())\nAs = list(map(int, input().split()))\n\n# four = sum([1 for a in As if a%4 == 0])\n# odd = sum([1 for a in As if a%2 == 1])\n# two = sum([1 for a in As if a%2 == 0 and a%4 != 0])\nfour = 0\nodd = 0\ntwo = 0\nfor a in As:\n if a % 2 == 1:\n odd += 1\n elif a % 4 == 0:\n four += 1\n else:\n two += 1\n\n\nif four < two%2 + odd - 1:\n print("No")\nelse:\n print("Yes")\n\n']
['Runtime Error', 'Accepted']
['s142039187', 's014513539']
[2940.0, 15020.0]
[17.0, 65.0]
[473, 401]
p03639
u609814378
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N = int(input())\nA = list(map(int, input().split()))\n\neight = 0\none = 0\ntwo = 0\n\n\nfor i in A:\n print(i%4)\n if i%4 == 0:\n eight = eight + 1\n if i == 1:\n one = one + 1\n if i%2 == 0:\n two = two + 1\n\nif len(A)//2 <= eight:\n print("Yes")\nelif (len(A)//2) <= (eight + (two//2)):\n print("Yes")\n\nelif (eight >= one) and (eight + one +(two//2)) > (len(A)//2):\n print("Yes")\nelif (two//2) == len(A):\n print("Yes")\nelse:\n print("No")', 'N = int(input())\nA = list(map(int, input().split()))\n \neight = 0\none = 0\ntwo = 0\n \n \nfor i in A:\n if i%4 == 0:\n eight = eight + 1\n if i == 1:\n one = one + 1\n if i % 2 == 0 and i % 4 != 0:\n two = two + 1\n \nif len(A)//2 <= eight:\n print("Yes")\nelif (len(A)//2) <= (eight + (two//2)):\n print("Yes")\n \nelif (eight >= one) and (eight + one +(two//2)) > (len(A)//2):\n print("Yes")\nelse:\n print("No")\n\n']
['Wrong Answer', 'Accepted']
['s080984795', 's427388539']
[20024.0, 20028.0]
[100.0, 72.0]
[470, 437]
p03639
u631277801
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['import sys\n\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nn = ni()\na = list(li())\n\nodd = 0\nml2 = 0\nml4 = 0\n\nfor ai in a:\n if ai % 2:\n odd += 1\n elif ai % 4:\n ml2 = 1\n else:\n ml4 += 1\n\nprint("Yes" if (odd + ml2) <= (ml4 + 1) else "No")', 'import sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nn = ni()\na = list(li())\n\nodd = 0\nml2 = 0\nml4 = 0\n\nfor ai in a:\n if ai % 2:\n odd += 1\n elif ai % 4:\n ml2 = 1\n else:\n ml4 += 1\n\nprint("Yes" if (odd + ml2) <= (ml4 + 1) else "No")']
['Runtime Error', 'Accepted']
['s502774439', 's503597629']
[3064.0, 14168.0]
[18.0, 62.0]
[639, 638]
p03639
u640922335
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["N=int(input())\nA=list(map(int,input().split()))\na=0\nb=0\nfor num in A:\n if num%2==1:\n a+=1\n elif num%4==0:\n b+=1\n\nif N==3:\n if a==3 or (a>=1 and b==0):\n print('No')\n else:\n print('Yes')\nelse:\n if a=<b:\n print('Yes')\n else:\n print('No')", "N=int(input())\nA=list(map(int,input().split()))\na=0\nb=0\nfor num in A:\n if num%2==1:\n a+=1\n elif num%4==0:\n b+=1\n\nif N%2==1:\n if a>b+1:\n print('No')\n else:\n print('Yes')\nelse:\n if a<=b:\n print('Yes')\n else:\n print('No')"]
['Runtime Error', 'Accepted']
['s783144384', 's064464440']
[9008.0, 20108.0]
[23.0, 65.0]
[294, 278]
p03639
u667024514
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['h,w=map(int,input().split())\nn=int(input())\nlis=list(map(int,input().split()))\nans=[]\ncnt=0\ns=""\nhh=0\nfor i in range(n):\n for j in range(lis[i]):\n if hh==0:\n s=s+str(i+1)+" "\n else:\n s=str(i+1)+" "+s\n cnt+=1\n if cnt==w:\n ans.append(s)\n s=""\n cnt=0\n hh=(hh+1)%2\nfor i in range(h):\n print(ans[i])\n', 'n = int(input())\nlis = list(map(int,input().split()))\nnu1 = 0\nnu2 = 0\nnu4 = 0\nfor nu in lis:\n if nu % 2 == 0:\n if nu % 4 == 0:\n nu4 += 1\n else:\n nu2 = 1\n else:\n nu1 += 1\nif nu4 >= nu1 + nu2:print("Yes")\nelse:print("No")', 'n = int(input())\nlis = list(map(int,input().split()))\nnu1 = 0\nnu2 = 0\nnu4 = 0\nfor nu in lis:\n if nu % 2 == 0:\n if nu % 4 == 0:\n nu4 += 1\n else:\n nu2 = 1\n else:\n nu1 += 1\nif nu4 + 1 >= nu1 + nu2:print("Yes")\nelse:print("No")']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s246051108', 's707519727', 's018898883']
[3064.0, 15020.0, 14252.0]
[18.0, 62.0, 62.0]
[339, 268, 272]
p03639
u671211357
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N=int(input())\nA=list(map(int,input().split()))\ncount_4=0\ncount_2=0\ncount_1=0\nfor i in A:\n if i%4==0:\n count_4+=1\n elif i%2==0:\n count_2+=1\n else:\n count_1+=1\nif count_2<2:\n if count_1+count_2<count_4:\n print("Yes")\n else:\n print("No")\nelse:\n if count_1<count_4:\n print("Yes")\n else:\n print("No")', 'N=int(input())\nA=list(map(int,input().split()))\ncount_4=0\ncount_2=0\ncount_1=0\nfor i in A:\n if i%4==0:\n count_4+=1\n elif i%2==0:\n count_2+=1\n else:\n count_1+=1\nif count_2<2:\n if count_1+count_2<=count_4:\n print("Yes")\n else:\n print("No")\nelse:\n if count_1<=count_4:\n print("Yes")\n else:\n print("No")', 'N=int(input())\nA=list(map(int,input().split()))\ncount_4=0\ncount_2=0\ncount_1=0\nfor i in A:\n if i%4==0:\n count_4+=1\n elif i%2==0:\n count_2+=1\n else:\n count_1+=1\nif count_2<2:\n if count_1+count_2-1<=count_4:\n print("Yes")\n else:\n print("No")\nelse:\n if count_1<=count_4:\n print("Yes")\n else:\n print("No")']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s713715112', 's974476627', 's098666288']
[15020.0, 14252.0, 14252.0]
[64.0, 63.0, 63.0]
[366, 368, 370]
p03639
u674588203
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nif N==1:\n if mod40==N:\n print("Yes")\n else:\n print("No")\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n else:\n print("No")\n\nif N%2==1:\n if oddcount<=2*mod40:\n print("Yes")\n else:\n print("No")\n\nelse:\n if oddcount+1<=2*mod40:\n print("Yes")\n else:\n print("No")\n', '\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nN=N-other\n\nif N==1:\n if mod40==N:\n print("Yes")\n else:\n print("No")\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n else:\n print("No")\n\nif (N-other)%2==1:\n if (N-other)//2 <= mod40:\n print("Yes")\n else:\n print("No")\n\nelse:\n if (N-other)//2 < mod40:\n print("Yes")\n else:\n print("No")\n', '\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nif N==1:\n if mod40==N:\n print("Yes")\n else:\n print("No")\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n else:\n print("No")\n\n\nif N%2==1:\n if N-((other//2)*2)//2 <= mod40:\n print("Yes")\n else:\n print("No")\n\nelse:\n print(np.array)', '\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nif N==1:\n if mod40==N:\n print("Yes")\n else:\n print("No")\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n else:\n print("No")\n\n\nif N%2==1:\n if (N-((other//2)*2))//2 <= mod40:\n print("Yes")\n else:\n print("No")\n\nelse:\n print(np.array)\n\n\n # if (N-other)//2 < mod40:\n # print("Yes")\n # else:\n # print("No")\n', '\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nif N==1:\n if mod40==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n\n\nif (N-((other//2)*2))//2 <= mod40:\n print("Yes")\n exit()\n else:\n print("No")\n exit()', ' \n # C - 4-adjacent\n\n N=int(input())\n alist=list(map(int,input().split()))\n\n oddcount=0\n mod40=0\n other=0\n\n for a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\n if N==1:\n if mod40==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n if N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n \n\n if N%2==1:\n if (N-((other//2)*2))//2 <= mod40:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n\n else:\n if other%2==1:\n if (N-other)//2<=mod40:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n else:\n if (N-other)//2<mod40:\n print("Yes")\n exit()\n else:\n print("No")\n exit', '\n# C - 4-adjacent\n\nN=int(input())\nalist=list(map(int,input().split()))\n\noddcount=0\nmod40=0\nother=0\n\nfor a in alist:\n if a%2==1:\n oddcount+=1\n elif a%4==0:\n mod40+=1\n else:\n other+=1\n\nif N==1:\n if mod40==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\nif N==2 or N==3:\n if mod40>0 or other==N:\n print("Yes")\n exit()\n else:\n print("No")\n exit()\n\nelse:\n if (N-((other//2)*2))//2 <= mod40:\n print("Yes")\n exit()\n else:\n print("No")\n exit()']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s127463463', 's278857804', 's484886189', 's838824896', 's846436619', 's919349634', 's353635563']
[20120.0, 20428.0, 20128.0, 20136.0, 8840.0, 8844.0, 19968.0]
[64.0, 66.0, 64.0, 65.0, 25.0, 28.0, 65.0]
[590, 614, 580, 673, 650, 1148, 639]
p03639
u676264453
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["import sys\n\nN = int(input())\nls = list(map(int, input().split()))\nk = len(ls)\np = [ i for i in ls if (i%4) == 0]\nj = [ i for i in ls if (i%4) != 0]\nr = [ i for i in j if (i%2) == 0]\n\nif(len(p) >= int(k/2)):\n print('Yes')\nelif (len(p) >= (len(j) - len(r))):\n print('Yes')\nelse:\n print('No')\n----", "import sys\n\nN = int(input())\nls = list(map(int, input().split()))\nk = len(ls)\np = [ i for i in ls if (i%4) == 0]\nj = [ i for i in ls if (i%4) != 0]\nr = [ i for i in j if (i%2) == 0]\n\nif(len(p) >= int(k/2)):\n print('Yes')\nelif (len(p) >= (len(j) - len(r))):\n print('Yes')\nelse:\n print('No')"]
['Runtime Error', 'Accepted']
['s885120613', 's380933490']
[3064.0, 14252.0]
[19.0, 65.0]
[303, 298]
p03639
u692632484
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N=int(input())\na=[int(i) for i in input().split()]\nnum4=0\nnum2=0\nnum1=0\nfor i in a:\n if i%4==0:\n num4+=1\n elif i%2==0:\n num2+=1\nnum1=N-num4-num2\n\nif num2>0:\n num1+=1\n\nif num1<=num4+1:\n print("Yes")\nelse:\n print("No") ~ ~ ', 'N=int(input())\na=[int(i) for i in input().split()]\nnum4=0\nnum2=0\nnum1=0\nfor i in a:\n if i%4==0:\n num4+=1\n elif i%2==0:\n num2+=1\nnum1=N-num4-num2\n\nif num2>0:\n num1+=1\n\nif num1<=num4+1:\n print("Yes")\nelse:\n print("No")']
['Runtime Error', 'Accepted']
['s384969802', 's748661050']
[3064.0, 14252.0]
[17.0, 67.0]
[468, 281]
p03639
u729133443
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n,a=open(0)\na=[int(i)%4for i in a.split()]\nf,g=a.count(0),a.count(2)\nprint('YNeos'[int(n)-f-g>f+(g==0)])", "n,a=open(0)\nc=[int(i)%4for i in a.split()].count\nf,g=c(0),c(2)\nprint('YNeos'[int(n)-f-g>f+(g==0)::2])"]
['Wrong Answer', 'Accepted']
['s518931366', 's553596136']
[11936.0, 11936.0]
[52.0, 54.0]
[104, 101]
p03639
u742729271
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
['N = int(input())\na = list(map(int, input().split()))\nc2=c4=0\n\nfor i in range(len(N)):\n if a[i]%4==0:\n c4+=1\n if a[i]%2==0:\n c2+=1\n\nnodd=N-c2\nc4=c4-c2\n\nif nodd<c4:\n print("Yes")\nelse:\n print("No")', 'N = int(input())\na = list(map(int, input().split()))\nc2=c4=0\n\nfor i in range(N):\n if a[i]%4==0:\n c4+=1\n if a[i]%2==0:\n c2+=1\n\nnodd=N-c2\nc2=c2-c4\nif c2>0:\n nodd+=1\nif c4>=nodd-1:\n print("Yes")\nelse:\n print("No")\n']
['Runtime Error', 'Accepted']
['s405068405', 's532477886']
[14252.0, 14252.0]
[41.0, 80.0]
[205, 222]
p03639
u802772880
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n=int(input())\na=list(map(int,input().split()))\nans='No'\na2=[i//2 for i in a if i%2==0]\na4=[i for i in a2 if i%2==0]\nla2=len(a2)\nla4=len(a4)\nif la2+la4>=n:\n ans='Yes'\nprint(ans)\nprint(a2)\nprint(a4)", "n=int(input())\na=list(map(int,input().split()))\nans='No'\na2=[i//2 for i in a if i%2==0]\na4=[i for i in a2 if i%2==0]\nla2=len(a2)\nla4=len(a4)\nif la2+la4>=n and la2>0:\n ans='Yes'\nelif la2==la4 and 2*la4+1>=n:\n ans='Yes'\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s837870253', 's861563149']
[17184.0, 14252.0]
[83.0, 63.0]
[200, 234]
p03639
u817328209
2,000
262,144
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
["n = int(input())\na = list(map(int, input().split()))\nodds = 0\nevens2 = 0\nevens4 = \nfor ai in a :\n if ai % 4 == 0 :\n evens4 += 1\n elif ai % 2 == 0 :\n evens2 += 1\n else :\n odds += 1\n\nif evens4 >= odds :\n print('Yes')\nelif odds - evens4 == 1 and evens2 == 0 :\n print('Yes')\nelse :\n print('No')", "n = int(input())\na = list(map(int, input().split()))\nodds = 0\nevens2 = 0\nevens4 = \nfor ai in a :\n if ai % 4 == 0 :\n evens4 += 1\n elif ai % 2 == 0 :\n evens2 += 1\n else :\n odds += 1\n\nif evens4 >= odds :\n print('Yes')\nelif odds - evens4 == 1 and evens2 == 0 :\n print('Yes')\nelse :\n print('No')", "n = int(input())\na = list(map(int, input().split()))\nodds = 0\nevens2 = 0\nevens4 = 0\nfor ai in a :\n if ai % 4 == 0 :\n evens4 += 1\n elif ai % 2 == 0 :\n evens2 += 1\n else :\n odds += 1\n\nif evens4 >= odds :\n print('Yes')\nelif odds - evens4 == 1 and evens2 == 0 :\n print('Yes')\nelse :\n print('No')"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s354376888', 's764451190', 's913094954']
[2940.0, 2940.0, 14252.0]
[17.0, 17.0, 63.0]
[329, 329, 330]