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
s153731490
p03856
u375616706
1548713570
Python
Python (3.4.3)
py
Runtime Error
93
4072
464
s1 = "maerd" s2 = "remaerd" s3 = "esare" s4 = "resare" i = input() s = '' for c in reversed(i): s += c l = len(s) i = 0 def dfs(i): if i == l: print("YES") exit() if i+5 <= l and s[i:i+5] == s1: dfs(i+5) elif i+7 <= l and s[i:i+7] == s2: dfs(i+7) elif i+5 <= l and s[i:i+5] == s3: dfs(i+5) elif i+6 <= l and s[i:i+6] == s4: dfs(i+6) else: print("NO") exit() dfs(0)
s645470992
p03856
u375616706
1548712383
Python
Python (3.4.3)
py
Runtime Error
77
4064
353
s = input() l = len(s) def dfs(i): # print("->", s[i:]) if i == l: print("YES") exit() if s[i:i+5] == "dream": if i+7 < l and s[i+5:i+7] == "er": dfs(i+7) dfs(i+5) elif s[i:i+5] == "erase": if i+5 < l and s[i+5] == "r": dfs(i+6) dfs(i+5) dfs(0) print("NO")
s942806938
p03856
u375616706
1548712223
Python
Python (3.4.3)
py
Runtime Error
80
4060
313
s = input() l = len(s) def dfs(i): if i == l: print("YES") exit() if s[i:i+5] == "dream": if i+7 < l and s[i+5:i+7] == "er": dfs(i+7) dfs(i+5) elif s[i:i+5] == "erase": if i+6 < l and s[i+5] == "r": dfs(i+6) dfs(i+5) dfs(0)
s279803105
p03856
u375616706
1548710556
Python
Python (3.4.3)
py
Runtime Error
130
98584
318
ans = "NO" s = input() def dfs(s): ret = 0 if len(s) == 0: return 1 if s[:5] == 'dream' or s[:5] == 'erase': ret += dfs(s[5:]) if s[:7] == 'dreamer': ret += dfs(s[7:]) if s[:6] == 'eraser': ret += dfs(s[6:]) return ret if dfs(s): ans = "YES" print(ans)
s894227964
p03856
u284854859
1544817214
Python
Python (3.4.3)
py
Runtime Error
18
2940
11
dreameraser
s168734391
p03856
u620868411
1534617728
Python
Python (3.4.3)
py
Runtime Error
126
98548
306
# -*- coding: utf-8 -*- def f(s): # print(s) if s.startswith("dream"): return f(s[5:]) or f(s[7:]) elif s.startswith("erase"): return f(s[5:]) or f(s[6:]) elif s=="": return True else: return False if f(input()): print("YES") else: print("NO")
s817371347
p03856
u765237551
1532804646
Python
Python (3.4.3)
py
Runtime Error
28
3188
504
s = input() def solve(s): i = 0 n = len(s) while i < n: if s[i:i+5] == 'dream': if s[i+5:i+7] != 'er': i += 5 elif i+7 < n and s[i+7] == 'a': i += 5 else: i += 7 elif s[i:i+5] == 'erase': if s[i+5] == 'r': i += 6 else: i += 5 else: return False return True if solve(s): print("Yes") else: print('No')
s801639497
p03856
u341855122
1506906807
Python
Python (2.7.6)
py
Runtime Error
11
2692
249
S = raw_input() t = ['dreamer','dream','eraser','erase'] while len(S) > 0: for i in t: if S[S.rfind(i):]==i: S = S[:S.rfind(t)] break elif i == t[-1]: print "NO" exit() print "YES"
s348912913
p03856
u341855122
1506906633
Python
Python (2.7.6)
py
Runtime Error
11
2692
251
S = raw_input() t = ['dreamer','dream','eraser','erase'] while len(S) > 0: for i in t: if S[S.rfind(i):]==i: S = S[:S.rfind(t)] continue elif i == t[-1]: print "NO" exit() print "YES"
s828867647
p03856
u844771757
1500593131
Python
PyPy3 (2.4.0)
py
Runtime Error
310
45936
354
s=input() n=len(s) f=[-1]*(n+1) def check(x): if(f[x]!=-1):return f[x] if(x==n):return 1 if(n-x>6 and s[x:x+7]=='dreamer'and check(x+7)):f[x]=1;return 1 if(n-x>5 and s[x:x+6]=='eraser'and check(x+6)):f[x]=1;return 1 if(n-x>4 and s[x:x+5]in ['erase','dream']and check(x+5)):f[x]=1;return 1 f[x]=0 return 0 if(check(0)):print("YES") else:print("NO")
s895218987
p03856
u471797506
1491600287
Python
Python (2.7.6)
py
Runtime Error
12
2936
1125
from collections import defaultdict class UnionFind: def __init__(self, size): self.rank = [0] * size self.par = range(size) def find(self, x): if x == self.par[x]: return x self.par[x] = self.find(self.par[x]) return self.par[x] def same(self, x, y): return self.find(x) == self.find(y) def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if (self.rank[x] > self.rank[y]): self.par[y] = x else: self.par[x] = y if (self.rank[x] == self.rank[y]): self.rank[y] += 1 N, K, L = map(int, raw_input().split()) pq = [map(int, raw_input().split()) for i in xrange(K)] rs = [map(int, raw_input().split()) for i in xrange(L)] road = UnionFind(N) rail = UnionFind(N) for p, q in pq: road.unite(p - 1, q - 1) for r, s in rs: rail.unite(r - 1, s - 1) for i in xrange(N): road.find(i) rail.find(i) pair = defaultdict(int) for i, j in zip(road.par, rail.par): pair[i, j] += 1 print " ".join(map(str, [pair[road.par[i], rail.par[i]] for i in xrange(N)]))
s913768548
p03856
u332385682
1489360924
Python
PyPy3 (2.4.0)
py
Runtime Error
175
42352
1230
import sys from collections import Counter class UnionFind: def __init__(self, n): self.p = list(range(n)) self.rank = [0] * n def find_root(self, x): if x != self.p[x]: self.p[x] = self.find_root(self.p[x]) return self.p[x] def is_same(self, x, y): return self.find_root(x) == self.find_root(y) def unite(self, x, y): u = self.find_root(x) v = self.find_root(y) if u == v: return if self.rank[u] < self.rank[v]: self.p[u] = v else: self.p[v] = u if self.rank[u] == self.rank[v]: self.rank[u] += 1 N, K, L = map(int, sys.stdin.readline().split()) uf1 = UnionFind(N) uf2 = UnionFind(N) for i in range(K): p, q = map(int, sys.stdin.readline().split()) p, q = p - 1, q - 1 uf1.unite(p, q) for i in range(L): r, s = map(int, sys.stdin.readline().split()) r, s = r - 1, s - 1 uf2.unite(r, s) cntr = Counter() for i in range(N): u = uf1.find_root(i) v = uf2.find_root(i) cntr[(u, v)] += 1 ans = [] for i in range(N): u = uf1.find_root(i) v = uf2.find_root(i) ans.append(cntr[(u, v)]) print(*ans)
s072498758
p03856
u136231568
1481949246
Python
Python (3.4.3)
py
Runtime Error
22
3064
403
s = input().strip() strings = "eraser erase dreamer dream".split() exceptions = "dreameraser dreamerase".split() while 1: for string in strings: if s.startswith(string): if string == "dreamer": for exception in exceptions: if startswith(exception): s = s[len(exception):] else: s = s[len(string):] break else: break print("NO" if s else "YES")
s583082420
p03856
u297228366
1481762533
Python
Python (2.7.6)
py
Runtime Error
16
2568
1224
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; const int MAXN = 200005; int N, K, L, u, v, visited[2][MAXN], cnt[2] = {1, 2}; vector<int> adjList[2][MAXN]; map<ii,int> m; void dfs(int id, int node) { if (visited[id][node]) { return; } else { visited[id][node] = cnt[id]; for (int i = 0; i < adjList[id][node].size(); i++) { int neighbor = adjList[id][node][i]; dfs(id, neighbor); } } } int main() { scanf("%d%d%d", &N, &K, &L); for (int i = 0; i < K; i++) { scanf("%d%d", &u, &v); adjList[0][u].push_back(v); adjList[0][v].push_back(u); } for (int i = 0; i < L; i++) { scanf("%d%d", &u, &v); adjList[1][u].push_back(v); adjList[1][v].push_back(u); } for (int i = 1; i <= N; i++) { if (!visited[0][i]) { dfs(0, i); cnt[0] += 2; } if (!visited[1][i]) { dfs(1, i); cnt[1] += 2; } } for (int i = 1; i <= N; i++) { m[ii(visited[0][i], visited[1][i])]++; } for (int i = 1; i <= N; i++) { cout << m[ii(visited[0][i], visited[1][i])] << " "; } return 0; }
s993300189
p03856
u594903131
1481554238
Python
Python (3.4.3)
py
Runtime Error
22
3068
3
no
s475454272
p03856
u966695411
1481437177
Python
Python (3.4.3)
py
Runtime Error
25
3316
132
S = input() for i in ['eraser', 'erase', 'dreamer', 'dream']: S=S.replace(i, 'R') print(['NO', 'YES'][len(s) == 1 and 'R' in s])
s035123277
p03856
u123756661
1481435545
Python
Python (2.7.6)
py
Runtime Error
21
3068
2308
#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys import re import math import itertools import collections import bisect #sys.stdin=file('input.txt') #sys.stdout=file('output.txt','w') #10**9+7 mod=1000000007 #mod=1777777777 pi=3.141592653589 IS=float('inf') xy=[(1,0),(-1,0),(0,1),(0,-1)] bs=[(-1,-1),(-1,1),(1,1),(1,-1)] def niten(a,b): return abs(a-b) if a>=0 and b>=0 else a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b)) def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)] def gcd(a,b): return a if b==0 else gcd(b,a%b) def lcm(a,b): return a*b/gcd(a,b) def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5 def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0 def pscl(num,l=[1]): for i in range(num): l = map(lambda x,y:x+y,[0]+l,l+[0]) return l class UnionFind: def __init__(self, size): self.rank=[0]*size self.par =range(size) self.grp =size def find(self, x): if x==self.par[x]: return x self.par[x]=self.find(self.par[x]) return self.par[x] def same(self, x, y): #2つの頂点が同じグループであるかを判定する return self.find(x)==self.find(y) def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する x,y=self.find(x),self.find(y) if x==y: return self.grp-=1 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 group_num(self): return self.grp def ra(self): return self.rank n,k,l=map(int,raw_input().split()) uf=UnionFind(n) q1,q2=[],[] ans=[0]*n for i in range(k): a,b=map(int,raw_input().split()) uf.unite(a-1,b-1) q1.append((a-1,b-1)) ans[a-1]=1 ans[b-1]=1 for i in range(l): a,b=map(int,raw_input().split()) if ans[a-1]==0: ans[a-1]=1 if ans[b-1]==0: ans[b-1]=1 if uf.same(a-1,b-1): ans[a-1]=2 ans[b-1]=2 uf=UnionFind(n) for i in q2: uf.unite(i[0],i[1]) for i in q1: if uf.same(i[0],i[1]): ans[i[0]]=2 ans[i[1]]=2 print ' '.join(map(str,ans))
s459250952
p03856
u104282757
1481425858
Python
Python (2.7.6)
py
Runtime Error
71
2820
645
S = raw_input() def pick_greedy(S): if S[0:5] == 'dream': if S[5:7] == 'er': if S[7] == 'a': ret = 'dream' else: ret = 'dreamer' else: ret = 'dream' elif S[0:5] == 'erase': if S[5] == 'r': ret = 'eraser' else: ret = 'erase' else: ret = 'no' return ret sol = 'YES' while len(S) > 0: r = pick_greedy(S) if r == 'no': sol = 'NO' break else: if len(S) < len(r): sol = 'NO' break else: S = S[len(r):] print sol
s084906263
p03856
u297228366
1481424543
Python
Python (2.7.6)
py
Runtime Error
147
98172
636
T = ["maerd", "remaerd", "esare", "resare"] def match(s): if s == "": return True elif s[0] == "m" and len(s) >= len(T[0]) and s[:len(T[0])] == T[0]: return match(s[len(T[0]):]) elif s[0] == "r" and len(s) > 2: if s[2] == "m" and len(s) >= len(T[1]) and s[:len(T[1])] == T[1]: return match(s[len(T[1]):]) elif s[2] == "s" and len(s) >= len(T[3]) and s[:len(T[3])] == T[3]: return match(s[len(T[3]):]) else: return False elif s[0] == "e" and len(s) >= len(T[2]) and s[:len(T[2])] == T[2]: return match(s[len(T[2]):]) else: return False S = raw_input() S = S[::-1] if match(S): print "YES" else: print "NO"
s406348487
p03856
u297228366
1481423859
Python
Python (2.7.6)
py
Runtime Error
168
98136
267
T = ["dream", "dreamer", "erase", "eraser"] def match(s): if s == "": return True else: ans = False for i in T: if len(i) <= len(s) and s[:len(i)] == i: ans |= match(s[len(i):]) return ans S = raw_input() if match(S): print "YES" else: print "NO"
s648416376
p03856
u384094369
1481423366
Python
Python (2.7.6)
py
Runtime Error
16
2692
507
s = raw_input() def func(st): head = st[:8] if head[5:8] == 'dre' or head[5:8] == 'era': return st[5:] elif head[5:8] == 'erd' or head[5:8] == 'ere': return st[7:] elif head[5:8] == 'rdr' or head[5:8] == 'rer': return st[6:] else: return '' while True: if len(t) < 8: if t == 'dream' or t == 'erase' or t == 'dreamer' or t == 'eraser': print 'YES' else: print 'NO' break else: t = func(t)
s760008554
p03856
u384094369
1481423098
Python
Python (2.7.6)
py
Runtime Error
16
2692
541
s = raw_input() def func(st): head = st[:8] if head[5:8] == 'dre' or head[5:8] == 'era': return st[5:] elif head[5:8] == 'erd' or head[5:8] == 'ere': return st[7:] elif head[5:8] == 'rdr' or head[5:8] == 'rer': return st[6:] else: return '' while True: print t if len(t) < 8: if t == 'dream' or t == 'erase' or t == 'dreamer' or t == 'eraser': print 'YES' break else: print 'NO' break else: t = func(t)
s009468810
p03856
u104282757
1481422320
Python
Python (2.7.6)
py
Runtime Error
67
2820
558
S = raw_input() def pick_greedy(S): if S[0:5] == 'dream': if S[5:7] == 'er': if S[7] == 'a': ret = 'dream' else: ret = 'dreamer' else: ret = 'dream' elif S[0:5] == 'erase': if S[5] == 'r': ret = 'eraser' else: ret = 'erase' else: ret = 'no' return ret sol = 'YES' while len(S) > 0: r = pick_greedy(S) if r == 'no': sol = 'NO' break else: S = S[len(r):] print sol
s803118482
p03857
u163907160
1585803329
Python
PyPy3 (2.4.0)
py
Runtime Error
170
38484
897
from collections import * from heapq import * from itertools import * import sys import copy from bisect import * sys.setrecursionlimit(10000000) sys. N,K,L = map(int,input().split()) RoLists=[[] for i in range(N)] RaLists=[[] for _ in range(N)] for i in range(K): p,q=map(int,input().split()) RoLists[p-1].append(q-1) RoLists[q-1].append(p-1) for j in range(L): p,q=map(int,input().split()) RaLists[p-1].append(q-1) RaLists[q-1].append(p-1) def dfs(g, v, visited): if not visited[v]: yield v visited[v] = True for w in iter(g[v]): for x in rdfs(g, w, visited): yield x def r_dfs(g,v): visited = [False] * N for x in dfs(g, v, visited): yield x for i in range(N): ans=0 for h in r_dfs(RoLists,i): for i in r_dfs(RaLists,i): if i == h: ans+=1 print(ans)
s131481297
p03857
u163907160
1585803175
Python
PyPy3 (2.4.0)
py
Runtime Error
1102
91468
862
from collections import * from heapq import * from itertools import * import sys import copy from bisect import * N,K,L = map(int,input().split()) RoLists=[[] for i in range(N)] RaLists=[[] for _ in range(N)] for i in range(K): p,q=map(int,input().split()) RoLists[p-1].append(q-1) RoLists[q-1].append(p-1) for j in range(L): p,q=map(int,input().split()) RaLists[p-1].append(q-1) RaLists[q-1].append(p-1) def dfs(g, v, visited): if not visited[v]: yield v visited[v] = True for w in iter(g[v]): for x in rdfs(g, w, visited): yield x def r_dfs(g,v): visited = [False] * N for x in dfs(g, v, visited): yield x for i in range(N): ans=0 for h in r_dfs(RoLists,i): for i in r_dfs(RaLists,i): if i == h: ans+=1 print(ans)
s786586225
p03857
u547167033
1584480770
Python
Python (3.4.3)
py
Runtime Error
2105
22356
1309
class UnionFind(): def __init__(self,n): self.n=n self.parents=[-1]*n def find(self,x): if self.parents[x] < 0: return x else: self.parents[x]=self.find(self.parents[x]) return self.parents[x] def unite(self,x,y): x = self.find(x) y = self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i,x in enumerate(self.parents) if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n,k,l=map(int,input().split()) uf1=UnionFind(n) uf2=UnionFind(n) for _ in range(k): u,v=map(int,input().split()) uf1.unite(u-1,v-1) for _ in range(k): u,v=map(int,input().split()) uf2.unite(u-1,v-1) ans=[] for i in range(n): x=set(uf1.members(i))&set(uf2.members(i)) ans.append(len(x)) print(*ans)
s298622164
p03857
u547167033
1584480744
Python
PyPy3 (2.4.0)
py
Runtime Error
2114
147052
1308
class UnionFind(): def __init__(self,n): self.n=n self.parents=[-1]*n def find(self,x): if self.parents[x] < 0: return x else: self.parents[x]=self.find(self.parents[x]) return self.parents[x] def unite(self,x,y): x = self.find(x) y = self.find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i)==root] def roots(self): return [i for i,x in enumerate(self.parents) if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} n,k,l=map(int,input().split()) uf1=UnionFind(n) uf2=UnionFind(n) for _ in range(k): u,v=map(int,input().split()) uf1.unite(u-1,v-1) for _ in range(k): u,v=map(int,input().split()) uf2.unite(u-1,v-1) ans=[] for i in range(n): x=set(uf1.members(i))&set(uf2.members(i)) ans.append(len(x)) print(*ans)
s991963021
p03857
u871980676
1584237719
Python
PyPy3 (2.4.0)
py
Runtime Error
1419
134176
1431
from collections import Counter import queue N, K, L = map(int, input().split()) PQ = [tuple(map(int, input().split())) for _ in range(K)] RS = [tuple(map(int, input().split())) for _ in range(L)] road = [set() for _ in range(N)] railroad = [set() for _ in range(N)] for p, q in PQ: road[p - 1].add(q - 1) road[q - 1].add(p - 1) for r, s in RS: railroad[r - 1].add(s - 1) railroad[s - 1].add(r - 1) uf_road = [0] * N uf_railroad = [0] * N idx_road = 1 idx_railroad = 1 # 連結判定 for i in range(N): if uf_road[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() uf_road[now_node] = idx_road for target in road[now_node]: road[target].remove(now_node) if uf_road[target] == 0: q.put(target) #road[now_node] = [] idx_road += 1 if uf_railroad[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() uf_railroad[now_node] = idx_railroad for target in railroad[now_node]: railroad[target].remove(now_node) if uf_railroad[target] == 0: q.put(target) #railroad[now_node] = [] idx_railroad += 1 c = Counter(zip(uf_road,uf_railroad)) res = [c[(i, j)] for i, j in zip(uf_road, uf_railroad)] print(*res)
s040875941
p03857
u871980676
1584219513
Python
PyPy3 (2.4.0)
py
Runtime Error
1151
115360
1369
from collections import defaultdict as dd import queue N, K, L = map(int,input().split()) PQ = [tuple(map(int,input().split())) for _ in range(K)] RS = [tuple(map(int,input().split())) for _ in range(L)] road = [[] for _ in range(N)] railroad = [[] for _ in range(N)] for p,q in PQ: road[p-1].append(q-1) road[q-1].append(p-1) for r,s in RS: railroad[r-1].append(s-1) railroad[s-1].append(r-1) uf_road = [0]*N uf_railroad = [0]*N idx_road = 1 idx_railroad = 1 # 連結判定 for i in range(N): if uf_road[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() uf_road[now_node] = idx_road for target in road[now_node]: road[target].remove(now_node) q.put(target) #if uf_road[target] == 0: # q.put(target) idx_road += 1 if uf_railroad[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() uf_railroad[now_node] = idx_railroad for target in railroad[now_node]: railroad[target].remove(now_node) q.put(target) idx_railroad += 1 dic = dd(int) for i,j in zip(uf_road, uf_railroad): dic[(i,j)] += 1 res = [dic[(i,j)] for i,j in zip(uf_road, uf_railroad)] print(*res)
s843748836
p03857
u511379665
1576359049
Python
Python (3.4.3)
py
Runtime Error
585
18504
1218
#temp class Uf: def __init__(self, N): self.p = list(range(N)) self.rank = [0] * N self.size = [1] * N def root(self, x): if self.p[x] != x: self.p[x] = self.root(self.p[x]) return self.p[x] def same(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): u = self.root(x) v = self.root(y) if u == v: return if self.rank[u] < self.rank[v]: self.p[u] = v self.size[v] += self.size[u] self.size[u] = 0 else: self.p[v] = u self.size[u] += self.size[v] self.size[v] = 0 if self.rank[u] == self.rank[v]: self.rank[u] += 1 def count(self, x): return self.size[self.root(x)] N,K,L=map(int,input().split()) p=[] q=[] r=[] s=[] for i in range(K): a,b=map(int,input().split()) p.append(a-1) q.append(b-1) for i in range(L): a,b=map(int,input().split()) r.append(a-1) s.append(b-1) road=Uf() train=Uf() for i in range(K): road.unite(p[i],q[i]) for i in range(L): train.unite(r[i],s[i]) ans=[1]*N for i in range(N): r=road.count()
s878615117
p03857
u614314290
1562774728
Python
Python (3.4.3)
py
Runtime Error
2114
171204
1464
N, K, L = list(map(int, input().split())) PQ = [list(map(int, input().split())) for _ in range(K)] RS = [list(map(int, input().split())) for _ in range(L)] def uft_root(g, a): if g[a] < 0: return a g[a] = uft_root(g, g[a]) return g[a] def uft_size(g, a): return -g[uft_root(g, a)] def uft_merge(g, a, b): a, b = uft_root(g, a), uft_root(g, b) if a == b: return size_a, size_b = uft_size(g, a), uft_size(g, b) if size_a < size_b: a, b = b, a size_a, size_b = size_b, size_a g[a] -= size_b g[b] = a g_pq = [[] for _ in range(N)] for p, q in PQ: p, q = p - 1, q - 1 g_pq[p] += [q] g_pq[q] += [p] g_rs = [[] for _ in range(N)] for r, s in RS: r, s = r - 1, s - 1 g_rs[r] += [s] g_rs[s] += [r] def dfs(v, g, uft, visited): if visited[v]: return visited[v] = True for n in g[v]: if visited[n]: continue uft_merge(uft, v, n) dfs(n, g, uft, visited) visited_pq = [False] * N visited_rs = [False] * N uft_pq = [-1] * N uft_rs = [-1] * N for n in range(N): dfs(n, g_pq, uft_pq, visited_pq) dfs(n, g_rs, uft_rs, visited_rs) group_pq, group_rs = {}, {} for n in range(N): root_pq = uft_root(uft_pq, n) if not root_pq in group_pq: group_pq[root_pq] = {n} else: group_pq[root_pq] |= {n} root_rs = uft_root(uft_rs, n) if not root_rs in group_rs: group_rs[root_rs] = {n} else: group_rs[root_rs] |= {n} for n in range(N): print(len(group_pq[uft_root(uft_pq, n)] & group_rs[uft_root(uft_rs, n)]), "", end="") print()
s698142951
p03857
u620480037
1556590851
Python
Python (3.4.3)
py
Runtime Error
2108
45372
1351
import collections import bisect N,K,L=map(int,input().split()) RP=[i for i in range(N+1)] Rsize=[1 for i in range(N+1)] TP=[i for i in range(N+1)] Tsize=[1 for i in range(N+1)] def findR(a): if a==RP[a]: return a else: return findR(RP[a]) def findT(a): if a==TP[a]: return a else: return findT(TP[a]) def unionR(b,c): B=findR(b) C=findR(c) if Rsize[B]>=Rsize[c]: Rsize[B]+=Rsize[C] RP[C]=RP[B] else: Rsize[C]+=Rsize[B] RP[B]=RP[C] def unionT(b,c): B=findT(b) C=findT(c) if Tsize[B]>=Tsize[c]: Tsize[B]+=Tsize[C] TP[C]=TP[B] else: Tsize[C]+=Tsize[B] TP[B]=TP[C] for i in range(K): p,q=map(int,input().split()) if findR(p)==findR(q): pass else: unionR(p,q) for i in range(L): r,s=map(int,input().split()) if findT(r)==findT(s): pass else: unionT(r,s) L=collections.Counter() for i in range(1,N+1): L[findR(i),findT(i)]+=1 #print(L) ANS=L.items() ANS=list(ANS) ANS.sort() K=[] V=[] for i in range(len(ANS)): K.append(ANS[i][0]) V.append(ANS[i][1]) ans=str(V[bisect.bisect_left(K,(findR(1),findT(1)))]) for i in range(2,N+1): ans+=" "+str(V[bisect.bisect_left(K,(findR(i),findT(i)))]) print(ans)
s387574317
p03857
u620480037
1556588203
Python
Python (3.4.3)
py
Runtime Error
2105
33860
1163
import collections N,K,L=map(int,input().split()) RP=[i for i in range(N+1)] Rsize=[1 for i in range(N+1)] TP=[i for i in range(N+1)] Tsize=[1 for i in range(N+1)] def findR(a): if a==RP[a]: return a else: return findR(RP[a]) def findT(a): if a==TP[a]: return a else: return findT(TP[a]) def unionR(b,c): B=findR(b) C=findR(c) if Rsize[B]>=Rsize[c]: Rsize[B]+=Rsize[C] RP[C]=RP[B] else: Rsize[C]+=Rsize[B] RP[B]=RP[C] def unionT(b,c): B=findT(b) C=findT(c) if Tsize[B]>=Tsize[c]: Tsize[B]+=Tsize[C] TP[C]=TP[B] else: Tsize[C]+=Tsize[B] TP[B]=TP[C] for i in range(K): p,q=map(int,input().split()) if findR(p)==findR(q): pass else: unionR(p,q) for i in range(L): r,s=map(int,input().split()) if findT(r)==findT(s): pass else: unionT(r,s) L=collections.defaultdict(int) for i in range(1,N+1): L[findR(i),findT(i)]+=1 ans=str(L[findR(1),findT(1)]) for i in range(2,N+1): ans+=" "+str(L[findR(i),findT(i)]) print(ans)
s408572785
p03857
u623819879
1554958022
Python
PyPy3 (2.4.0)
py
Runtime Error
2035
175308
1233
# coding: utf-8 # Your code here! from collections import Counter from collections import defaultdict n,k,l=map(int,input().split()) p=[0]*(k+1) q=[0]*(k+1) rd=[[] for _ in range(n+1)] r=[0]*(l+1) s=[0]*(l+1) rw=[[] for _ in range(n+1)] for i in range(k): a,b=map(int,input().split()) p[i],q[i]=a,b rd[a].append(b) rd[b].append(a) for i in range(l): a,b=map(int,input().split()) r[i],s[i]=a,b rw[a].append(b) rw[b].append(a) prd=[i for i in range(n+1)] prw=[i for i in range(n+1)] def union(x,y): rx=root(x) ry=root(y) if rx==ry: return p[rx]=ry def root(x): if p[x]==x: return x p[x]=root(p[x]) return p[x] cnt=[[] for _ in range(n+1)] #print(rd) #print(rw) p=prd for i in range(1,n+1): for j in rd[i]: union(i,j) for i in range(1,n+1): rt=root(i) prd[i]=rt cnt[i].append(rt) p=prw for i in range(1,n+1): for j in rw[i]: union(i,j) for i in range(1,n+1): rt=root(i) prw[i]=rt cnt[i].append(rt) #print(cnt) #c=Counter(cnt) dc=defaultdict(int) for i in cnt: dc[','.join([str(c) for c in i])] += 1 #for i in range(n+1): print(*[dc[','.join([str(c) for c in cnt[i]])] for i in range(1,n+1)])
s423804468
p03857
u555962250
1553882839
Python
Python (3.4.3)
py
Runtime Error
18
2940
1129
#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; const int MAX_N = 200001; int par[MAX_N]; int rnk[MAX_N]; void init(int n) { rep(i,n) { par[i] = i; rnk[i] = 0; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } void solve() { int N, K, L, p, q; cin >> N >> K >> L; init(N); rep(i,K) { cin >> p >> q; unite(p - 1, q - 1); } int roads[N]; rep(i,N) roads[i] = find(i); init(N); rep(i,L) { cin >> p >> q; unite(p - 1, q - 1); } map<pair<int, int>, int> d; rep(i,N) d[make_pair(roads[i], find(i))]++; rep(i,N) cout << d[make_pair(roads[i], find(i))] << " "; cout << endl; return; } int main() { solve(); }
s201661126
p03857
u543954314
1553093911
Python
Python (3.4.3)
py
Runtime Error
2106
54692
605
from collections import defaultdict as dd road = dd(list) train = dd(list) def gr(tree,start): island = set() rest = [start,] while rest: node = rest.pop() island.add(node) for x in tree[node]: if x not in island: rest.append(x) return(island) n,k,l = map(int, input().split()) for _ in range(k): a,b = map(int,input().split()) road[a].append(b) road[b].append(a) for _ in range(k): a,b = map(int,input().split()) train[a].append(b) train[b].append(a) for i in range(1,n+1): print(len(gr(road,i)&gr(train,i)))
s444582550
p03857
u572144347
1551637556
Python
PyPy3 (2.4.0)
py
Runtime Error
2860
141288
1383
N,K,L = map(int, input().split()) class UFT: def __init__(self, N): self.UFdata = [-1] * (N+1) self.rank = [0] * (N+1) def find(self,x): UFdata = self.UFdata while UFdata[x] != -1: x = UFdata[x] return x def unite(self,x,y): UFdata = self.UFdata rank = self.rank find = self.find x = find(x) y = find(y) if x != y: if rank[x] < rank[y]: x,y = y,x if rank[x] == rank[y]: rank[x] += 1 UFdata[y] = x UF1 = UFT(N) UF2 = UFT(N) ans = [1] * (N+1) MAP= [ [0] * (N+1) for _ in range(N+1)] import sys input = sys.stdin.readline #PQ = [ [int(j) for j in input().split()] for _ in range(K)] #RS = [ [int(j) for j in input().split()] for _ in range(L)] for i in range(K): p,q = map(int,input().split()) UF1.unite(p,q) for i in range(L): p,q = map(int,input().split())#RS[i] UF2.unite(p, q) counter=[] from collections import defaultdict cntdic =defaultdict(int) for i in range(1,N+1): counter.append(UF1.find(i)+UF2.find(i)*10**6) cntdic[counter[-1]]+=1 ans = [0]*(N+1) for i in range(1,N+1): ans[i] = cntdic[UF1.find(i)+UF2.find(i)*10**6] del ans[0] # print(" ".join( map(lambda x: str(x), connected_num[1:]))) print(" ".join( map(lambda x: str(x), ans)))
s984511053
p03857
u572144347
1551637038
Python
PyPy3 (2.4.0)
py
Runtime Error
2545
149100
1320
N,K,L = map(int, input().split()) class UFT: def __init__(self, N): self.UFdata = [-1] * (N+1) self.rank = [0] * (N+1) def find(self,x): UFdata = self.UFdata while UFdata[x] != -1: x = UFdata[x] return x def unite(self,x,y): UFdata = self.UFdata rank = self.rank find = self.find x = find(x) y = find(y) if x != y: if rank[x] < rank[y]: x,y = y,x if rank[x] == rank[y]: rank[x] += 1 UFdata[y] = x UF1 = UFT(N) UF2 = UFT(N) ans = [1] * (N+1) MAP= [ [0] * (N+1) for _ in range(N+1)] import sys input = sys.stdin.readline PQ = [ [int(j) for j in input().split()] for _ in range(K)] RS = [ [int(j) for j in input().split()] for _ in range(L)] for i in range(K): p,q = PQ[i] UF1.unite(p,q) for i in range(L): p,q = RS[i] UF2.unite(p, q) counter=[] from collections import defaultdict cntdic =defaultdict(int) for i in range(1,N+1): counter.append(UF1.find(i)+UF2.find(i)*10**6) cntdic[counter[-1]]+=1 ans = [0]*(N+1) for i in range(1,N+1): ans[i] = cntdic[counter[i-1]] del ans[0] # print(" ".join( map(lambda x: str(x), connected_num[1:]))) print(" ".join( map(lambda x: str(x), ans)))
s735206841
p03857
u572144347
1551637003
Python
PyPy3 (2.4.0)
py
Runtime Error
2321
127716
1318
N,K,L = map(int, input().split()) class UFT: def __init__(self, N): self.UFdata = [-1] * (N+1) self.rank = [0] * (N+1) def find(self,x): UFdata = self.UFdata while UFdata[x] != -1: x = UFdata[x] return x def unite(self,x,y): UFdata = self.UFdata rank = self.rank find = self.find x = find(x) y = find(y) if x != y: if rank[x] < rank[y]: x,y = y,x if rank[x] == rank[y]: rank[x] += 1 UFdata[y] = x UF1 = UFT(N) UF2 = UFT(N) ans = [1] * (N+1) MAP= [ [0] * (N+1) for _ in range(N+1)] import sys input = sys.stdin.readline PQ = [ [int(j) for j in input().split()] for _ in range(K)] RS = [ [int(j) for j in input().split()] for _ in range(L)] for i in range(K): p,q = PQ[i] UF1.unite(p,q) for i in range(L): p,q = RS[i] UF2.unite(p, q) counter=[] from collections import defaultdict cntdic =defaultdict(int) for i in range(1,N+1): counter.append(UF1.find(i)+UF2.find(i)*10**6) cntdic[counter[-1]]+=1 ans = [0]*(N+1) for i in range(1,N+1): ans[i] = cntdic[counter[i]] del ans[0] # print(" ".join( map(lambda x: str(x), connected_num[1:]))) print(" ".join( map(lambda x: str(x), ans)))
s146534942
p03857
u572144347
1551635218
Python
PyPy3 (2.4.0)
py
Runtime Error
2474
149100
1290
N,K,L = map(int, input().split()) class UFT: def __init__(self, N): self.UFdata = [-1] * (N+1) self.rank = [0] * (N+1) def find(self,x): UFdata = self.UFdata while UFdata[x] != -1: x = UFdata[x] return x def unite(self,x,y): UFdata = self.UFdata rank = self.rank find = self.find x = find(x) y = find(y) if x != y: if rank[x] < rank[y]: x,y = y,x if rank[x] == rank[y]: rank[x] += 1 UFdata[y] = x UF1 = UFT(N) UF2 = UFT(N) ans = [1] * (N+1) MAP= [ [0] * (N+1) for _ in range(N+1)] import sys input = sys.stdin.readline PQ = [ [int(j) for j in input().split()] for _ in range(K)] RS = [ [int(j) for j in input().split()] for _ in range(L)] for i in range(K): p,q = PQ[i] UF1.unite(p,q) for i in range(L): p,q = RS[i] UF2.unite(p, q) counter=[] for i in range(1,N+1): counter.append((UF1.find(i),UF2.find(i))) from collections import Counter p=Counter(counter) ans = [0]*(N+1) for i in range(1,N+1): ans[i] = p[(UF1.find(i),UF2.find(i))] del ans[0] # print(" ".join( map(lambda x: str(x), connected_num[1:]))) print(" ".join( map(lambda x: str(x), ans)))
s268348483
p03857
u368780724
1541763988
Python
Python (3.4.3)
py
Runtime Error
2111
144756
861
def inpl(): return [int(i) for i in input().split()] def root(x,par): if par[x] == x: return [x,[x]] else: return [root(par[x],par)[0],root(par[x],par)[1]+[x]] N, K, L = inpl() parK = list(range(N)) for i in range(K): p, q = inpl() rp = root(p-1,parK) rq = root(q-1,parK) if len(rp[1]) < len(rq[1]) : parK[rq[0]] = rp[0] else: parK[rp[0]] = rq[0] print(parK) parL = list(range(N)) for i in range(L): r, s = inpl() rr = root(r-1,parL) rs = root(s-1,parL) for i in rr[1]: parL[i] = rr[0] for j in rs[1]: parL[j] = rr[0] from collections import defaultdict ans = defaultdict(lambda: 0) for i in range(N): ans[root(i,parK)[0],root(i,parL)[0]] +=1 Ans = [0 for _ in range(N)] for i in range(N): Ans[i] = ans[root(i,parK)[0],root(i,parL)[0]] print(*Ans)
s258207166
p03857
u631277801
1541642946
Python
Python (3.4.3)
py
Runtime Error
2113
178360
2005
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) 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()) class UnionFind: def __init__(self, node:int) -> None: self.n = node self.par = [i for i in range(self.n)] self.rank = [0 for i in range(self.n)] def find(self, x:int) -> int: if x == self.par[x]: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x:int, y:int) -> bool: if self.isSame(x,y): #print("x and y has already united") return False rx = self.find(x) ry = self.find(y) if self.rank[rx] < self.rank[ry]: self.par[rx] = self.par[ry] else: self.par[ry] = self.par[rx] if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 return True def isSame(self, x:int, y:int) -> bool: return self.find(x) == self.find(y) n,k,l = li() pq = [] rs = [] for _ in range(k): pq.append(tuple(li_())) for _ in range(l): rs.append(tuple(li_())) road = UnionFind(n) rail = UnionFind(n) for p,q in pq: road.unite(p,q) for r,s in rs: rail.unite(r,s) for i in range(k): road.find(i) for i in range(l): rail.find(i) road_dic = {i:set() for i in range(n)} rail_dic = {i:set() for i in range(n)} for i in range(n): road_dic[road.par[i]].add(i) rail_dic[rail.par[i]].add(i) ans = [] for i in range(n): ans.append(len(road_dic[road.par[i]] & rail_dic[rail.par[i]])) print(*ans)
s827502756
p03857
u593005350
1538517460
Python
Python (3.4.3)
py
Runtime Error
2108
50180
762
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,0) add(1,0) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
s755212214
p03857
u593005350
1538510398
Python
Python (3.4.3)
py
Runtime Error
2107
50180
754
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,n) add(1,n) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
s402173539
p03857
u593005350
1538510367
Python
Python (3.4.3)
py
Runtime Error
17
3064
757
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,n) add(1,n) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
s967387062
p03857
u593005350
1538510276
Python
Python (3.4.3)
py
Runtime Error
17
3064
754
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,n) add(1,n) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
s975379205
p03857
u593005350
1538495563
Python
Python (3.4.3)
py
Runtime Error
1630
51244
728
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) add(0,0) add(1,0) n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
s583001799
p03857
u075012704
1531319374
Python
Python (3.4.3)
py
Runtime Error
18
2940
1526
v\from collections import defaultdict N, K, L = map(int, input().split()) class UnionFind: def __init__(self, n): self.par = [i for i in range(n)] self.rank = [0] * n self.size = [1] * 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 self.size[y] += self.size[x] self.size[x] = 0 else: self.par[y] = x self.size[x] += self.size[y] self.size[y] = 0 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) UF1 = UnionFind(N) UF2 = UnionFind(N) for k in range(K): p, q = map(int, input().split()) p, q = p-1, q-1 UF1.union(p, q) for l in range(L): r, s = map(int, input().split()) r, s = r-1, s-1 UF2.union(r, s) UF1.all_find() UF2.all_find() D = defaultdict(int) for p1, p2 in zip(UF1.par, UF2.par): D[(p1, p2)] += 1 ans = [D[(p1, p2)] for p1, p2 in zip(UF1.par, UF2.par)] print(*ans)
s955279269
p03857
u098968285
1496162666
Python
PyPy3 (2.4.0)
py
Runtime Error
187
41328
1367
# 頂点 v の所属するグループを調べる def root(v): if uni[v] < 0: # v が親の場合 return v else: # v が子の場合 uni[v] = root(uni[v]) # 親のrootを調べる return uni[v] # 頂点 a と頂点 b をつなぐ。もともと同じグループのとき、False を返す def connect(a, b): # まずはそれぞれ根の番号に置き換える ra = root(a) rb = root(b) if ra == rb: # a と b がそもそも同じグループに属しているなら即終了 return False # ra を大きなグループにしたいので、逆であれば入れ替える if uni[ra] > uni[rb]: # rbの方が要素数が多ければ tmp = ra ra = rb rb = tmp # ra と rb を結合し、rb の親を ra とする uni[ra] += uni[rb] uni[rb] = ra return True ## N, K, L = map(int, input().split()) road = [-1]*(N+1) rail = [-1]*(N+1) for i in range(K): a, b = map(int, input().split()) connect(a, b, road) for i in range(L): a, b = map(int, input().split()) connect(a, b, rail) ## dp = [0]*(N+1) for i in range(1, N+1): dp[i] = (root(i, road), root(i, rail)) dic = {} for i in range(1, N+1): key = dp[i] if key not in dic: dic[key] = 1 else: dic[key] += 1 for i in range(1, N+1): ans = dic[dp[i]] if i == N: print(ans) else: print(ans, end=" ")
s692248673
p03857
u132291455
1481426980
Python
PyPy2 (5.6.0)
py
Runtime Error
706
111644
794
n,k,l=map(int,raw_input().split()) e1=[[] for i in range(n)] e2=[[] for i in range(n)] for i in range(k): p,q=map(int,raw_input().split()) e1[p-1].append(q-1) e1[q-1].append(p-1) for i in range(l): p,q=map(int,raw_input().split()) e2[p-1].append(q-1) e2[q-1].append(p-1) num1=[0]*n num2=[0]*n def dfs1(x,i): num1[x]=i for node in e1[x]: if num1[node]==0:dfs1(node,i) def dfs2(x,i): num2[x]=i for node in e2[x]: if num2[node]==0:dfs2(node,i) cnt1=1 cnt2=1 for x in range(n): if num1[x]==0:dfs1(x,cnt1);cnt1+=1 if num2[x]==0:dfs2(x,cnt2);cnt2+=1 dic={} for x in range(n): t=(num1[x],num2[x]) if t in dic:dic[t]+=1 else:dic[t]=1 ans=[0]*n for x in range(n): ans[x]=dic[(num1[x],num2[x])] print ' '.join(map(str,ans))
s959125805
p03857
u123756661
1481426841
Python
Python (2.7.6)
py
Runtime Error
16
2824
2338
#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys import re import math import itertools import collections import bisect #sys.stdin=file('input.txt') #sys.stdout=file('output.txt','w') #10**9+7 mod=1000000007 #mod=1777777777 pi=3.141592653589 IS=float('inf') xy=[(1,0),(-1,0),(0,1),(0,-1)] bs=[(-1,-1),(-1,1),(1,1),(1,-1)] def niten(a,b): return abs(a-b) if a>=0 and b>=0 else a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b)) def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)] def gcd(a,b): return a if b==0 else gcd(b,a%b) def lcm(a,b): return a*b/gcd(a,b) def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5 def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0 def pscl(num,l=[1]): for i in range(num): l = map(lambda x,y:x+y,[0]+l,l+[0]) return l class UnionFind: def __init__(self, size): self.rank=[0]*size self.par =range(size) self.grp =size def find(self, x): if x==self.par[x]: return x self.par[x]=self.find(self.par[x]) return self.par[x] def same(self, x, y): #2つの頂点が同じグループであるかを判定する return self.find(x)==self.find(y) def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する x,y=self.find(x),self.find(y) if x==y: return self.grp-=1 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 group_num(self): return self.grp def ra(self): return self.rank n,k,l=map(int,raw_input().split()) uf=UnionFind(n) q1,q2=[],[] ans=[0]*n for i in range(k): a,b=map(int,raw_input().split()) uf.unite(a-1,b-1) q1.append((a-1,b-1)) ans[a-1]=1 ans[b-1]=1 for i in range(l): a,b=map(int,raw_input().split()) uf2.unite(a-1,b-1) if ans[a-1]==0: ans[a-1]=1 if ans[b-1]==0: ans[b-1]=1 if uf.same(a-1,b-1): ans[a-1]=2 ans[b-1]=2 uf2=UnionFind(n) for i in q2: uf2.unite(i[0],i[1]) for i in q1: if uf2.find(i[[0],i[1]): ans[i[0]]=2 ans[i[1]]=2 print ' '.join(map(str,ans))
s519593761
p03857
u104282757
1481425290
Python
Python (2.7.6)
py
Runtime Error
18
2696
1685
# N K L # p1 q1 # : # pK qK # r1 s1 # : # rL sL import numpy as np N, K, L = map(int, raw_input().split()) # graph Gp = dict() Gq = dict() # conn. components p_con_todo = [] q_con_todo = [] # init for n in range(1, N+1): p_con_todo.append(str(n)) q_con_todo.append(str(n)) Gp[str(n)] = [] Gq[str(n)] = [] p_con_ids = np.zeros(N, dtype='int') q_con_ids = np.zeros(N, dtype='int') # input for _ in range(K): p, q = map(int, raw_input().split()) Gp[str(p)].append(str(q)) Gp[str(q)].append(str(p)) for _ in range(L): p, q = map(int, raw_input().split()) Gq[str(p)].append(str(q)) Gq[str(q)].append(str(p)) # DFS p_con_id = 0 while len(p_con_todo) > 0: p_con_id += 1 ques = [p_con_todo[0]] conn = [] while len(ques) > 0: n = ques.pop() conn.append(n) p_con_ids[int(n)-1] = p_con_id for m in Gp[n]: if m in conn: pass else: ques.append(m) p_con_todo = [n for n in p_con_todo if n not in conn] # DFS q_con_id = 0 while len(q_con_todo) > 0: q_con_id += 1 ques = [q_con_todo[0]] conn = [] while len(ques) > 0: n = ques.pop() conn.append(n) q_con_ids[int(n)-1] = q_con_id for m in Gq[n]: if m in conn: pass else: ques.append(m) q_con_todo = [n for n in q_con_todo if n not in conn] # print p_con_ids # print q_con_ids # print anser res_list = [] for n in range(N): res = int(np.ones(N)[p_con_ids = p_con_ids[n] and q_con_ids == q_con_ids[n]]) res_list.append(str(res)) # print res_list print " ".join(res_list)
s199902618
p03857
u123756661
1481424934
Python
Python (2.7.6)
py
Runtime Error
974
23840
2998
#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys import re import math import itertools import collections import bisect #sys.stdin=file('input.txt') #sys.stdout=file('output.txt','w') #10**9+7 mod=1000000007 #mod=1777777777 pi=3.141592653589 IS=float('inf') xy=[(1,0),(-1,0),(0,1),(0,-1)] bs=[(-1,-1),(-1,1),(1,1),(1,-1)] def niten(a,b): return abs(a-b) if a>=0 and b>=0 else a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b)) def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)] def gcd(a,b): return a if b==0 else gcd(b,a%b) def lcm(a,b): return a*b/gcd(a,b) def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5 def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0 def pscl(num,l=[1]): for i in range(num): l = map(lambda x,y:x+y,[0]+l,l+[0]) return l class UnionFind: def __init__(self, size): self.rank=[0]*size self.par =range(size) self.grp =size def find(self, x): if x==self.par[x]: return x self.par[x]=self.find(self.par[x]) return self.par[x] def same(self, x, y): #2つの頂点が同じグループであるかを判定する return self.find(x)==self.find(y) def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する x,y=self.find(x),self.find(y) if x==y: return self.grp-=1 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 group_num(self): return self.grp def ra(self,x): return self.rank[x] class UnionFind2: def __init__(self, size): self.rank=[0]*size self.par =range(size) self.grp =size def find(self, x): if x==self.par[x]: return x self.par[x]=self.find(self.par[x]) return self.par[x] def same(self, x, y): #2つの頂点が同じグループであるかを判定する return self.find(x)==self.find(y) def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する x,y=self.find(x),self.find(y) if x==y: return self.grp-=1 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 group_num(self): return self.grp def ra(self,x): return self.rank[x] n,k,l=map(int,raw_input().split()) uf=UnionFind(n) uf2=UnionFind2(n) for i in range(k): a,b=map(int,raw_input().split()) uf.unite(a-1,b-1) for i in range(l): a,b=map(int,raw_input().split()) uf2.unite(a-1,b-1) ans=[] for i in range(n): tmp=0 if uf.rank(i): tmp+=1 if uf2.rank(i): tmp+=1 ans.append(tmp) print ' '.join(map(str,ans))
s067297599
p03858
u340781749
1481430255
Python
Python (3.4.3)
py
Runtime Error
2720
37016
701
import numpy as np n, a, b = map(int, input().split()) holes = np.fromiter((complex(*map(int, input().split())) for _ in range(n)), dtype=complex) ab = holes[a - 1] - holes[b - 1] d = abs(ab.real) + abs(ab.imag) links = [set() for _ in range(n)] for i in range(0, n, 10000): xy1, xy2 = np.meshgrid(holes, holes[i:i + 10000]) diff = xy1 - xy2 dists = abs(diff.real) + abs(diff.imag) for x, y in zip(*np.where(dists == d)): links[x].add(y) visited = set() queue = [a - 1] while queue: p = queue.pop() if p in visited: continue visited.add(p) queue.extend(q for q in links[p] if q not in visited) print(sum(p < q for p in visited for q in links[p]))
s395047383
p03858
u340781749
1481427511
Python
Python (3.4.3)
py
Runtime Error
655
14472
604
import numpy as np n, a, b = map(int, input().split()) holes = np.fromiter((complex(*map(int, input().split())) for _ in range(n)), dtype=complex) xy1, xy2 = np.meshgrid(holes, holes) diff = xy1 - xy2 dists = abs(diff.real) + abs(diff.imag) d = dists[a - 1][b - 1] w = np.where(dists == d) links = [set() for _ in range(n)] for x, y in zip(*w): links[x].add(y) visited = set() queue = [a - 1] while queue: p = queue.pop() if p in visited: continue visited.add(p) queue.extend(q for q in links[p] if q not in visited) print(sum(p < q for p in visited for q in links[p]))
s941355240
p03859
u231905444
1601025314
Python
Python (3.8.2)
py
Runtime Error
26
9016
1368
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; typedef long long ll; const int MOD = (int)1e9 + 7; int add(int x, int y) { x += y; if (x >= MOD) return x - MOD; return x; } int sub(int x, int y) { x -= y; if (x < 0) return x + MOD; return x; } int mult(int x, int y) { return ((ll)x * y) % MOD; } const int N = 3030; int n; char s[N]; int a[N]; int b[N]; int dp[N][N]; int C[N][N]; void read() { int m; scanf("%d%d", &n, &m); scanf(" %s ", s); for (int i = 0; i < n; i++) a[i] = (int)(s[i] - '0'); for (int i = 0; i < n; i++) b[i] = i + 1; while(m--) { int l, r; scanf("%d%d", &l, &r); l--; b[l] = max(b[l], r); } for (int i = 1; i < n; i++) b[i] = max(b[i], b[i - 1]); } int main() { read(); for (int i = 0; i < N; i++) C[i][0] = C[i][i] = 1; for (int i = 1; i < N; i++) for (int j = 1; j < i; j++) C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]); dp[0][0] = 1; int cur = 0; for (int i = 0; i < n; i++) { int willAdd = 0; while(cur < b[i]) { willAdd += a[cur]; cur++; } for (int x = 0; x <= n; x++) { if (dp[i][x] == 0) continue; int y = x + willAdd; if (y != 0) dp[i + 1][y - 1] = add(dp[i + 1][y - 1], dp[i][x]); if (y != cur - i) dp[i + 1][y] = add(dp[i + 1][y], dp[i][x]); } } printf("%d\n", dp[n][0]); return 0; }
s190019081
p03859
u638456847
1563745429
Python
Python (3.4.3)
py
Runtime Error
17
3188
1918
class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) self.size = [1] * (n+1) # 譬ケ繧呈、懃エ「縺吶k髢「謨ー def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.find(self.par[x]) # 邨仙粋(unite)縺吶k髢「謨ー def unite(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 self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 蜷後§繧ー繝ォ繝シ繝励↓螻槭☆繧九°繧貞愛螳壹☆繧矩未謨ー def same_check(self, x, y): return self.find(x) == self.find(y) # 隕∫エ縺悟ア槭☆繧区惠縺ョ豺ア縺輔r霑斐☆髢「謨ー def get_depth(self, x): return self.rank[self.find(x)] # 隕∫エ縺悟ア槭☆繧区惠縺ョ繧オ繧、繧コ繧定ソ斐☆髢「謨ー def get_size(self, x): return self.size[self.find(x)] # 繧ー繝ォ繝シ繝玲焚繧定ソ斐☆髢「謨ー def group_sum(self): c = 0 for i in range(len(self.par)): if self.find(i) == i: c += 1 return c if __name__ == "__main__": N,K,L = map(int, input().split()) uf = UnionFind(N) for i in range(K): p, q = [int(i) for i in input().split()] uf.unite(p, q) ans = [1]*N for i in range(L): r, s = [int(i) for i in input().split()] if uf.same_check(r, s): ans[r-1] += 1 ans[s-1] += 1 print(*ans)
s885538403
p03860
u961469795
1601527001
Python
Python (3.8.2)
py
Runtime Error
24
8884
71
arr = list(input().split()) print(arr[0].[0] + arr[1].[0] + arr[2].[0])
s003133000
p03860
u401183062
1601230491
Python
Python (3.8.2)
py
Runtime Error
27
8900
73
string = input() Capital = string[0] print("A" + Capital + "C")
s271428895
p03860
u485349322
1598750924
Python
Python (3.8.2)
py
Runtime Error
27
9128
55
a,b,c=map(int,input().split()) print(len(set([a,b,c])))
s920519231
p03860
u642012866
1598630279
Python
Python (3.8.2)
py
Runtime Error
25
8952
44
print("".join(s[0] for s in input()split()))
s025249183
p03860
u546853743
1598371699
Python
Python (3.8.2)
py
Runtime Error
26
8872
56
a,b,c=map(input.split()) print('A' + b.head+ 'C',sep="")
s745887591
p03860
u310381103
1597728459
Python
Python (3.8.2)
py
Runtime Error
23
9024
50
s=input() ss=s[0] sss=upper(ss) print("A"+sss+"C")
s493035513
p03860
u310381103
1597728407
Python
Python (3.8.2)
py
Runtime Error
24
9088
32
print('A'+upper(input()[0])+'C')
s100833902
p03860
u895918162
1597438148
Python
Python (3.8.2)
py
Runtime Error
28
8936
160
sentence = input() new_sent = sentence.split(" ") acro = "" for i in range(len(new_sent)): for j in range(new_sent[i]): acro += new_sent[i][0] print(acro)
s403349432
p03860
u714104087
1596575881
Python
PyPy3 (7.3.0)
py
Runtime Error
234
73872
60
x = map(int, input().split()) print(x[0][0]+x[1][0]+x[2][0])
s346983682
p03860
u714104087
1596574804
Python
PyPy3 (7.3.0)
py
Runtime Error
111
74668
51
x = map(int, input().split()) print(x[0]+x[1]+x[2])
s999231235
p03860
u714104087
1596574744
Python
PyPy3 (7.3.0)
py
Runtime Error
91
74672
49
x=map(int, input().split()) print(x[0]+x[1]+x[2])
s342286496
p03860
u207767041
1596492904
Python
PyPy3 (7.3.0)
py
Runtime Error
105
74752
90
a,b,c = list(map(int,input().split())) a1 = a//c if a%c else a//c-1 a2 = b//c print(a2-a1)
s253198114
p03860
u207767041
1596492848
Python
PyPy3 (7.3.0)
py
Runtime Error
111
74704
90
a,b,c = list(map(int,input().split())) a1 = a//c if a%x else a//c-1 a2 = b//c print(a2-a1)
s563212109
p03860
u207767041
1596492807
Python
Python (3.8.2)
py
Runtime Error
24
9080
90
a,b,x = list(map(int,input().split())) a1 = a//x if a%x else a//x-1 a2 = b//x print(a2-a1)
s367284191
p03860
u207767041
1596492406
Python
Python (3.8.2)
py
Runtime Error
26
8964
86
a,b,c = list(map(int,input().split())) a = a//c b = b//c if b%x else b//c-1 print(a-b)
s753029884
p03860
u207767041
1596492333
Python
Python (3.8.2)
py
Runtime Error
25
9156
88
a,b,c = list(map(int,input().split())) b = a//c b = b//c if b%c else b//c-1 print(a1-a2)
s334337290
p03860
u207767041
1596492257
Python
Python (3.8.2)
py
Runtime Error
25
8932
67
a,b,c = list(map(str,input().split())) a = a//c b = b//c print(b-a)
s094947237
p03860
u388297793
1596406839
Python
Python (3.8.2)
py
Runtime Error
27
9052
41
a,b,c=imput().split() print('A'+b[0]+'C')
s488581240
p03860
u642528832
1596321661
Python
Python (3.8.2)
py
Runtime Error
23
9080
44
a,b,c = map(input().split()) print(a+b[0]+c)
s229543603
p03860
u099212858
1596147191
Python
Python (3.8.2)
py
Runtime Error
25
9024
52
a, b, c = str(input().split()) print(a[0]+b[0]+c[0])
s029674437
p03860
u684743124
1595739910
Python
Python (3.8.2)
py
Runtime Error
25
9080
51
a,b,x=map(int,input().split()) print(b//x-(a-1)//x)
s393069530
p03860
u684743124
1595739877
Python
Python (3.8.2)
py
Runtime Error
29
9072
51
a,b,x=map(int,input().split()) print(b//x-(a-1)//x)
s558983006
p03860
u487288850
1595635532
Python
Python (3.8.2)
py
Runtime Error
23
8860
44
xs = inpt().split() print("A"+xs[2][0]+"B")
s018411395
p03860
u942280986
1595563280
Python
Python (3.8.2)
py
Runtime Error
21
9164
106
a,b,x=map(int,input().split()) a_p=a//x b_p=b//x if a%x==0: print(b_p-a_p+1) else: print(b_p-a_p)
s884331714
p03860
u414920281
1595540958
Python
PyPy3 (7.3.0)
py
Runtime Error
89
74740
60
a,b,c=map(int,input().split()) ans=a[0]+b[0]+c[0] print(ans)
s312123901
p03860
u898702162
1595380902
Python
Python (3.8.2)
py
Runtime Error
21
8956
42
a = Ab b = Cd c = Ef print(a[0]+b[0]+c[0])
s650752902
p03860
u185806788
1594863447
Python
PyPy3 (7.3.0)
py
Runtime Error
95
74728
53
a,b,c=map(int,input().split()) print(a[0]+b[0]+c[0])
s709315328
p03860
u185806788
1594863413
Python
PyPy3 (7.3.0)
py
Runtime Error
89
74556
58
a,b,c=map(int,input().split()) print("a[0]"+"b[0]"+"c[0]")
s645388218
p03860
u456416458
1594568770
Python
Python (3.8.2)
py
Runtime Error
20
9136
232
s = input().split() a = int(s[0]) b = int(s[1]) x = int(s[2]) def bet_ween(p, q): if p < 0: return 0 else: return (p // q) + 1 fa = bet_ween(a-1, x) fb = bet_ween(b, x) answer = fb - fa print(int(answer))
s937750481
p03860
u534308356
1594180776
Python
Python (3.8.2)
py
Runtime Error
27
9032
62
a, s, c = map(int, input().split()) print(a[0] + s[0] + c[0])
s240512653
p03860
u917558625
1594074955
Python
Python (3.8.2)
py
Runtime Error
23
9100
52
a,b,c=map(int,input().split()) print(a[0]+b[0]+c[0])
s342829062
p03860
u773440446
1593460336
Python
Python (3.8.2)
py
Runtime Error
27
8728
53
a,b,c = input().split() print(a[0],upper(b[0]),c[0])
s470596869
p03860
u773440446
1593460274
Python
PyPy3 (7.3.0)
py
Runtime Error
291
74548
53
a,b,c = input().split() print(upper(a[0],b[0],c[0]))
s438664526
p03860
u710398282
1593023540
Python
Python (3.8.2)
py
Runtime Error
28
8988
53
a, b, c = input().split() print("A", b[1], "C")
s974877803
p03860
u078349616
1592881187
Python
Python (3.8.2)
py
Runtime Error
23
9124
52
A, B, C = map(int, input().split()) print("A"+B+"C")
s329941611
p03860
u492910842
1592684604
Python
PyPy3 (7.3.0)
py
Runtime Error
96
74552
93
s = map(input().split()) print(s[1])s = list(map(str,input().split())) print("A"+s[1][0]+"C")
s567036946
p03860
u729119068
1592495269
Python
Python (3.4.3)
py
Runtime Error
18
3060
70
A = list(input().split) B='' for a in A: B += a[0].upper() print(B)
s576878756
p03860
u445509700
1592399149
Python
Python (3.4.3)
py
Runtime Error
17
2940
35
print(f"A{input().split()[1][0]}C")
s804357120
p03860
u217303170
1592384547
Python
Python (3.4.3)
py
Runtime Error
17
2940
96
import re s = input() x = s[8:-8] print('{}''{}''{}'.format('A', *re.findall('[A-Z]', x), 'C'))
s193553761
p03860
u875608890
1592112171
Python
Python (3.4.3)
py
Runtime Error
17
2940
149
a, b, x = map(int, input().split()) if 1 <= b // x - a // x or (a==b and a % x == 0): res = b // x - a // x + 1 print(res) else: print(0)
s822616101
p03860
u667694979
1591898744
Python
Python (3.4.3)
py
Runtime Error
17
2940
42
a,s,c=input().split() print(a[0+s[0]+c[0])
s601853933
p03860
u685244071
1591630268
Python
Python (3.4.3)
py
Runtime Error
17
2940
75
a = input().split() initial_middle = a[7] print('A'+ initial_middle +'C')
s924628565
p03860
u602972961
1590170149
Python
Python (3.4.3)
py
Runtime Error
17
2940
29
s=input() ptint('A'+s[8]+'C')