s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s522289971 | p04002 | u375616706 | 1548706029 | Python | Python (3.4.3) | py | Runtime Error | 3330 | 1693428 | 514 | H, W, N = map(int, input().split())
mat = [[0]*W for _ in range(H)]
for _ in range(N):
a, b = map(int, input().split())
mat[a-1][b-1] = 1
dp = [[0]*(W-2) for _ in range(H)]
ran = range(W)
for h in range(H):
for a, b, c in zip(ran, ran[1:], ran[2:]):
co = mat[h][a]+mat[h][b]+mat[h][c]
dp[h][a] = co
ans = [0]*10
for h in range(H-2):
for w in range(W-2):
tmp = 0
for i in range(3):
tmp += dp[h+i][w]
ans[tmp] += 1
for a in ans:
print(a)
|
s441477800 | p04002 | u375616706 | 1548704882 | Python | Python (3.4.3) | py | Runtime Error | 3326 | 1693684 | 653 | H, W, N = map(int, input().split())
mat = [[0]*W for _ in range(H)]
for _ in range(N):
a, b = map(int, input().split())
mat[a-1][b-1] = 1
dp = [[0]*W for _ in range(H)]
for h in range(H):
cnt = 0
if mat[h][0] == 1:
dp[h][0] = 1
for w in range(1, W):
if mat[h][w] == 1:
dp[h][w] += 1
dp[h][w] += dp[h][w-1]
ans = [0]*10
for i in range(10):
tmp = 0
for h in range(H-3):
for w in range(W-3):
s = 0
for k in range(3):
s += dp[h+k][w+2]-dp[h+k][w]
if s == i:
tmp += 1
ans[i] = tmp
for i in ans:
print(i)
|
s113961647 | p04002 | u375616706 | 1548704557 | Python | Python (3.4.3) | py | Runtime Error | 3330 | 1693556 | 653 | H, W, N = map(int, input().split())
mat = [[0]*W for _ in range(H)]
for _ in range(N):
a, b = map(int, input().split())
mat[a-1][b-1] = 1
dp = [[0]*W for _ in range(H)]
for h in range(H):
cnt = 0
if mat[h][0] == 1:
dp[h][0] = 1
for w in range(1, W):
if mat[h][w] == 1:
dp[h][w] += 1
dp[h][w] += dp[h][w-1]
ans = [0]*10
for i in range(10):
tmp = 0
for h in range(H-3):
for w in range(w-3):
s = 0
for k in range(3):
s += dp[h+k][w+2]-dp[h+k][w]
if s == i:
tmp += 1
ans[i] = tmp
for i in ans:
print(i)
|
s776409646 | p04002 | u024809932 | 1541257620 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 888 | #include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
int main(void){
long long h,w,n,d=1000000000,c[10]={0};
unordered_map<long long,int> m{};
cin>>h>>w>>n;
for(int i=0;i<n;i++){
long long a,b;
cin>>a>>b;
a--;
b--;
for(int j=-1;j<=1;j++){
for(int k=-1;k<=1;k++){
if(a+j>=0&&a+j<h&&b+k>=0&&b+k<w){
m[(a+j)*d+b+k]++;
//cout<<a+j<<","<<b+k<<":"<<m[(a+j)*d+b+k]<<endl;
}
}
}
}
for(auto x=m.begin();x!=m.end();x++){
long long a=(x->first)/d,b=(x->first)%d;
if(a>=1&&a<=h-2&&b>=1&&b<=w-2){
c[x->second]++;
c[0]++;
}
}
cout<<(h-2)*(w-2)-c[0]<<endl;
for(int i=1;i<=9;i++){
cout<<c[i]<<endl;
}
}
|
s403265982 | p04002 | u691493208 | 1525653761 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1211 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;
map<P, int> mp;
int dy[] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
int dx[] = {-2, -1, 0, -2, -1, 0, -2, -1, 0};
int ans[10];
signed main(){
int h, w, n, cnt = 0;
scanf("%lld%lld%lld", &h, &w, &n);
rep(i,n){
int x, y;
scanf("%lld%lld", &y, &x);
rep(j,9){
int yy = y+dy[j];
int xx = x+dx[j];
if(yy <= 0 or xx <= 0)continue;
if(yy+2 > h or xx+2 > w)continue;
mp[P(yy, xx)]++;
}
}
for(auto it = mp.begin();it != mp.end();it++){
ans[it->second]++;
cnt++;
}
ans[0] = (h-2)*(w-2)-cnt;
rep(i,10){
printf("%lld\n", ans[i]);
}
return 0;
}
|
s570824002 | p04002 | u435281580 | 1519355726 | Python | Python (3.4.3) | py | Runtime Error | 310 | 16624 | 878 | def snuke_coloring(h, w, poses):
counts = np.zeros(10, np.int64)
searched = {}
for pos in poses:
for y in range(max(1, pos[0] - 2), min(h - 2, pos[0]) + 1):
for x in range(max(1, pos[1] - 2), min(w - 2, pos[1]) + 1):
index = (y - 1) * w + (x - 1)
if index in searched: continue
searched[index] = True
count = 0
for target in poses:
if x <= target[1] and target[1] <= x + 2 and \
y <= target[0] and target[0] <= y + 2:
count += 1
counts[count] += 1
nonzero_count = int(np.sum(counts))
counts[0] = (h - 2) * (w - 2) - nonzero_count
print(counts)
h, w, n = map(int, input().split())
poses = [tuple(map(int, input().split())) for _ in range(n)]
snuke_coloring(h, w, poses) |
s190720751 | p04002 | u680619771 | 1473647110 | Python | Python (3.4.3) | py | Runtime Error | 40 | 3064 | 930 | import sys
grid = []
painted = []
height, width, n = sys.stdin.readline().strip().split()
height, width, n = int(height), int(width), int(n)
def checkGrid(x, y, grid):
count = 0
for col in range(x, x+3):
for row in range(y, y+3):
if grid[row][col] == 1:
count += 1
return count
# Build empty grid
for i in range(height):
painted.append([])
for j in range(width):
painted[i].append(0)
inp = sys.stdin.readline().strip()
while inp:
a, b = inp.split()
grid.append([int(a) - 1, int(b) - 1])
inp = sys.stdin.readline().strip()
# Build painted cells
for cell in grid:
painted[cell[0]][cell[1]] = 1
for i in range(0, 10):
count = 0
for col in range(width - 2):
for row in range(height - 2):
if checkGrid(col, row, painted) == i:
count += 1
print(count) |
s338119834 | p04003 | u401686269 | 1600981992 | Python | PyPy3 (7.3.0) | py | Runtime Error | 3332 | 862044 | 1101 | from collections import defaultdict
N,M=map(int,input().split())
if M == 0:
print(-1)
exit()
INF = 10**20
pqc = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
G = defaultdict(dict)
lines = [set() for _ in range(N)]
for p,q,c in pqc:
G[(p,c)][(q,c)] = G[(q,c)][(p,c)] = 0
lines[p].add(c)
lines[q].add(c)
for v in range(N):
if len(lines[v])>1:
tmp = list(lines[v])
for i in range(len(tmp)-1):
for j in range(i+1,len(tmp)):
G[(v,tmp[i])][(v,tmp[j])] = G[(v,tmp[j])][(v,tmp[i])] = 1
def dijkstra(start = 0):
from heapq import heappop, heappush
d = defaultdict(lambda:INF)
d[start] = 0
que = []
heappush(que, (0, start))
while que:
p = heappop(que)
v = p[1]
if d[v] < p[0]: continue
for u in G[v].keys():
if d[u] > d[v] + G[v][u]:
d[u] = d[v] + G[v][u]
heappush(que, (d[u], u))
return d
ans = INF
for c in lines[0]:
d = dijkstra((0,c))
ans = min(ans, min(d[(N-1,c2)] for c2 in lines[N-1]))
print(ans+1 if ans < INF else -1) |
s972527330 | p04003 | u401686269 | 1600981158 | Python | Python (3.8.2) | py | Runtime Error | 3324 | 544160 | 1101 | from collections import defaultdict
N,M=map(int,input().split())
if M == 0:
print(-1)
exit()
INF = 10**20
pqc = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(N)]
G = defaultdict(dict)
lines = [set() for _ in range(N)]
for p,q,c in pqc:
G[(p,c)][(q,c)] = G[(q,c)][(p,c)] = 0
lines[p].add(c)
lines[q].add(c)
for v in range(N):
if len(lines[v])>1:
tmp = list(lines[v])
for i in range(len(tmp)-1):
for j in range(i+1,len(tmp)):
G[(v,tmp[i])][(v,tmp[j])] = G[(v,tmp[j])][(v,tmp[i])] = 1
def dijkstra(start = 0):
from heapq import heappop, heappush
d = defaultdict(lambda:INF)
d[start] = 0
que = []
heappush(que, (0, start))
while que:
p = heappop(que)
v = p[1]
if d[v] < p[0]: continue
for u in G[v].keys():
if d[u] > d[v] + G[v][u]:
d[u] = d[v] + G[v][u]
heappush(que, (d[u], u))
return d
ans = INF
for c in lines[0]:
d = dijkstra((0,c))
ans = min(ans, min(d[(N-1,c2)] for c2 in lines[N-1]))
print(ans+1 if ans < INF else -1) |
s372568393 | p04003 | u183422236 | 1598275201 | Python | PyPy3 (7.3.0) | py | Runtime Error | 597 | 113020 | 660 | import collections
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
p, q, c = map(lambda x:int(x) - 1, input().split())
g[p].append((q, c))
g[q].append((p, c))
que = collections.deque()
que.append((0, c))
cost = [float("INF")] * n
cost[0] = 0
while que:
ps, pc = que.popleft()
for ns, nc in g[ps]:
if pc == nc and cost[ns] > cost[ps]:
cost[ns] = cost[ps]
que.appendleft((ns, nc))
elif pc != nc and cost[ns] > cost[ps] + 1:
cost[ns] = cost[ps] + 1
que.append((ns, nc))
if cost[n - 1] == float("INF"):
print(-1)
else:
print(cost[n - 1]) |
s213911564 | p04003 | u794173881 | 1593888534 | Python | PyPy3 (7.3.0) | py | Runtime Error | 3321 | 381964 | 1411 | import heapq
def dijkstra():
dp[sup_v][0] = 1
q = [(0, sup_v, 0)] # q = [(startからの距離, 現在地)]
while q:
d, v1, v2 = heapq.heappop(q)
if dp[v1][v2] < d:
continue
for nxt_v1, nxt_v2, cost in graph[v1][v2]:
if dp[v1][v2] + cost < dp[nxt_v1][nxt_v2]:
dp[nxt_v1][nxt_v2] = dp[v1][v2] + cost
heapq.heappush(q, (dp[nxt_v1][nxt_v2], nxt_v1, nxt_v2))
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
INF = 10 ** 18
sup_v = 10 ** 6
graph = {sup_v: {}}
dp = {sup_v: {}}
for a, b, c in info:
a -= 1
b -= 1
if c not in graph:
graph[c] = {}
dp[c] = {}
if a not in graph[c]:
graph[c][a] = []
graph[c][a].append((sup_v, a, 1))
dp[c][a] = INF
if b not in graph[c]:
graph[c][b] = []
graph[c][b].append((sup_v, b, 1))
dp[c][b] = INF
if a not in graph[sup_v]:
graph[sup_v][a] = []
dp[sup_v][a] = INF
if b not in graph[sup_v]:
graph[sup_v][b] = []
dp[sup_v][b] = INF
graph[c][a].append((c, b, 0))
graph[c][b].append((c, a, 0))
graph[sup_v][a].append((c, b, 0))
graph[sup_v][b].append((c, a, 0))
dijkstra()
ans = INF
for i in dp:
for j in dp[i]:
if j == n - 1:
ans = min(dp[i][j], ans)
print(ans) |
s222981535 | p04003 | u608088992 | 1592531910 | Python | PyPy3 (7.3.0) | py | Runtime Error | 90 | 74628 | 1895 | import heapq
import sys
from collections import defaultdict
input = sys.stdin.readline
N, M = map(int, input().split())
Rails = [[] for _ in range(N)]
def constant_factory(value): return lambda: value
def solve():
Costs = defaultdict(constant_factory(1000000000))
Visited = defaultdict(constant_factory(False))
for _ in range(M):
p, q, c = map(int, input().split())
Rails[p-1].append((q-1, c))
Rails[q-1].append((p-1, c))
Q = [(0, 0, -1)]
heapq.heapify(Q)
while Q:
currentCost, currentNode, currentCompany = heapq.heappop(Q)
if not Visited[(currentNode, currentCompany)]:
Visited[(currentNode, currentCompany)] = True
if currentCompany == -1:
for nextNode, nextCompany in Rails[currentNode]:
if not Visited[(nextNode, nextCompany)]:
if Costs[(nextNode, nextCompany)] > currentCost + 1:
Costs[(nextNode, nextCompany)] = currentCost + 1
heapq.heappush(Q, (currentCost + 1, nextNode, nextCompany))
else:
if not Visited[(currentNode, -1)]:
if Costs[(currentNode, -1)] > currentCost:
Costs[(currentNode, -1)] = currentCost
heapq.heappush(Q, (currentCost, currentNode, -1))
for nextNode, nextCompany in Rails[currentNode]:
if nextCompany == currentCompany and not Visited[(nextNode, nextCompany)]:
if Costs[(nextNode, nextCompany)] > currentCost:
Costs[(nextNode, nextCompany)] = currentCost
heapq.heappush(Q, (currentCost, nextNode, nextCompany))
minCost = Costs[(N-1, -1)]
print(minCost if minCost < 1000000000 else -1)
return 0
if __name__ == "__main__":
solve() |
s960582771 | p04003 | u754022296 | 1591596377 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1209 | 154624 | 678 | import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n, m = map(int, input().split())
G = defaultdict(set)
seen = set()
for _ in range(n):
p, q, c = map(int, input().split())
G[(p, c)].add(((q, c), 0))
G[(q, c)].add(((p, c), 0))
G[(p, c)].add(((p, -1), 0))
G[(q, c)].add(((q, -1), 0))
G[(p, -1)].add(((p, c), 1))
G[(q, -1)].add(((q, c), 1))
que = deque()
que.append(((1, -1), 0))
while que:
v, cnt = que.popleft()
if v in seen:
continue
if v == (n, -1):
print(cnt)
exit()
seen.add(v)
for nv, cost in G[v]:
if cost == 0:
que.appendleft((nv, cnt+cost))
else:
que.append((nv, cnt+cost))
print(-1) |
s221327608 | p04003 | u754022296 | 1591596316 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1107 | 154596 | 667 | import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n, m = map(int, input().split())
G = defaultdict(set)
seen = set()
for _ in range(n):
p, q, c = map(int, input().split())
G[(p, c)].add(((q, c), 0))
G[(q, c)].add(((p, c), 0))
G[(p, c)].add(((p, -1), 0))
G[(q, c)].add(((q, -1), 0))
G[(p, -1)].add(((p, c), 1))
G[(q, -1)].add(((q, c), 1))
que = deque()
que.append(((1, -1), 0))
while que:
v, cnt = que.popleft()
if v in seen:
continue
if v == (n, -1):
print(cnt)
break
seen.add(v)
for nv, cost in G[v]:
if cost == 0:
que.appendleft((nv, cnt+cost))
else:
que.append((nv, cnt+cost)) |
s531554204 | p04003 | u358254559 | 1587501176 | Python | PyPy3 (2.4.0) | py | Runtime Error | 179 | 38768 | 886 | input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop,heappushpop,heapify
n,m = map(int, input().split())
link = defaultdict(list)
chg=10**8
for _ in range(m):
p,q,c=map(int, input().split())
link[p].append([p+chg*c,1])
link[p+chg*c].append([p,1])
link[q+chg*c].append([p+chg*c,0])
link[p+chg*c].append([q+chg*c,0])
link[q+chg*c].append([q,1])
link[q].append([q+chg*c,1])
def dks(g,start):
INF=float('inf')
visited = set()
hq = []
heappush(hq, (0,start))
while hq:
shortest, i = heappop(hq)
if i in visited:
continue
visited.add(i)
for j, t in g[i]:
if j in visited:
continue
if j==n:
return (shortest+t)//2
heappush(hq, (shortest + t, j))
return -1
ans=dks(link,1)
print(ans) |
s840802680 | p04003 | u358254559 | 1587499653 | Python | PyPy3 (2.4.0) | py | Runtime Error | 183 | 38640 | 382 | import sys
input=sys.stdin.readline
n,m = map(int, input().split())
link = defaultdict(list)
for _ in range(m):
p,q,c=map(int, input().split())
p-=1
q-=1
c-=1
link[(p,-1)].append([(p,c),1])
link[(p,c)].append([(p,-1),1])
link[(p,c)].append([(q,c),0])
link[(q,c)].append([(p,c),0])
link[(q,-1)].append([(q,c),1])
link[(q,c)].append([(q,-1),1]) |
s188482754 | p04003 | u340781749 | 1581642555 | Python | Python (3.4.3) | py | Runtime Error | 1419 | 175880 | 1110 | import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visited.add((v, e))
if e == 0:
for c, us in links[v]:
for u in us:
if (u, c) in visited:
continue
q.append((d + 1, u, c))
else:
for u in links[v][e]:
if (u, e) in visited:
continue
q.appendleft((d, u, e))
if (v, 0) not in visited:
q.appendleft((d, v, 0))
return -1
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
p -= 1
q -= 1
links[p][c].add(q)
links[q][c].add(p)
print(bfs01(0, n - 1, links))
|
s096665058 | p04003 | u619819312 | 1578629970 | Python | Python (3.4.3) | py | Runtime Error | 3160 | 79152 | 435 | n,m=map(int,input().split())
s=[[]for i in range(n+1)]
for j in range(m):
p,q,c=map(int,input().split())
s[p].append([q,c])
s[q].append([p,c])
l=[0]*(n+1)
l[1]=1
d=[[1,0,0]]
while not l[-1]:
a,b,c=d.pop(0)
for i,j in s[a]:
if not l[i]:
if j==b:
l[i]=c
d.insert(0,[i,b,c])
else:
l[i]=c+1
d.append([i,j,c+1])
print(l[-1]) |
s447660829 | p04003 | u892251744 | 1570495264 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1245 | 99888 | 1229 | from collections import deque, defaultdict
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
p, q, c = map(int, input().split())
adj[p].append((q, c))
adj[q].append((p, c))
deq = deque()
cost = [10 ** 7] * (N+1)
seen = [0] * (N+1)
prev = defaultdict(list)
deq.append(1)
cost[1] = 0
seen[1] = 1
while deq:
v = deq.pop()
for uc in adj[v]:
u, c = uc
if c in prev[v]:
if cost[u] == cost[v]:
cost[u] = cost[v]
if seen[u] == 0:
deq.append(u)
seen[u] = 1
prev[u].append(c)
elif cost[u] > cost[v]:
cost[u] = cost[v]
if seen[u] == 0:
deq.append(u)
seen[u] = 1
prev[u] = [c]
else:
if cost[u] > cost[v] + 1:
cost[u] = cost[v] + 1
if seen[u] == 0:
deq.appendleft(u)
seen[u] = 1
prev[u].append(c)
elif cost[u] == cost[v] + 1:
prev[u].append(c)
print(cost[N]) if cost[N] < 10 ** 7 else print(-1)
x |
s796089193 | p04003 | u803848678 | 1563232721 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2563 | 218092 | 1466 | # https://juppy.hatenablog.com/entry/2019/04/10/ARC061_-_E_%E3%81%99%E3%81%AC%E3%81%91%E5%90%9B%E3%81%AE%E5%9C%B0%E4%B8%8B%E9%89%84%E6%97%85%E8%A1%8C_-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder
# 参考にさせていただきました。
from collections import deque, defaultdict
chg = 10**6
n, m = map(int, input().split())
edges = defaultdict(set)
visited = dict()
for i in range(m):
p, q, c = map(int, input().split())
edges[p+c*chg].add(q+c*chg)
edges[q+c*chg].add(p+c*chg)
edges[p].add(p+c*chg)
edges[q].add(q+c*chg)
edges[p+c*chg].add(p)
edges[q+c*chg].add(q)
visited[p] = False
visited[q] = False
visited[p+c*chg] = False
visited[q+c*chg] = False
ans = float("inf")
que = deque()
# now, dist
que.append((1, 0))
# 今求めるのはendの距離だけなので、dist配列はいらない
# さらに、距離は0/1なのでheapで辺を管理する必要もなく、0なら最短確定なので先に、1ならその時点での最長なので後ろにすれば良い
while que:
now, dist = que.popleft()
if visited[now]:
continue
visited[now] = True
if now == n:
ans = dist
break
for to in edges[now]:
# 駅→ホーム
if now < chg and to > chg:
que.append((to, dist+1))
else:
que.appendleft((to, dist))
if ans == float("inf"):
print(-1)
else:
print(ans) |
s743137348 | p04003 | u729133443 | 1556966817 | Python | PyPy3 (2.4.0) | py | Runtime Error | 3168 | 303136 | 989 | from collections import*
from heapq import*
def dijkstra(s):
d=[inf]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=set()
l=set()
f=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2 or b<2:f=True
x,y=a+-~n*c,b+-~n*c
if b==n:l|={y}
e[a].append((1,x))
e[b].append((1,y))
e[x].extend([(0,a),(0,y)])
e[y].extend([(0,b),(0,x)])
s|=set((a,b,x,y))
if not f:
print(-1)
exit()
d={i:v for v,i in enumerate(sorted(s))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf]) |
s651221053 | p04003 | u729133443 | 1556966207 | Python | PyPy3 (2.4.0) | py | Runtime Error | 3166 | 289436 | 995 | from collections import*
from heapq import*
def dijkstra(s):
d=[inf]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=[]
l=[]
f=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2 or b<2:f=True
x,y=a+-~n*c,b+-~n*c
if b==n:l.append(y)
e[a].append((1,x))
e[b].append((1,y))
e[x].extend([(0,a),(0,y)])
e[y].extend([(0,b),(0,x)])
s.extend([a,b,x,y])
if not f:
print(-1)
exit()
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf]) |
s235624518 | p04003 | u729133443 | 1556965875 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2818 | 278304 | 979 | from collections import*
from heapq import*
def dijkstra(s):
d=[inf]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=[]
l=[]
f=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2 or b<2:f=True
x,y=a+-~n*c,b+-~n*c
if b==n:l.append(y)
e[a].append((1,x))
e[b].append((1,y))
e[y].append((0,b))
e[x].append((0,y))
s.extend([a,b,x,y])
if not f:
print(-1)
exit()
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf]) |
s650050328 | p04003 | u729133443 | 1556965347 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2160 | 244268 | 951 | from collections import*
from heapq import*
def dijkstra(s):
d=[inf]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=[]
l=[]
f=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if a<2:f=True
x,y=a+-~n*c,b+-~n*c
if b==n:l.append(y)
e[a].append((1,x))
e[y].append((0,b))
e[x].append((0,y))
s.extend([a,b,x,y])
if not f:
print(-1)
exit()
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf]) |
s186239633 | p04003 | u729133443 | 1556964911 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2146 | 246888 | 931 | from collections import*
from heapq import*
def dijkstra(s):
d=[inf]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
if m<1:
print(-1)
exit()
e=defaultdict(list)
s=[]
l=[]
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if b==n:l.append(b+n*c)
e[a].append((1,a+n*c))
e[b+n*c].append((0,b))
e[a+n*c].append((0,b+n*c))
s.extend([a,b,a+n*c,b+n*c])
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf]) |
s040526336 | p04003 | u729133443 | 1556964641 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2314 | 251796 | 938 | from collections import*
from heapq import*
def dijkstra(s):
d=[float('inf')]*n
used=[True]*n
d[s]=0
used[s]=False
edgelist=[]
for e in edge[s]:
heappush(edgelist,e)
while len(edgelist):
minedge=heappop(edgelist)
if not used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=False
for e in edge[v]:
if used[e[1]]:
heappush(edgelist,(e[0]+d[v],e[1]))
return d
n,m,*t=map(int,open(0).read().split())
if m<1:
print(-1)
exit()
e=defaultdict(list)
s=[]
l=[]
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
if b<a:a,b=b,a
if b==n:l.append(b+n*c)
e[a].append((1,a+n*c))
e[b+n*c].append((0,b))
e[a+n*c].append((0,b+n*c))
s.extend([a,b,a+n*c,b+n*c])
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==float('inf')]) |
s698287477 | p04003 | u368780724 | 1553032287 | Python | PyPy3 (2.4.0) | py | Runtime Error | 173 | 38384 | 892 | import sys
from collections import deque
N, M = map(int, input().split())
Edge = [[] for _ in range(N+1)]
comp = set()
for _ in range(M):
p, q, c = map(int, sys.stdin.readline().split())
Edge[p].append((q, c))
Edge[q].append((p, c))
comp.add(c)
dist = {(1, 0): 0}
Q = deque()
Q.append((1, 0))
visited = set()
while Q:
vn, cp = Q.pop()
if (vn, cp) in visited:
continue
visited.add((vn, cp))
for vf, cf in Edge[vn]:
if (vf, cp) in visited:
continue
if cp == cf:
dist[(vf, cf)] = min(dist.get((vf, cf), 10**9), dist.get((vn, cp), 10**9))
Q.append((vf, cf))
else:
dist[(vf, cf)] = min(dist.get((vf, cf), 10**9), 1 + dist.get((vn, cp), 10**9))
Q.appendleft((vf, cf))
L = [dist.get((N, c), 10**9) for c in comp]
if not L or min(L) == 10**9:
print(-1)
else:
print(min(L)) |
s446321557 | p04003 | u368780724 | 1553031649 | Python | Python (3.4.3) | py | Runtime Error | 3169 | 204376 | 820 | import sys
from collections import deque
N, M = map(int, input().split())
Edge = [[] for _ in range(N+1)]
comp = set()
for _ in range(M):
p, q, c = map(int, sys.stdin.readline().split())
Edge[p].append((q, c))
Edge[q].append((p, c))
comp.add(c)
dist = {(1, 0): 0}
Q = deque()
Q.append((1, 0))
visited = set()
while Q:
vn, cp = Q.pop()
if (vn, cp) in visited:
continue
visited.add((vn, cp))
for vf, cf in Edge[vn]:
if cp == cf:
dist[(vf, cf)] = min(dist.get((vf, cf), float('inf')), dist.get((vn, cp), float('inf')))
Q.append((vf, cf))
else:
dist[(vf, cf)] = min(dist.get((vf, cf), float('inf')), 1 + dist.get((vn, cp), float('inf')))
Q.appendleft((vf, cf))
print(min([dist.get((N, c), float('inf')) for c in comp])) |
s047606489 | p04003 | u368780724 | 1553031616 | Python | PyPy3 (2.4.0) | py | Runtime Error | 3171 | 240380 | 820 | import sys
from collections import deque
N, M = map(int, input().split())
Edge = [[] for _ in range(N+1)]
comp = set()
for _ in range(M):
p, q, c = map(int, sys.stdin.readline().split())
Edge[p].append((q, c))
Edge[q].append((p, c))
comp.add(c)
dist = {(1, 0): 0}
Q = deque()
Q.append((1, 0))
visited = set()
while Q:
vn, cp = Q.pop()
if (vn, cp) in visited:
continue
visited.add((vn, cp))
for vf, cf in Edge[vn]:
if cp == cf:
dist[(vf, cf)] = min(dist.get((vf, cf), float('inf')), dist.get((vn, cp), float('inf')))
Q.append((vf, cf))
else:
dist[(vf, cf)] = min(dist.get((vf, cf), float('inf')), 1 + dist.get((vn, cp), float('inf')))
Q.appendleft((vf, cf))
print(min([dist.get((N, c), float('inf')) for c in comp])) |
s242660882 | p04003 | u631277801 | 1550278944 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2485 | 259124 | 2350 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from heapq import heappush, heappop
def dijkstra(graph: list, start, INF, num2node, destination) -> int:
n = len(graph)
dist = [INF]*n
visited = [False]*n
dist[start] = 0
que = [(dist[start], start)]
while que:
cost, cur = heappop(que)
if visited[cur]:
continue
if num2node[cur][0] == destination:
return cost
visited[cur] = True
for nextnode, edgecost in graph[cur]:
nextcost = cost + edgecost
if nextcost < dist[nextnode]:
dist[nextnode] = nextcost
heappush(que, (nextcost, nextnode))
return INF
def get_nodenum(station, company, keyset, node2num):
if (station, company) not in keyset:
keyset.add((station, company))
keyslen = len(keyset)-1
node2num.update({(station, company): keyslen})
return keyslen
else:
return node2num[(station, company)]
n,m = li()
graph = [[] for _ in [0]*(5*(10**5))]
node2num = {}
num2node = {}
keyset = set()
for _ in range(m):
p,q,c = li()
# ノードの登録
pc_nodenum = get_nodenum(p,c,keyset,node2num)
qc_nodenum = get_nodenum(q,c,keyset,node2num)
pz_nodenum = get_nodenum(p,0,keyset,node2num)
qz_nodenum = get_nodenum(q,0,keyset,node2num)
# 隣接リストの更新
graph[pc_nodenum].append((qc_nodenum, 0))
graph[qc_nodenum].append((pc_nodenum, 0))
graph[pc_nodenum].append((pz_nodenum, 0))
graph[qc_nodenum].append((qz_nodenum, 0))
graph[pz_nodenum].append((pc_nodenum, 1))
graph[qz_nodenum].append((qc_nodenum, 1))
num2node = {ni: (stati, compi) for (stati, compi), ni in node2num.items()}
INF = 1<<62
start = get_nodenum(1, 0, keyset, node2num)
ans = dijkstra(graph, start, INF, num2node, n)
print(-1 if ans == INF else ans) |
s479356914 | p04003 | u631277801 | 1550278147 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2467 | 185772 | 2392 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from heapq import heappush, heappop
def dijkstra(graph: list, start, INF=float('inf')) -> list:
n = len(graph)
dist = [INF]*n
visited = [False]*n
dist[start] = 0
que = [(dist[start], start)]
while que:
cost, cur = heappop(que)
if visited[cur]:
continue
visited[cur] = True
for nextnode, edgecost in graph[cur]:
nextcost = cost + edgecost
if nextcost < dist[nextnode]:
dist[nextnode] = nextcost
heappush(que, (nextcost, nextnode))
return dist
def get_nodenum(station, company, keyset, node2num):
if (station, company) not in keyset:
keyset.add((station, company))
keyslen = len(keyset)-1
node2num.update({(station, company): keyslen})
return keyslen
else:
return node2num[(station, company)]
n,m = li()
graph = [[] for _ in range(3*(10**5))]
node2num = {}
num2node = {}
keyset = set()
start = -1
for _ in range(m):
p,q,c = li()
# ノードの登録
pc_nodenum = get_nodenum(p,c,keyset,node2num)
qc_nodenum = get_nodenum(q,c,keyset,node2num)
pz_nodenum = get_nodenum(p,0,keyset,node2num)
qz_nodenum = get_nodenum(q,0,keyset,node2num)
# 隣接リストの更新
graph[pc_nodenum].append((qc_nodenum, 0))
graph[qc_nodenum].append((pc_nodenum, 0))
graph[pc_nodenum].append((pz_nodenum, 0))
graph[qc_nodenum].append((qz_nodenum, 0))
graph[pz_nodenum].append((pc_nodenum, 1))
graph[qz_nodenum].append((qc_nodenum, 1))
num2node = {ni: (stati, compi) for (stati, compi), ni in node2num.items()}
INF = 1<<62
ans = INF
start = get_nodenum(1, 0, keyset, node2num)
dist = dijkstra(graph, start, INF)
for nodei in range(len(keyset)):
if num2node[nodei][0] == n:
ans = min(ans, dist[nodei])
print(-1 if ans == INF else ans)
|
s063981454 | p04003 | u631277801 | 1550277776 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2070 | 163056 | 2584 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from heapq import heappush, heappop
def dijkstra(graph: list, start, INF=float('inf')) -> list:
n = len(graph)
dist = [INF]*n
visited = [False]*n
dist[start] = 1
que = [(dist[start], start)]
while que:
cost, cur = heappop(que)
if visited[cur]:
continue
visited[cur] = True
for nextnode, edgecost in graph[cur]:
nextcost = cost + edgecost
if nextcost < dist[nextnode]:
dist[nextnode] = nextcost
heappush(que, (nextcost, nextnode))
return dist
def get_nodenum(station, company, keyset, node2num):
if (station, company) not in keyset:
keyset.add((station, company))
keyslen = len(keyset)-1
node2num.update({(station, company): keyslen})
return keyslen
else:
return node2num[(station, company)]
n,m = li()
graph = [[] for _ in range(2*(10**5))]
node2num = {}
num2node = {}
keyset = set()
start = -1
for _ in range(m):
p,q,c = li()
# pかqが1ならスタートに設定
# ノードの登録
pc_nodenum = get_nodenum(p,c,keyset,node2num)
qc_nodenum = get_nodenum(q,c,keyset,node2num)
pz_nodenum = get_nodenum(p,0,keyset,node2num)
qz_nodenum = get_nodenum(q,0,keyset,node2num)
# pかqが1ならスタートに設定
if p == 1:
start = pc_nodenum
elif q == 1:
start = qc_nodenum
# 隣接リストの更新
graph[pc_nodenum].append((qc_nodenum, 0))
graph[qc_nodenum].append((pc_nodenum, 0))
graph[pc_nodenum].append((pz_nodenum, 0))
graph[qc_nodenum].append((qz_nodenum, 0))
graph[pz_nodenum].append((pc_nodenum, 1))
graph[qz_nodenum].append((qc_nodenum, 1))
num2node = {ni: (stati, compi) for (stati, compi), ni in node2num.items()}
INF = 1<<62
ans = INF
if start == -1:
print(-1)
else:
dist = dijkstra(graph, start, INF)
for nodei in range(len(keyset)):
if num2node[nodei][0] == n:
ans = min(ans, dist[nodei])
print(-1 if ans == INF else ans) |
s911821410 | p04003 | u236127431 | 1545250339 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2204 | 232564 | 808 | from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
print(-1)
exit()
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[a+(c<<30)].add(b+(c<<30))
G[b+(c<<30)].add(a+(c<<30))
G[a].add(a+(c<<30))
G[b].add(b+(c<<30))
G[a+(c<<30)].add(a)
G[b+(c<<30)].add(b)
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
stack=deque([(x,0)])
while stack:
s,m=stack.popleft()
if s==N:
return m
if d[s]>m:
d[s]=m
if s>=(1<<30):
for i in G[s]:
if d[i]>10**30:
stack.appendleft((i,m))
else:
for i in G[s]:
if d[i]>10**30:
stack.append((i,m+1))
return -1
print(BFS(1))
|
s723047080 | p04003 | u236127431 | 1545250098 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2065 | 232564 | 779 | from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
print(-1)
exit()
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[a+(c<<30)].add(b+(c<<30))
G[b+(c<<30)].add(a+(c<<30))
G[a].add(a+(c<<30))
G[b].add(b+(c<<30))
G[a+(c<<30)].add(a)
G[b+(c<<30)].add(b)
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
stack=deque([(x,0)])
while stack:
s,m=stack.popleft()
if s==N:
return m
if d[s]>m:
d[s]=m
if s>=(1<<30):
for i in G[s]:
if d[i]>10**30:
stack.appendleft((i,m))
else:
for i in G[s]:
if d[i]>10**30:
stack.append((i,m+1))
return -1
print(BFS(1))
|
s479146398 | p04003 | u236127431 | 1545249539 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1979 | 216064 | 761 | from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
print(-1)
exit()
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[a+c<<30].add(b+c<<30)
G[b+c<<30].add(a+c<<30)
G[a].add(a+c<<30)
G[b].add(b+c<<30)
G[a+c<<30].add(a)
G[b+c<<30].add(b)
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
stack=deque([(x,0)])
while stack:
s,m=stack.popleft()
if s==N:
return m
if d[s]>m:
d[s]=m
if s>=(1<<30):
for i in G[s]:
if d[i]>10**7:
stack.appendleft((i,m))
else:
for i in G[s]:
if d[i]>10**7:
stack.append((i,m+1))
return -1
print(BFS(1))
|
s753061269 | p04003 | u236127431 | 1545245466 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2774 | 292460 | 829 | from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[(a-1,c-1)].add((b-1,c-1))
G[(b-1,c-1)].add((a-1,c-1))
G[(a-1,-1)].add((a-1,c-1))
G[(b-1,-1)].add((b-1,c-1))
G[(a-1,c-1)].add((a-1,-1))
G[(b-1,c-1)].add((b-1,-1))
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
d[x]=0
stack=deque([(x,-1,0)])
while stack:
a,c,m=stack.popleft()
if a==N-1 and c==-1:
return m
if d[(a,c)]>m:
d[(a,c)]=m
if c>=0:
for i in G[(a,c)]:
if d[i]>10**30:
stack.appendleft((i[0],i[1],m))
else:
for i in G[(a,c)]:
if d[i]>10**30:
stack.append((i[0],i[1],m+1))
return -1
print(BFS(0))
|
s443834586 | p04003 | u236127431 | 1545240536 | Python | PyPy3 (2.4.0) | py | Runtime Error | 3171 | 287852 | 806 | from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[(a-1,c-1)].add((b-1,c-1))
G[(b-1,c-1)].add((a-1,c-1))
G[(a-1,-1)].add((a-1,c-1))
G[(b-1,-1)].add((b-1,c-1))
G[(a-1,c-1)].add((a-1,-1))
G[(b-1,c-1)].add((b-1,-1))
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
d[x]=0
stack=deque([(x,-1,0)])
while stack:
a,c,m=stack.popleft()
if a==N-1 and c==-1:
return m
d[(a,c)]=min(d[(a,c)],m)
if c>=0:
for i in G[(a,c)]:
if d[i]>10**30:
stack.appendleft((i[0],i[1],m))
else:
for i in G[(a,c)]:
if d[i]>10**30:
stack.append((i[0],i[1],m+1))
return -1
print(BFS(0))
|
s858940406 | p04003 | u075012704 | 1535465421 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2834 | 286504 | 2166 | from collections import defaultdict
import heapq
N, M = map(int, input().split())
D = {}
Edges = []
Edge_dict = {}
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * n
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same(self, x, y):
return self.find(x) == self.find(y)
# すべての頂点に対して親を検索する
def all_find(self):
for n in range(len(self.par)):
self.find(n)
UF = UnionFind(M)
for i in range(M):
p, q, c = map(int, input().split())
p, q = p-1, q-1
Edges.append((p, q, c))
if (p, c) in D:
UF.union(D[p, c], i)
D[p, c] = i
Edge_dict.setdefault(p, set()).add(c)
if (q, c) in D:
UF.union(D[q, c], i)
D[q, c] = i
Edge_dict.setdefault(q, set()).add(c)
UF.all_find()
Firm_Node = {}
for i in range(M):
p, q, c = Edges[i]
Firm_Node.setdefault(UF.par[i], set()).add(p)
Firm_Node.setdefault(UF.par[i], set()).add(q)
G = {}
for firm, node in Firm_Node.items():
for n in node:
G.setdefault(n, []).append(firm + N)
G.setdefault(firm + N, []).append(n)
def dijkstra(x):
d = defaultdict(float)
for key in G.keys():
d[key] = float('inf')
d[x] = 0
visited = {x}
# d, u
hq = [(0, x)]
while hq:
u = heapq.heappop(hq)[1]
visited.add(u)
for node in G[u]:
if (node not in visited) and d[node] > d[u] + 1:
d[node] = d[u] + 1
heapq.heappush(hq, (d[u]+1, node))
return d
dist = dijkstra(0)
print(dist[N-1] // 2 if dist[N-1] not in [0, float('inf')] else -1) |
s826861239 | p04003 | u180908266 | 1529881376 | Python | Python (3.4.3) | py | Runtime Error | 2463 | 213896 | 1566 | from collections import deque
N, M = map(int, input().split())
if M == 0:
print(-1)
exit()
F_C_of_S = [{} for i in range(N)]
# Companies of Station
C_of_S = {}
# def Union-find
parent = {i:i for i in range(M)}
def root(x):
if x == parent[x]:
return x
parent[x] = y = root(parent[x])
return y
def unite(x, y):
px = root(x); py = root(y);
if px < py:
parent[py] = px
else:
parent[px] = py
# Union-find
pqcs = []
#stations of company
S_of_C = {}
for i in range(M):
p, q, c = map(int, input().split())
p -= 1; q -= 1;
pqcs += [(p, q, c)]
if not 10**6+c in parent:
parent[10**6+c] = i
else:
unite(10**6+c, i)
C_of_S.setdefault(p, set()).add(root(i))
C_of_S.setdefault(q, set()).add(root(i))
c_set = S_of_C.setdefault(root(i), set())
c_set.add(p)
c_set.add(q)
Q = deque([(0, 0, 0)])
# cost to go to the station from station_0
dist = [float('inf')] * N
dist[0] = 0
# cost to get on the line
line_dist = [float('inf')] * M
while Q:
cost, v, flag = Q.popleft()
if not (flag): # (flag == 0) then line_dist_update
# v is station
for l in C_of_S[v]:
if (cost < line_dist[l]):
line_dist[l] = cost
Q.appendleft((cost, l, 1))
else: # (flag == 1) then dist_update
# v is company
for s in S_of_C[v]:
if (cost + 1 < dist[s]):
dist[s] = cost + 1
Q.append((cost + 1, s, 0))
print(dist[N - 1] if dist[N - 1] < float('inf') else -1) |
s861248931 | p04003 | u180908266 | 1529859607 | Python | Python (3.4.3) | py | Runtime Error | 2554 | 186312 | 1802 | from collections import deque
N, M = map(int, input().split())
F_C_of_S = [{} for i in range(N)]
#Companies of Station
C_of_S = {}
#def Union-find
parent = [-1]*M
def root(x):
if (parent[x] < 0): return x
else:
parent[x] = y = root(parent[x])
return y
def unite(x, y):
px = root(x)
py = root(y)
if (px == py): return False
"""
if (parent[px] > parent[py]):
px = root(y)
py = root(x)
parent[px] += parent[py]
parent[py] = px
"""
parent[py] += parent[px]
parent[px] = px
return True
#Union-find
pqcs = []
#stations of company
S_of_C = {}
for i in range(M):
p, q, c = map(int, input().split())
p -= 1; q -= 1;
pqcs += [(p, q, c)]
#The first
if not c in F_C_of_S[p]:
#Numbering in order of appearance
F_C_of_S[p][c] = i
#else
else:
unite(F_C_of_S[p][c], i)
#set a line that can ride from the station
C_of_S.setdefault(p, set()).add(c)
if not (c in F_C_of_S[q]):
F_C_of_S[q][c] = i
else:
unite(F_C_of_S[q][c], i)
C_of_S.setdefault(q, set()).add(c)
c_set = S_of_C.setdefault(root(i), set())
c_set.add(p)
c_set.add(q)
#stations of company
#S_of_C = {}
#for i in range(M):
#p, q, c = pqcs[i]
#c_set = S_of_C.setdefault(root(i), set())
#c_set.add(p)
#c_set.add(q)
Q = deque([(0, 0, 0)])
#cost to go to the station from station_0
dist = [float('inf')]*N
dist[0] = 0
#cost to get on the line
gdist = [float('inf')]*M
while Q:
cost, v, flag = Q.popleft()
if not (flag):#(flag == 0) then gdist_update
#v is station
for l in F_C_of_S[v].values():
l = root(l)
if (cost < gdist[l]):
gdist[l] = cost
Q.appendleft((cost, l, 1))
else:#(flag == 1) then dist_update
#v is company
for s in S_of_C[v]:
if (cost+1 < dist[s]):
dist[s] = cost+1
Q.append((cost+1, s, 0))
print(dist[N - 1] if dist[N - 1] < float('inf') else -1) |
s569342838 | p04003 | u180908266 | 1529803596 | Python | Python (3.4.3) | py | Runtime Error | 1965 | 125600 | 1753 | from collections import deque
N, M = map(int, input().split())
F_C_of_S = [{} for i in range(N)]
#Companies of Station
C_of_S = {}
#def Union-find
parent = [-1]*M
def root(x):
if (parent[x] < 0): return x
else:
parent[x] = y = root(parent[x])
return y
def unite(x, y):
px = root(x)
py = root(y)
if (px == py): return False
if (parent[px] > parent[py]):
px = root(y)
py = root(x)
parent[px] += parent[py]
parent[py] = px
return True
#Union-find
pqcs = []
for i in range(M):
p, q, c = map(int, input().split())
p -= 1; q -= 1;
pqcs += [(p, q, c)]
#The first
if not c in F_C_of_S[p]:
#Numbering in order of appearance
F_C_of_S[p][c] = i
#else
else:
unite(F_C_of_S[p][c], i)
#set a line that can ride from the station
C_of_S.setdefault(p, set()).add(c)
if not (c in F_C_of_S[q]):
F_C_of_S[q][c] = i
else:
unite(F_C_of_S[q][c], i)
C_of_S.setdefault(q, set()).add(c)
#stations of company
S_of_C = {}
c_set = S_of_C.setdefault(root(i), set())
c_set.add(p)
c_set.add(q)
"""
#stations of company
S_of_C = {}
for i in range(M):
p, q, c = pqcs[i]
c_set = S_of_C.setdefault(root(i), set())
c_set.add(p)
c_set.add(q)
"""
Q = deque([(0, 0, 0)])
#cost to go to the station from station_0
dist = [float('inf')]*N
dist[0] = 0
#cost to get on the line
gdist = [float('inf')]*M
while Q:
cost, v, flag = Q.popleft()
if not (flag):#(flag == 0) then gdist_update
#v is station
for l in F_C_of_S[v].values():
l = root(l)
if (cost < gdist[l]):
gdist[l] = cost
Q.appendleft((cost, l, 1))
else:#(flag == 1) then dist_update
#v is company
for s in S_of_C[v]:
if (cost+1 < dist[s]):
dist[s] = cost+1
Q.append((cost+1, s, 0))
print(dist[N - 1] if dist[N - 1] < float('inf') else -1) |
s293986699 | p04003 | u180908266 | 1529717342 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 692 | from heapq import heappop, heappush
N,M = map(int, input().split())
edges = [[] for _ in range(N)]
cs = set{}
for i in range(M):
p,q,c = map(int, input().split())
cs += c
edges[p-1] += [[q-1, c]]
edges[q-1] += [[p-1, c]]
c_num = len(cs)
distance = [[float('inf')]*(c_num+1) for _ in range(N)]
distance[0][0] = 0
min_distance = [float('inf')]*N
min_distance[0] = 0
Q = [[0, 0]]
while Q:
s_now,c_now = heappop(Q)
for t, c in edges[s_now]:
if min_distance[t] > distance[s_now][c_now] + (c_now != c):
distance[t][c] = distance[s_now][c_now] + (c_now != c)
min_distance[t] = distance[t][c]
heappush(Q, [t, c])
print(min_distance[N-1] if min_distance[N-1] != float('inf') else -1) |
s579180862 | p04003 | u180908266 | 1529716680 | Python | Python (3.4.3) | py | Runtime Error | 3699 | 1615072 | 757 | from collections import deque
N,M = map(int, input().split())
edges = [[] for _ in range(N)]
c_max = 0
for i in range(M):
p,q,c = map(int, input().split())
c_max = max(c, c_max)
edges[p-1] += [[q-1, c]]
edges[q-1] += [[p-1, c]]
distance = [[float('inf')]*(c_max+1) for _ in range(N)]
distance[0][0] = 0
min_distance = [float('inf')]*N
min_distance[0] = 0
Q = deque([[0,0]])
flag = False
while Q:
s_now,c_now = Q.popleft()
for t, c in edges[s_now]:
if min_distance[t] > distance[s_now][c_now] + (c_now != c):
distance[t][c] = distance[s_now][c_now] + (c_now != c)
min_distance[t] = distance[t][c]
if c_now == c:
Q.appendleft([t, c])
continue
Q.append([t, c])
print(min_distance[N-1] if min_distance[N-1] != float('inf') else -1) |
s277314546 | p04003 | u180908266 | 1529716456 | Python | Python (3.4.3) | py | Runtime Error | 3284 | 1615080 | 679 | from collections import deque
N,M = map(int, input().split())
edges = [[] for _ in range(N)]
c_max = 0
for i in range(M):
p,q,c = map(int, input().split())
c_max = max(c, c_max)
edges[p-1] += [[q-1, c]]
edges[q-1] += [[p-1, c]]
distance = [[float('inf')]*(c_max+1) for _ in range(N)]
distance[0][0] = 0
Q = deque([[0,0]])
flag = False
while Q:
s_now,c_now = Q.popleft()
for t, c in edges[s_now]:
t_dist = min(distance[t])
if t_dist > distance[s_now][c_now] + (c_now != c):
distance[t][c] = distance[s_now][c_now] + (c_now != c)
if c_now == c:
Q.appendleft([t, c])
continue
Q.append([t, c])
d = min(distance[N-1])
print(d if d != float('inf') else -1) |
s591339347 | p04003 | u180908266 | 1529716418 | Python | Python (3.4.3) | py | Runtime Error | 3380 | 1873872 | 675 | from collections import deque
N,M = map(int, input().split())
edges = [[] for _ in range(N)]
c_max = 0
for i in range(M):
p,q,c = map(int, input().split())
c_max = max(c, c_max)
edges[p-1] += [[q-1, c]]
edges[q-1] += [[p-1, c]]
distance = [[float('inf')]*(c+1) for _ in range(N)]
distance[0][0] = 0
Q = deque([[0,0]])
flag = False
while Q:
s_now,c_now = Q.popleft()
for t, c in edges[s_now]:
t_dist = min(distance[t])
if t_dist > distance[s_now][c_now] + (c_now != c):
distance[t][c] = distance[s_now][c_now] + (c_now != c)
if c_now == c:
Q.appendleft([t, c])
continue
Q.append([t, c])
d = min(distance[N-1])
print(d if d != float('inf') else -1) |
s435197331 | p04003 | u180908266 | 1529700215 | Python | Python (3.4.3) | py | Runtime Error | 3170 | 289676 | 1157 | from collections import deque
N,M = map(int, input().split())
if M == 0:
print(-1)
exit()
Q = {0:deque([1])}
distance = {1:0}
#辺へ重み付け
edges = {}
for _ in range(M):
p,q,c = map(int, input().split())
edge = {}
edge[c*10**6+q] = 0
edge[p] = 0
edges.setdefault(c*10**6+p, {})
edges[c*10**6+p].update(edge)
edge = {}
edge[c*10**6+p] = 0
edge[q] = 0
edges.setdefault(c*10**6+q, {})
edges[c*10**6+q].update(edge)
edge = {}
edge[c*10**6+p] = 1
edges.setdefault(p, {})
edges[p].update(edge)
edge = {}
edge[c*10**6+q] = 1
edges.setdefault(q, {})
edges[q].update(edge)
flag = False
while 1:
for i in range(len(Q)):
if not (Q[i]):
continue
flag = True
target_min_ind = Q[i].popleft()
target_node = edges[target_min_ind]
break
if not (flag):
break
for key, value in target_node.items():
distance.setdefault(key, float('inf'))
dist = distance[target_min_ind] + value
if distance[key] > dist:
distance[key] = dist
Q.setdefault(dist, deque())
Q[dist].append(key)
if key == N:
flag = False
if not (flag):
break
print(distance[N] if distance[N] != float('inf') else -1) |
s137441303 | p04003 | u180908266 | 1529692450 | Python | Python (3.4.3) | py | Runtime Error | 3170 | 267120 | 1175 | from collections import deque
N,M = map(int, input().split())
if M == 0:
print(-1)
exit()
Q = {0:deque([1])}
distance = {1:0}
#辺へ重み付け
edges = {}
for p,q,c in (list(map(int, input().split())) for _ in range(M)):
edge = {}
edge[c*10**6+q] = 0
edge[p] = 0
edges.setdefault(c*10**6+p, {})
edges[c*10**6+p].update(edge)
edge = {}
edge[c*10**6+p] = 0
edge[q] = 0
edges.setdefault(c*10**6+q, {})
edges[c*10**6+q].update(edge)
edge = {}
edge[c*10**6+p] = 1
edges.setdefault(p, {})
edges[p].update(edge)
edge = {}
edge[c*10**6+q] = 1
edges.setdefault(q, {})
edges[q].update(edge)
flag = False
while 1:
for i in range(len(Q)):
if not (Q[i]):
continue
flag = True
target_min_ind = Q[i].popleft()
target_node = edges[target_min_ind]
break
if not (flag):
break
for key, value in target_node.items():
distance.setdefault(key, float('inf'))
dist = distance[target_min_ind] + value
if distance[key] > dist:
distance[key] = dist
Q.setdefault(dist, deque())
Q[dist].append(key)
if key == N:
flag = False
if not (flag):
break
print(distance[N] if distance[N] != float('inf') else -1) |
s183394629 | p04003 | u180908266 | 1529556723 | Python | Python (3.4.3) | py | Runtime Error | 3614 | 2002640 | 1456 | N,M = map(int, input().split())
if M == 0:
print(-1)
exit()
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0~N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
edges[3*c+(p-1)][3*c+(q-1)] = 0
edges[3*c+(q-1)][3*c+(p-1)] = 0
edges[p-1][3*c+(p-1)] = 1
edges[q-1][3*c+(q-1)] = 1
edges[3*c+(p-1)][p-1] = 0
edges[3*c+(q-1)][q-1] = 0
while (distance[N-1] == float('inf')):
temp_min_dist = float('inf')
for unsearched_ind in unsearached_nodes:
if temp_min_dist > distance[unsearched_ind]:
temp_min_dist = distance[unsearched_ind]
target_min_ind = unsearched_ind
if temp_min_dist == float('inf'):
break
unsearached_nodes.remove(target_min_ind)
target_node = edges[target_min_ind]
flag = False
for index, rota_dist in enumerate(target_node):
if rota_dist != float('inf'):
if distance[index] > distance[target_min_ind] + rota_dist:
distance[index] = distance[target_min_ind] + rota_dist
#opt_nodes[index] = target_min_ind
print(distance[N-1] if distance[N-1] != float('inf') else -1) |
s315008567 | p04003 | u180908266 | 1529556427 | Python | Python (3.4.3) | py | Runtime Error | 5656 | 2002640 | 1404 | N,M = map(int, input().split())
if M == 0:
print(-1)
exit()
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0~N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
edges[3*c+(p-1)][3*c+(q-1)] = 0
edges[3*c+(q-1)][3*c+(p-1)] = 0
edges[p-1][3*c+(p-1)] = 1
edges[q-1][3*c+(q-1)] = 1
edges[3*c+(p-1)][p-1] = 0
edges[3*c+(q-1)][q-1] = 0
while (distance[N-1] == float('inf')):
temp_min_dist = float('inf')
for unsearched_ind in unsearached_nodes:
if temp_min_dist > distance[unsearched_ind]:
temp_min_dist = distance[unsearched_ind]
target_min_ind = unsearched_ind
unsearached_nodes.remove(target_min_ind)
target_node = edges[target_min_ind]
flag = False
for index, rota_dist in enumerate(target_node):
if rota_dist != float('inf'):
if distance[index] > distance[target_min_ind] + rota_dist:
distance[index] = distance[target_min_ind] + rota_dist
#opt_nodes[index] = target_min_ind
print(distance[N-1] if distance[N-1] != float('inf') else -1) |
s556250449 | p04003 | u180908266 | 1529556319 | Python | Python (3.4.3) | py | Runtime Error | 3758 | 2002900 | 1412 | N,M = map(int, input().split())
"""
if M == 0:
print(-1)
exit()
"""
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0~N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
edges[3*c+(p-1)][3*c+(q-1)] = 0
edges[3*c+(q-1)][3*c+(p-1)] = 0
edges[p-1][3*c+(p-1)] = 1
edges[q-1][3*c+(q-1)] = 1
edges[3*c+(p-1)][p-1] = 0
edges[3*c+(q-1)][q-1] = 0
while (distance[N-1] == float('inf')):
temp_min_dist = float('inf')
for unsearched_ind in unsearached_nodes:
if temp_min_dist > distance[unsearched_ind]:
temp_min_dist = distance[unsearched_ind]
target_min_ind = unsearched_ind
unsearached_nodes.remove(target_min_ind)
target_node = edges[target_min_ind]
flag = False
for index, rota_dist in enumerate(target_node):
if rota_dist != float('inf'):
if distance[index] > distance[target_min_ind] + rota_dist:
distance[index] = distance[target_min_ind] + rota_dist
#opt_nodes[index] = target_min_ind
print(distance[N-1] if distance[N-1] != float('inf') else -1) |
s127124546 | p04003 | u180908266 | 1529556232 | Python | Python (3.4.3) | py | Runtime Error | 3705 | 2002768 | 1411 | N,M = map(int, input().split())
"""
if M == 0:
print(-1)
exit()
"""
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0~N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
edges[3*c+(p-1)][3*c+(q-1)] = 0
edges[3*c+(q-1)][3*c+(p-1)] = 0
edges[p-1][3*c+(p-1)] = 1
edges[q-1][3*c+(q-1)] = 1
edges[3*c+(p-1)][p-1] = 0
edges[3*c+(q-1)][q-1] = 0
while (distance[N-1] == float('inf')):
temp_min_dist = float('inf')
for unsearched_ind in unsearached_nodes:
if temp_min_dist > distance[unsearched_ind]:
temp_min_dist = distance[unsearched_ind]
target_min_ind = unsearched_ind
unsearached_nodes.remove(target_min_ind)
target_node = edges[target_min_ind]
flag = False
for index, rota_dist in enumerate(target_node):
if rota_dist != float('inf'):
if distance[index] > distance[target_min_ind] + rota_dist:
distance[index] = distance[target_min_ind] + rota_dist
#opt_nodes[index] = target_min_ind
print(distance[N-1] if distnce[N-1] != float('inf') else -1) |
s010712249 | p04003 | u180908266 | 1529555497 | Python | Python (3.4.3) | py | Runtime Error | 4712 | 2002896 | 1346 | N,M = map(int, input().split())
if M == 0:
print(-1)
exit()
pqcs = [list(map(int, input().split())) for _ in range(M)]
c_max = max(list(map(lambda x: x[2],pqcs)))
node_num = (c_max+1)*N
unsearached_nodes = list(range(node_num))#0~N-1(n-1)が乗換経由ノード/路線iの駅nは3*i+(n-1)番ノード
#opt_nodes = [-1]*node_num
distance = [float('inf')]*node_num
distance[0] = 0
cost = 0
edges = [[float('inf')]*node_num for _ in range(node_num)]
#辺へ重み付け
for p,q,c in pqcs:
edges[3*c+(p-1)][3*c+(q-1)] = 0
edges[3*c+(q-1)][3*c+(p-1)] = 0
edges[p-1][3*c+(p-1)] = 1
edges[q-1][3*c+(q-1)] = 1
edges[3*c+(p-1)][p-1] = 0
edges[3*c+(q-1)][q-1] = 0
while (distance[N-1] == float('inf')):
temp_min_dist = float('inf')
for unsearched_ind in unsearached_nodes:
if temp_min_dist > distance[unsearched_ind]:
temp_min_dist = distance[unsearched_ind]
target_min_ind = unsearched_ind
unsearached_nodes.remove(target_min_ind)
target_node = edges[target_min_ind]
for index, rota_dist in enumerate(target_node):
if rota_dist != float('inf'):
if distance[index] > distance[target_min_ind] + rota_dist:
distance[index] = distance[target_min_ind] + rota_dist
#opt_nodes[index] = target_min_ind
print(distance[N-1]) |
s605573397 | p04003 | u898651494 | 1520666331 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 3732 | #include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define MAP map<int,int>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e17;
void ANS(bool flag){
cout << ((flag) ? "YES" : "NO") << endl;
}
void Ans(bool flag) {
cout << ((flag) ? "Yes" : "No") << endl;
}
void ans(bool flag) {
cout << ((flag) ? "yes" : "no") << endl;
}
struct EDGE {
int fromtrain, to, totrain, cost;
};
vector<vector<PAIR>> edge(100000 + 1);
vector<vector<PAIR>> node(100000 + 1);
void dijkstra(void) {
priority_queue<pair<int,PAIR>, vector<pair<int,PAIR>>, greater<pair<int,PAIR>>> pq;
set<PAIR> st;
node[1][0].second = 0;
pq.push({ 0,{1, 0}});
while (!pq.empty()) {
int from = pq.top().second.first;
int i = pq.top().second.second;
pq.pop();
if (i == 0) {
REP(j, edge[from].size()) {
int to = edge[from][j].first;
int train = edge[from][j].second;
FOR(k, 1, node[to].size()) {
if (node[to][k].first == train && node[to][k].second > node[from][0].second + 1) {
node[to][k].second = node[from][0].second + 1;
pq.push({ node[to][k].second,{ to , k } });
}
}
}
}
else {
if (node[from][0].second > node[from][i].second) {
node[from][0].second = node[from][i].second;
pq.push({ node[from][0].second,{ from , 0 } });
}
REP(j, edge[from].size()) {
int to = edge[from][j].first;
int train = edge[from][j].second;
if (node[from][i].first == train) {
FOR(k, 1, node[to].size()) {
if (node[to][k].first == node[from][i].first && node[to][k].second > node[from][i].second) {
node[to][k].second = node[from][i].second;
pq.push({ node[to][k].second,{ to , k } });
}
}
}
}
}
}
return;
}
int main() {
int N, M;
cin >> N >> M;
FOR(i, 1, N + 1) node[i].push_back({ -1, 10000000 });
set<PAIR> st;
REP(i, M) {
int p, q, c;
cin >> p >> q >> c;
if (st.insert({ p,c }).second) node[p].push_back({ c, 10000000 });
if (st.insert({ q,c }).second) node[q].push_back({ c, 10000000 });
edge[p].push_back({q,c});
edge[q].push_back({p,c});
}
if (M == 0) {
cout << -1 << endl;
return 0;
}
dijkstra();
//FOR(i, 1, N + 1) {
// cout << i << " ";
// REP(j, node[i].size()){
// cout << node[i][j].first << " " << node[i][j].second << " ";
// }
// cout << endl;
//}
cout << node[N][0].second << endl;
//cin >> N >> M;
return 0;
}
|
s443598302 | p04003 | u435281580 | 1519677926 | Python | Python (3.4.3) | py | Runtime Error | 3179 | 307652 | 573 | import numpy as np
N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
queue = [(1, 0, 0)]
dist = np.zeros(N + 1, 'i')
dist[:] = 10000
while len(queue) > 0:
start, lastm, cost = queue[0]
del queue[0]
if start == N:
print(cost)
exit()
if cost > dist[start]:
continue
dist[start] = cost
for (f, t, m) in routes[routes[:, 0] == start]:
if m == lastm:
queue.insert(0, (t, m, cost))
else:
queue.append((t, m, cost + 1))
print(-1) |
s753859761 | p04003 | u435281580 | 1519677032 | Python | Python (3.4.3) | py | Runtime Error | 3180 | 331532 | 462 | import numpy as np
N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
queue = [(1, 0, 0)]
while len(queue) > 0:
start, lastm, cost = queue[0]
del queue[0]
if start == N:
print(cost)
exit()
for (f, t, m) in routes[routes[:, 0] == start]:
if m == lastm:
queue.insert(0, (t, m, cost))
else:
queue.append((t, m, cost + 1))
print(-1) |
s664043234 | p04003 | u435281580 | 1519676266 | Python | Python (3.4.3) | py | Runtime Error | 3163 | 69444 | 595 | import numpy as np
N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
# i駅まで到達したときの最小コスト(最終電車がjで示される)
dp = [{} for _ in range(N + 1)]
dp[1][0] = 0
for i in range(2, N + 1):
for (f, t, m) in routes[routes[:, 1] == i]:
if m in dp[f]:
dp[t][m] = dp[f][m]
else:
values = dp[f].values()
if len(values) > 0:
dp[t][m] = min(values) + 1
if len(dp[N].values()) > 0:
print(min(dp[N].values()))
else:
print(-1) |
s852151449 | p04003 | u435281580 | 1519674454 | Python | Python (3.4.3) | py | Runtime Error | 3189 | 1600312 | 584 | import numpy as np
N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
#print(routes)
# i駅まで到達したときの最小コスト(最終電車がjで示される)
dp = np.zeros((N + 1, M + 1), 'i')
dp[:, :] = 10000
dp[1, 0] = 0
for i in range(2, N + 1):
for (f, t, m) in routes:
if t != i:
continue
if dp[f, m] < 10000:
dp[t, m] = dp[f, m]
else:
dp[t, m] = min(dp[f, :]) + 1
cost = min(dp[N, :])
if cost < 10000:
print(cost)
else:
print(-1)
|
s754363807 | p04003 | u435281580 | 1519674408 | Python | Python (3.4.3) | py | Runtime Error | 3182 | 1600344 | 583 | import numpy as np
N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
print(routes)
# i駅まで到達したときの最小コスト(最終電車がjで示される)
dp = np.zeros((N + 1, M + 1), 'i')
dp[:, :] = 10000
dp[1, 0] = 0
for i in range(2, N + 1):
for (f, t, m) in routes:
if t != i:
continue
if dp[f, m] < 10000:
dp[t, m] = dp[f, m]
else:
dp[t, m] = min(dp[f, :]) + 1
cost = min(dp[N, :])
if cost < 10000:
print(cost)
else:
print(-1)
|
s774543354 | p04004 | u100858029 | 1562436209 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1045 | #include<iostream>
#define MOD 1000000007
#define N 1000
using namespace std;
typedef long long LL;
LL mod_pow(LL base, LL exp)
{
if(exp==0) return 1;
if(exp&1) return (mod_pow(base,exp-1)*base)%MOD;
else return mod_pow((base*base)%MOD,exp/2);
}
LL fac[3*N+1];
LL fac_inv[3*N+1];
LL C(LL n, LL k)
{
if(k < 0 || n < k) return 0;
LL num = fac[n];
LL den = (fac_inv[n-k]*fac_inv[k])%MOD;
return (num*den)%MOD;
}
int main()
{
fac[0] = 1;
for(LL n = 1; n <= 3*N; n++)
fac[n] = (fac[n-1]*n)%MOD;
fac_inv[3*N] = mod_pow(fac[3*N],MOD-2);
for(LL n = 3*N-1; n >= 0; n--)
fac_inv[n] = (fac_inv[n+1]*(n+1))%MOD;
LL a, b, c; cin >> a >> b >> c;
a++;
//WLOG, b > c
if(!(b>c))
{
b = b^c;
c = b^c;
b = b^c;
}
LL ans = 0;
LL sum = 1;
LL pull = 0;
for(LL n = a; n <= a+b+c; n++)
{
LL sub = 0;
sub = (sub+sum-pull)%MOD;
sub = (sub*C(n-2,a-2))%MOD;
sub = (sub*mod_pow(3,a+b+c-n))%MOD;
ans = (ans+sub)%MOD;
sum = (2*sum-C(n-a,c))%MOD;
pull = (2*pull+C(n-a,n-a-b))%MOD;
}
cout<<(ans+MOD)%MOD<<endl;
return 0;
} |
s034516980 | p04004 | u089230684 | 1538857794 | Python | Python (3.4.3) | py | Runtime Error | 3156 | 3188 | 383 | mod=int(1E9+7)
JS=[1]
for i in range(1,5000):
JS.append(JS[-1]*i%mod)
Cs=lambda x,y:js(x)*inv(js(y))*inv(js(x-y))%mod
inv =lambda x:pow(x,mod-2,mod)
js=lambda x:JS[x]
#while True:
A,B,C=map(int,input().split())
A-=1;B+=1;C+=1;
ans=0
for x in range(1,B+1):
for y in range(1,C+1):
ans+=Cs(A+B-x+C-y,A)*Cs(B-x+C-y,B-x)*pow(3,x-1+y-1,mod)%mod
ans%=mod
print(ans)
|
s874727383 | p04004 | u863370423 | 1538857702 | Python | Python (3.4.3) | py | Runtime Error | 3156 | 3188 | 383 | mod=int(1E9+7)
JS=[1]
for i in range(1,4000):
JS.append(JS[-1]*i%mod)
Cs=lambda x,y:js(x)*inv(js(y))*inv(js(x-y))%mod
inv =lambda x:pow(x,mod-2,mod)
js=lambda x:JS[x]
#while True:
A,B,C=map(int,input().split())
A-=1;B+=1;C+=1;
ans=0
for x in range(1,B+1):
for y in range(1,C+1):
ans+=Cs(A+B-x+C-y,A)*Cs(B-x+C-y,B-x)*pow(3,x-1+y-1,mod)%mod
ans%=mod
print(ans)
|
s952328387 | p04005 | u468972478 | 1599785033 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9100 | 124 | s = sorted(list(map(int, input().split())))
a = s.pop(-1)
b,c = a // 2, a - (a//2)
d = s[0] * a[1]
print(abs(d * b - d * c)) |
s442961607 | p04005 | u547537397 | 1593489059 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9044 | 252 | import sys
input = sys.stdin.readline
def linput(ty=int, cvt=list):
return cvt(map(ty,input().split()))
def gcd(a: int, b: int):
while b: a, b = b, a%b
return a
def lcm(a: int, b: int):
return a * b // gcd(a, b)
def main():
#n=int(input()) |
s714040157 | p04005 | u131453093 | 1593376777 | Python | Python (3.8.2) | py | Runtime Error | 29 | 9032 | 197 | A, B, C = map(int, input().split())
if any(i % 2 == 0 for i in [A, B, C]):
print(0)
else:
AB = A * B
lis = [AB] * C
mid = len(lis) // 2
print(sum(lis[mid:]) - sum(lis[0:mid]))
|
s436471343 | p04005 | u556589653 | 1593314873 | Python | PyPy3 (7.3.0) | py | Runtime Error | 96 | 74332 | 66 | a,b,c = map(int,input().split())
print(min(B * C,C * A,A * B)) |
s506737742 | p04005 | u322171361 | 1592254203 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 80 | a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
a,b,c=[a,b,c].sort()
print(a*b) |
s903013426 | p04005 | u961683878 | 1591593071 | Python | Python (2.7.6) | py | Runtime Error | 224 | 16264 | 396 | #! /usr/bin/env python3
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
A, B, C = map(int, readline().split())
if (A % 2 == 0) or (B % 2 == 0) or (C % 2 == 0):
print(0)
else:
tmp = [A, B, C]
tmp = sorted(tmp)
print(tmp[0] * tmp[1])
|
s844579471 | p04005 | u810288681 | 1590103493 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 127 | l = sorted(list(map((int, input().split()))))
ans = 0
if l[0]%2!=0 and l[1]%2!=0 and l[2]%2!=0:
ans += l[0]*l[1]
print(ans) |
s116251230 | p04005 | u026788530 | 1589904058 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 115 | a=[int(_) for i in range(n)]
if a[0]%2==0 or a[1]%2==0 or a[2]%2==0:
print(0)
else:
a.sort()
print(a[0]*a[1]) |
s556267653 | p04005 | u252828980 | 1588794407 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 134 | a,b,c = list(map(int,input().split()))
if any([i%2==0 for i in (a,b,c)]):
print(0)
else:
ans = min(a*b , c*b , a*c)
print(ans) |
s446199180 | p04005 | u252828980 | 1588794025 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 200 | a,b,c = list(map(int,input().split()))
if any([i%2==0 for i in (a,b,c)]):
print(0)
else:
ans = min(a*b*(c//2+1) - a*b*(c//2) , c*b*(a//2+1) - c*b*(a//2) , a*c*(b//2+1) - a*c*(b//2))
print(ans) |
s811185887 | p04005 | u309141201 | 1587861668 | Python | PyPy3 (2.4.0) | py | Runtime Error | 174 | 38640 | 286 | A, B, C = map(int, input().split())
if (A * B * C) % 2 == 0:
ans = 0
else:
V = A*B*C
AB = A*B
BC = B*C
CA = C*A
ans = min(V-(A//2)*BC, V-((A//2) + 1)*BC)
ans = min(V-(B//2)*CA, V-((B//2) + 1)*CA)
ans = min(V-(C//2)*AB, V-((C//2) + 1)*AB)
print(V - 2*ans) |
s969846267 | p04005 | u368563078 | 1587484022 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 164 | A,B,C = map(int,input())
num_list = [A,B,C]
list_s = sorted(num_list)
if A % 2 == 1 and B % 2 == 1 and C % 2 == 1:
print(list_s[0]*list_s[1])
else:
print(0) |
s435884578 | p04005 | u368563078 | 1587483958 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 171 | A,B,C = map(int,input())
num_list = [A,B,C]
list_s = sorted(num_list)
if A % 2 == 1 and B % 2 == 1 and C % 2 == 1:
print(list_s[0]*list_s[1])
else:
print(0)
|
s993966385 | p04005 | u746428948 | 1587149937 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 702 | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;
int main() {
ll A,B,C;
cin>>A>>B>>C;
if(A%2==0||B%2==0||C%2==0) cout<<0<<endl;
else {
vector<ll> v;
v.pb(A);
v.pb(B);
v.pb(C);
sort(all(v));
cout<<v[0]*v[1]<<endl;
}
} |
s534081873 | p04005 | u098982053 | 1585506429 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 300 | Cube = [int(i) for i in input().split(" ")]
# 一番長い辺で切れば断面の数は最小
L = max(Cube)
plane = [i for i in Cube if i!=L]
if len(plane)==0:
A = L
B = L
elif len(plane)==1:
A = plane[0]
B = L
else:
A,B = map(int,plabe)
print(abs((A*B*(L//2))-(A*B*(L-(L//2))))) |
s835226544 | p04005 | u098982053 | 1585506133 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 192 | Cube = [int(i) for i in input().split(" ")]
# 一番長い辺で切れば断面の数は最小
L = max(Cube)
A,B = map(int,[i for i in Cube if i!=L])
print(abs((A*B*(L//2))-(A*B*(L-(L//2))))) |
s299925517 | p04005 | u835924161 | 1583748439 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 110 | a,b,c=map(int,input().split())
if a%2==0 or b%2==0 or c%2==0:
print(0)
exit()
print(min[a*b,b*c,c*a]) |
s849433957 | p04005 | u693716675 | 1583556488 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 155 | a,b,c = [int(i) for i in input().split()]
if (a*b*c)%2==0:
print(0)
else:
ans = a*b
ans = min(ans, b*c)
ans = min(aans, c*a)
print(ans) |
s275727255 | p04005 | u252828980 | 1575689170 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 394 | a,b,c = map(int,input().split())
p = any((a%2 == 0,b%2 == 0,c%2 == 0))
if p:
print(0)
else:
L = []
for i in range(a//2,a//2+2):
L.append(i*b*c)
aa = abs(L[0]-L[1])
L = []
for j in range(b//2,b//2+2):
L.append(j*a*c)
bb = abs(L[0]-L[1])
L = []
for k in range(c//2,c//2+2):
L.append(k*a*b)
cc = abs(L[0]-L[1])
print(min(aa,bb,cc)) |
s034724514 | p04005 | u754022296 | 1573265653 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 117 | a, b, c = map(int, input().split())
if a%2 and b%2 and c%2:
l = sorted(a, b, c)
print(l[0]*l[1])
else:
print(0) |
s979365264 | p04005 | u204236873 | 1560577191 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 660 | if __name__ == "__main__":
N, x = input().split(" ")
N = int(N)
x = int(x)
a = []
for e in input().split(" "):
a.append(int(e))
min_cost = []
for i in range(N):
min_cost.append([0] * N)
min_total_cost = -1
for k in range(N):
temp_sum = 0
if k==0:
for i in range(N):
min_cost[k][i] = a[i]
temp_sum += min_cost[k][i]
else:
for i in range(N):
idx = (i-k) % N
min_cost[k][i] = min(min_cost[k-1][i], a[idx])
temp_sum += min_cost[k][i]
if min_total_cost == -1:
min_total_cost = (k * x) + temp_sum
else:
temp = (k * x) + temp_sum
if temp < min_total_cost:
min_total_cost = temp
print (min_total_cost) |
s494821604 | p04005 | u623687794 | 1557718590 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 113 | a=list(map(int,input().split()))
a.sort()
if a%2!=0 and b%2!=0 and c%2!=0:
print(a[0]*a[1])
else:
print("0")
|
s964849111 | p04005 | u623687794 | 1557718522 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 112 | a=list(map(int,input().split()))
a.sort()
if a%2!=0 and b%2!=0 and c%2!=0:
print(a[0]*a[1])
elif:
print("0") |
s480796509 | p04005 | u507116804 | 1557718284 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 111 | a,b,c=map(int,input().split())
m=a*b*c
k=max(a,b,c)
if m%2==0:
print(int(0))
else:
h=m/k
print(int((h)) |
s447316080 | p04005 | u507116804 | 1557717757 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 126 | a,b,c=map(int,input().split())
m=a*b*c
k=max(a,b,c)
if m%2==0:
print(int(0))
else:
n=k//2
h=m/k
print(int((k-2n)*h)) |
s631290542 | p04005 | u227082700 | 1553833804 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 88 | a=list(int,input().split());a.sort();s=a[0]*a[1]
if (a[2]*s)%2==0:print(0)
else:print(s) |
s190317035 | p04005 | u394721319 | 1552782742 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3316 | 165 | li = [int(i) for i in input().split()]
for i in li:
if i%2 == 0:
print(0)
exit()
li.pop(max(li))
ans = 1
for i in li:
ans *= i
print(ans)
|
s913342716 | p04005 | u263933075 | 1549821610 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 149 | s=input().split();a,b,c=int(s[0]),int(s[1]),int(s[2])
ma,mi=max(a,b,c),min(a,b,c);me=sum(a,b,c)-ma-mi
if ma%2==0:
print(0)
else:
print(mi*me) |
s309691044 | p04005 | u459233539 | 1546475161 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 63 | a,b,c=map(int,input().split())
print(min(a%*b*c,b%*a*c,c%*a*b)) |
s634536664 | p04005 | u459233539 | 1546475097 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 70 |
a,b,c=map(int,input().split())
print(min((a%)*b*c,a*(b%)*c,a*b*(c%))) |
s916052211 | p04005 | u459233539 | 1546475061 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 63 | a,b,c=map(int,input().split())
print(min(a%*b*c,a*b%*c,a*b*c%)) |
s475049765 | p04005 | u311944296 | 1542796102 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 504 | #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int64 a, b, c, ans = LLONG_MAX;
void calc(int64 a, int64 b, int64 c) {
int64 r = a / 2;
for(int64 i = max(1LL, r - 5); i <= min(r + 5, a - 1); i++) {
int64 v1 = i * b * c;
int64 v2 = (a - i) * b * c;
ans = min(ans, llabs(v1 - v2));
}
}
int main() {
scanf("%lld%lld%lld", &a, &b, &c);
calc(a, b, c);
calc(a, c, b);
calc(b, a, c);
calc(b, c, a);
calc(c, a, b);
calc(c, b, a);
printf("%lld\n", ans);
return 0;
} |
s362840031 | p04005 | u311944296 | 1542795914 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 455 | from math import *
a, b, c = map(int, input().split())
def calc(a, b, c):
r = sqrt(a)
ans = a * b * c
for i in range(max(1, r - 5), min(r + 5, a - 1) + 1):
v1 = i * b * c
v2 = (a - i) * b * c
ans = min(ans, abs(v1 - v2))
return ans
res = a * b * c
res = min(res, calc(a, b, c))
res = min(res, calc(a, c, b))
res = min(res, calc(b, a, c))
res = min(res, calc(b, c, a))
res = min(res, calc(c, a, b))
res = min(res, calc(c, b, a))
print(res) |
s801701820 | p04005 | u884982181 | 1541732213 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 111 | a = list(map(int,input().split()))
a.sort()
for i in a:
if a%2 == 0:
print(0)
exit()
print(a[0]*a[1]) |
s607652352 | p04005 | u333139319 | 1539111550 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 124 | [a,b,c] == [int(i) for i in input().split()]
if (a * b * c) % 2 == 0:
print(0)
else:
print(min(a * b,b * c,c * a))
|
s032473004 | p04005 | u824237520 | 1538510995 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 393 | n, x = map(int, input().split())
a = list(map(int, input().split()))
temp = 0
check = 0
for i in range(1, n):
if a[i] <= a[i - 1] + x:
check = 1
temp = i
break
if check == 1:
a = a[temp:] + a[:temp]
check = 1
for i in range(1, n):
if a[i] >= a[i - check] + x:
a[i] = a[i - check] + x
check += 1
else:
check = 1
print(sum(a)) |
s170651349 | p04005 | u790301364 | 1537202448 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 462 | def main10():
buf = int(input(""));
strbuf = input("");
strbufs = strbuf.split();
buf2 = [];
for i in range(buf):
buf2.append(int(strbufs[i]));
if len(buf2) == 1:
return("YES");
else:
ki = 0;
for i in range(buf):
if buf2[i] % 2 == 1:
ki += 1;
if ki % 2 == 0:
print("YES");
else:
print("NO");
if __name__ == '__main__':
main10() |
s179742963 | p04005 | u627417051 | 1531460529 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 147 | A, B, C = list(map(int, input().split()))
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
print(0)
else:
ABC = sort([A, B, C])
print(ABC[0] * ABC[1]) |
s810180512 | p04005 | u813356465 | 1475473420 | Python | PyPy2 (5.6.0) | py | Runtime Error | 40 | 8944 | 532 | def min_k_shift(k, a, N, x, range_min):
cost = k*x
for j in range(N):
cost += range_min[(j-k)%N][j] #min(a[(j-sj)%N] for sj in range(k))
return cost
N, x = [int(s) for s in raw_input().split()]
a = [int(s) for s in raw_input().split()]
range_min = [[0]*N for st in range(N)]
for st in range(N):
range_min[st][st] = a[st]
for k in range(1,N):
for st in range(N):
range_min[st][(st+k)%N] = min(range_min[st][(st+k-1)%N],a[(st+k)%N])
print(min(min_k_shift(k,a,N,x,range_min) for k in range(N))) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.