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
s278947851
p02239
u824204304
1454411939
Python
Python
py
Runtime Error
0
0
555
n = int(raw_input()) G = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] dis = [1000 for i in range(n)] dis[0] = 0 for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): a[G[0]-1][G[2+j]-1] = 1 def bfs_visit(s): for k in range(n): if a[s][k] == 1: if dis[k] > dis[s] + 1: dis[k] = dis[s] + 1 bfs_visit(k) for s in range(n): bfs_visit(s) for s in range(n): if dis[s] == 1000: dis[s] = -1 for s in range(n): print'{0} {1}'.format(s+1, d[s])
s275965396
p02239
u824204304
1454412145
Python
Python
py
Runtime Error
0
0
544
n = int(raw_input()) G = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] dis = [10000 for i in range(n)] dis[0] = 0 for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): a[G[0]-1][G[2+j]-1] = 1 def bfs_visit(s): for k in range(n): if a[s][k] == 1: if dis[k] > dis[s] + 1: dis[k] = dis[s] + 1 bfs_visit(k) for s in range(n): bfs_visit(s) for s in range(n): if dis[s] == 10000: dis[s] = -1 for s in range(n): print (s+1, d[s])
s732959015
p02239
u824204304
1454412333
Python
Python
py
Runtime Error
0
0
547
n = int(raw_input()) G = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] dis = [99999 for i in range(n)] dis[0] = 0 def bfs_visit(s): for k in range(n): if a[s][k] == 1: if dis[k] > dis[s] + 1: dis[k] = dis[s] + 1 bfs_visit(k) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): a[G[0]-1][G[2+j]-1] = 1 for s in range(n): bfs_visit(s) for s in range(n): if dis[s] == 99999: dis[s] = -1 for s in range(n): print (s+1, d[s])
s532606359
p02239
u824204304
1454412362
Python
Python
py
Runtime Error
0
0
545
n = int(raw_input()) G = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] dis = [99999 for i in range(n)] def bfs_visit(s): for k in range(n): if a[s][k] == 1: if dis[k] > dis[s] + 1: dis[k] = dis[s] + 1 bfs_visit(k) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): a[G[0]-1][G[2+j]-1] = 1 dis[0] = 0 for s in range(n): bfs_visit(s) for s in range(n): if dis[s] == 99999: dis[s] = -1 for s in range(n): print (s+1, d[s])
s084587989
p02239
u824204304
1454412936
Python
Python
py
Runtime Error
0
0
545
n = int(raw_input()) G = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] dis = [99999 for i in range(n)] def bfs_visit(s): for k in range(n): if a[s][k] == 1: if dis[k] > dis[s] + 1: dis[k] = dis[s] + 1 bfs_visit(k) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): a[G[0]-1][G[2+j]-1] = 1 dis[0] = 0 for s in range(n): bfs_visit(s) for s in range(n): if dis[s] == 99999: dis[s] = -1 for s in range(n): print (s+1, d[s])
s298431098
p02239
u824204304
1454414225
Python
Python
py
Runtime Error
0
0
521
nn = int(raw_input()) dis = [99999 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] def BFS(s): for e in range(n): if v[s][e] == 1: if dis[e] > dis[s] + 1: d[e] = d[s]+1 BFS(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): v[G[0]-1][G[2+j]-1] = 1 dis[0] = 0 for s in range(n): BFS(s) for s in range(n): if dis[s] == 99999: dis[s] = -1 for s in range(n): print'{0} {1}'.format(s+1, dis[s])
s358205956
p02239
u824204304
1454414235
Python
Python
py
Runtime Error
0
0
520
n = int(raw_input()) dis = [99999 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] def BFS(s): for e in range(n): if v[s][e] == 1: if dis[e] > dis[s] + 1: d[e] = d[s]+1 BFS(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): v[G[0]-1][G[2+j]-1] = 1 dis[0] = 0 for s in range(n): BFS(s) for s in range(n): if dis[s] == 99999: dis[s] = -1 for s in range(n): print'{0} {1}'.format(s+1, dis[s])
s569936696
p02239
u393769849
1454415972
Python
Python
py
Runtime Error
0
0
629
n = int(raw_input()) d = [99999 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): for e in range(n): if M[s][e] == 1: if d[e] > d[s] + 1: d[e] = d[s]+1 BFS(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 d[0] = 0 for s in range(n): BFS(s) for s in range(n): if d[s] == 99999: d[s] = -1 for s in range(n): print'{0} {1}'.format(s+1, d[s]) Compile Error Logs: You are not authorized to see the message.
s544894715
p02239
u970436839
1454420249
Python
Python
py
Runtime Error
0
0
434
n = input() d = [1000 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): q = [] q.append(s) d[s] = 0 while q.length != 0: u = q.pop() for v in range(n): if M[u][v] == 0 and d[v] != 1000: d[v] = d[u] + 1 q.push(v) for i in range(n): print i+1, d[i] for i in range(n): G = map(int, raw_input().split()) for j in range(X[1]): M[G[0]-1][G[2+j]-1] = 1 BFS()
s052193529
p02239
u970436839
1454420296
Python
Python
py
Runtime Error
0
0
434
n = input() d = [1000 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): q = [] q.append(s) d[s] = 0 while q.length != 0: u = q.pop() for v in range(n): if M[u][v] == 0 and d[v] != 1000: d[v] = d[u] + 1 q.push(v) for i in range(n): print i+1, d[i] for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 BFS()
s193285779
p02239
u970436839
1454420461
Python
Python
py
Runtime Error
0
0
435
n = input() d = [1000 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): q = [] q.append(s) d[s] = 0 while q.length != 0: u = q.pop() for v in range(n): if M[u][v] == 0 and d[v] != 1000: d[v] = d[u] + 1 q.push(v) for i in range(n): print i+1, d[i] for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 BFS(0)
s570758023
p02239
u970436839
1454420518
Python
Python
py
Runtime Error
0
0
438
n = input() d = [1000 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): q = [] q.append(s) d[s] = 0 while q.length != 0: u = q.pop(0) for v in range(n): if M[u][v] == 0 and d[v] != 1000: d[v] = d[u] + 1 q.append(v) for i in range(n): print i+1, d[i] for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 BFS(0)
s375226920
p02239
u970436839
1454420819
Python
Python
py
Runtime Error
0
0
451
n = input() d = [1000 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] def BFS(s): q = [] q.append(s) d[s] = 0 while q.length != 0: u = q[0] q.pop(0) for v in range(n): if M[u][v] == 0 and d[v] != 1000: d[v] = d[u] + 1 q.append(v) for i in range(n): print i+1, d[i] for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): M[G[0]-1][G[2+j]-1] = 1 BFS(0)
s698681200
p02239
u038243492
1454422831
Python
Python
py
Runtime Error
0
0
1151
n = int(raw_input()) d = [100 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] def Bread(s): for e in range(n): if v[s][e] == 1: if d[e] > d[s] + 1: d[e] = d[s]+1 Bread(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): v[G[0]-1][G[j+2]-1] = 1 d[0] = 0 for i in range(n): Bread(i) for i in range(n): if d[i] == 100: d[i] = -1 for i in range(n): print i+1, d[i] Compile Error Logs: You are not authorized to see the message. Status Judge: 8/8 Python CPU: 00.04 sec Memory: 6492 KB Length: 531 B 2016-02-02 22:02 2016-02-02 22:02 Results for testcases Case # Verdict CPU Time Memory In Out Case Name Case #1: : Accepted 00.01 sec 6476 KB 40 B 26 B 1.in Case #2: : Accepted 00.00 sec 6280 KB 20 B 12 B 2.in Case #3: : Accepted 00.00 sec 6472 KB 75 B 41 B 3.in Case #4: : Accepted 00.00 sec 6304 KB 62 B 20 B 4.in Case #5: : Accepted 00.00 sec 6320 KB 158 B 96 B 5.in Case #6: : Accepted 00.00 sec 6364 KB 355 B 152 B 6.in Case #7:
s035543587
p02239
u072053884
1463648513
Python
Python3
py
Runtime Error
50
7572
355
n = int(input()) adj = [None] for i in range(n): adj_i = list(map(int, input().split()[2:])) adj.append(adj_i) distance = [None] + [-1] * n def bfs(u, d): pd = distance[u] if pd == -1 or d < pd: distance[u] = d for v in adj[u]: bfs(v, d + 1) bfs(1, 0) for i, d in enumerate(distance[1:], start=1): print(i, d)
s292481894
p02239
u569960318
1467873996
Python
Python3
py
Runtime Error
30
7688
326
def BFS(G): ans = [0] + [[i+1,-1] for i in range(len(G))] def main(G,i,d): ans[i] = [i, d] for j in G[i-1][2:]: main(G,j,d+1) main(G,1,0) return ans[1:] if __name__=='__main__': n = int(input()) G = [list(map(int,input().split())) for _ in range(n)] for out in BFS(G): print(*out)
s273750465
p02239
u112247126
1488511277
Python
Python3
py
Runtime Error
0
0
718
from collections import deque def bfs(root): Q = deque() distance[root] = 0 Q.append(root) i = root while len(Q) > 0: for v in n: if adjMat[i][v] == 1 and color[v] == 'white': Q.append(v) color[v] = 'gray' distance[v] = distance[i] + 1 color[i] = 'black' i = Q.popleft() n = int(input()) adjMat = [[0] * n for _ in range(n)] color = ['white'] * n distance = [-1] * n for _ in range(n): adj = list(map(int, input().split())) i = adj[0] v = adj[2:] for j in v: adjMat[i - 1][j - 1] = 1 bfs(0) for i in range(n): out = '' out += '{} {}'.format(i + 1, distance[i]) print(out)
s515148989
p02239
u426534722
1499533833
Python
Python3
py
Runtime Error
0
0
429
from sys import stdin from collections import deque n = int(input()) d = [-1] * (n + 1) def bfs(): d[1] = 0 dq = deque([1]) while len(dq) != 0: v = dq.popleft() for c in G[v]: if d[c] != -1 : continue d[c] = d[v] + 1 dq.append(c) for i, x in enumerate(d[1:], start=1): print(i, x) G = [0] + [list(map(int, inpput().split()[2:])) for i in range(n)] bfs()
s261952728
p02239
u193453446
1504772868
Python
Python3
py
Runtime Error
20
7680
611
def srch(i, l, Lng, Dst): if Lng[i] > l: Lng[i] = l if Dst[i] is not None and len(Dst[i]) > 0: for c in Dst[i]: srch(c,l+1, Lng, Dst) def main(): num = int(input()) Dst = [None for i in range(num + 1)] Lng = [999] * (num + 1) for n in range(1, num+1): a = list(map(int,input().split())) u = a[0] if a[1] > 0: Dst[u] = a[2:] srch(1, 0, Lng, Dst) for n in range(1, num+1): l = Lng[n] if l > num: l = -1 print("{} {}".format(n,l)) if __name__ == '__main__': main()
s589354271
p02239
u845643816
1512130397
Python
Python3
py
Runtime Error
0
0
563
n = int(input()) a = [[] for i in range(n)] for i in range(n): v = list(map(int, input().split())) u = v[0] - 1 for j in v[2:]: a[u].append(j-1) d = [0] * n isDiscovered = [False] * n def bfs(x): global time_stamp isDiscovered [x] = True time_stamp += 1 for i in a[x]: if not isDiscovered[i]: d[i] = d[x] + 1 bfs(0) d_ = 1 while not(isDiscovered == [True] * n): for i in range(n): if d[i] is d_ and not isDiscovered[i]: bfs(i) d_ += 1 for i in range(n): print(i+1, d[i])
s712352296
p02239
u845643816
1512130719
Python
Python3
py
Runtime Error
0
0
572
n = int(input()) a = [[] for i in range(n)] for i in range(n): v = list(map(int, input().split())) u = v[0] - 1 for j in v[2:]: a[u].append(j-1) d = [0] * n isDiscovered = [False] * n def bfs(x): global time_stamp time_stamp += 1 for i in a[x]: if not isDiscovered[i]: isDiscovered [i] = True d[i] = d[x] + 1 bfs(0) d_ = 1 isDiscovered [0] = True while not(isDiscovered == [True] * n): for i in range(n): if d[i] is d_ : bfs(i) d_ += 1 for i in range(n): print(i+1, d[i])
s492161298
p02239
u089116225
1528877926
Python
Python3
py
Runtime Error
0
0
547
m = [[0 for _ in range(n+1)] for _ in range(n+1)] mm = [[] for _ in range(n+1)] n = int(input()) for _ in range(n): tmp = [int(x) for x in input().split()] u,k,l = tmp[0],tmp[1],tmp[2:] mm[u] += tmp[2:] for x in l: m[u][x] = 1 dp = [float('inf') for _ in range(n+1)] queue = [1] while queue: t = queue.pop(0) for x in mm[t]: if dp[x] > dp[t] + 1: dp[x] = dp[t] + 1 queue.append(x) else: pass for i,x in enumerate(queue): if i == 0: pass else: if x == float('inf'): print(i, -1) else: print(i, x)
s020491537
p02239
u782850731
1380697979
Python
Python
py
Runtime Error
0
0
562
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin from Queue import Queue def main(): num = int(stdin.readline()) L = [] for _ in xrange(num): L.append([int(s) for s in stdin.readline().split()[2:]]) d = [-1] * num d[0] = 0 q = Queue()javascript:void(0) q.put(0) while not q.empty(): u = q.get() for v in L[u]: if d[v-1] < 0: d[v-1] = d[u] + 1 q.put(v-1) for i, v in enumerate(d): print(i+1, v) main()
s091980846
p02240
u255317651
1531534343
Python
Python3
py
Runtime Error
40
7060
843
# -*- coding: utf-8 -*- """ Created on Sat Jul 14 10:14:13 2018 ALDS1_11_D @author: maezawa """ n, m = list(map(int, input().split())) v = [-1 for _ in range(n)] stack = [] adj = [[] for _ in range(n)] for i in range(m): s, t = list(map(int, input().split())) adj[s].append(t) adj[t].append(s) #print(*adj, sep='\n') def dfs(u, color): if v[u] > 0: return 0 v[u] = color #print(u, current, stack) for k in adj[u]: if v[k] > 0: continue dfs(k, color) return 1 color = 1 for start in range(n): if dfs(start, color) == 1: color += 1 #for i in range(n): # print('color:{} for node:{}'.format(i, v[i])) q = int(input()) for i in range(q): s, t = list(map(int, input().split())) if v[s] == v[t]: print('yes') else: print('no')
s019464790
p02240
u255317651
1531534460
Python
Python3
py
Runtime Error
50
8596
883
# -*- coding: utf-8 -*- """ Created on Sat Jul 14 10:14:13 2018 ALDS1_11_D @author: maezawa """ import sys sys.setrecursionlimit(10000) n, m = list(map(int, input().split())) v = [-1 for _ in range(n)] stack = [] adj = [[] for _ in range(n)] for i in range(m): s, t = list(map(int, input().split())) adj[s].append(t) adj[t].append(s) #print(*adj, sep='\n') def dfs(u, color): if v[u] > 0: return 0 v[u] = color #print(u, current, stack) for k in adj[u]: if v[k] > 0: continue dfs(k, color) return 1 color = 1 for start in range(n): if dfs(start, color) == 1: color += 1 #for i in range(n): # print('color:{} for node:{}'.format(i, v[i])) q = int(input()) for i in range(q): s, t = list(map(int, input().split())) if v[s] == v[t]: print('yes') else: print('no')
s620583474
p02240
u255317651
1531534490
Python
Python3
py
Runtime Error
700
126448
884
# -*- coding: utf-8 -*- """ Created on Sat Jul 14 10:14:13 2018 ALDS1_11_D @author: maezawa """ import sys sys.setrecursionlimit(100000) n, m = list(map(int, input().split())) v = [-1 for _ in range(n)] stack = [] adj = [[] for _ in range(n)] for i in range(m): s, t = list(map(int, input().split())) adj[s].append(t) adj[t].append(s) #print(*adj, sep='\n') def dfs(u, color): if v[u] > 0: return 0 v[u] = color #print(u, current, stack) for k in adj[u]: if v[k] > 0: continue dfs(k, color) return 1 color = 1 for start in range(n): if dfs(start, color) == 1: color += 1 #for i in range(n): # print('color:{} for node:{}'.format(i, v[i])) q = int(input()) for i in range(q): s, t = list(map(int, input().split())) if v[s] == v[t]: print('yes') else: print('no')
s348020895
p02240
u684241248
1531639165
Python
Python3
py
Runtime Error
30
7052
1063
# -*- coding: utf-8 -*- class LinkedList: def __init__(self, n): self.n = n self.ll = [[] for _ in range(self.n)] def link(self, u, v, direction=False): self.ll[u].append(v) if not direction: self.ll[v].append(u) def dfs(self): self.cc = [None] * self.n color = 1 for u in range(self.n): if not self.cc[u]: self.dfs_visit(u, color) color += 1 def dfs_visit(self, u, color): self.cc[u] = color for v in self.ll[u]: if not self.cc[v]: self.dfs_visit(v, color) def check(self, u, v): if self.cc[u] == self.cc[v]: print('yes') else: print('no') if __name__ == '__main__': n, m = map(int, input().split()) ll = LinkedList(n) for _ in range(m): u, v = map(int, input().split()) ll.link(u, v) ll.dfs() q = int(input()) for _ in range(q): u, v = map(int, input().split()) ll.check(u, v)
s677321391
p02240
u279605379
1534742391
Python
Python3
py
Runtime Error
310
8536
509
def dfs(s): global t if s == t: return True DP[s]=1 for i in F[s]: if not DP[i]: if dfs(i): return True return False n,m = [int(i) for i in input().split()] F = [{} for i in range(n)] for _ in range(m): i,j = [int(i) for i in input().split()] F[i][j] = 1 F[j][i] = 1 q = int(input()) for i in range(q): DP = [0]*n s,t = [int(i) for i in input().split()] if dfs(s): print("yes") else: print("no")
s739408595
p02240
u279605379
1534742463
Python
Python3
py
Runtime Error
1480
10296
549
import sys sys.setrecursionlimit(10000) def dfs(s): global t if s == t: return True DP[s]=1 for i in F[s]: if not DP[i]: if dfs(i): return True return False n,m = [int(i) for i in input().split()] F = [{} for i in range(n)] for _ in range(m): i,j = [int(i) for i in input().split()] F[i][j] = 1 F[j][i] = 1 q = int(input()) for i in range(q): DP = [0]*n s,t = [int(i) for i in input().split()] if dfs(s): print("yes") else: print("no")
s235129523
p02240
u007270338
1535683533
Python
Python3
py
Runtime Error
360
7000
685
#coding: utf-8 global b n, m = map(int,input().split()) List = [[] for i in range(n)] for i in range(m): s,t = map(int,input().split()) List[s].append(t) List[t].append(s) def search(a,target): if a == target: print("yes") return False for member in List[a]: if color[member] == "white": color[member] = "black" if search(member, target) == False: return False return True p = int(input()) for i in range(p): color = ["white" for i in range(n)] a, target = map(int,input().split()) color[a] = "black" b = search(a, target) if b : print("no")
s248605770
p02240
u637322311
1540714377
Python
Python3
py
Runtime Error
750
21024
999
from sys import stdin def read_graph(n, k): A = [ [] for _ in range(n) ] for _ in range(k): line = stdin.readline().strip().split() A[int(line[0])].append(int(line[1])) A[int(line[1])].append(int(line[0])) return A def dfs_ctrl(n, A, s, t): color = ["WHITE"] * n d = [0] * n f = [0] * n time = 0 def dfs(u): nonlocal color nonlocal time color[u] = "GRAY" time += 1 d[u] = time for v in A[u]: if color[v] == "WHITE": dfs(v) color[u] = "BLACK" time += 1 f[u] = time dfs(s) if d[t] != 0: print("yes") else: print("no") def read_and_print_connection(m): for _ in range(m): line = stdin.readline().strip().split() s = int(line[0]) t = int(line[1]) dfs_ctrl(n, A, s, t) n, k = [int(i) for i in input().split()] A = read_graph(n, k) m = int(input()) read_and_print_connection(m)
s651796788
p02240
u094978706
1540967819
Python
Python3
py
Runtime Error
40
7124
658
n, m = map(int, input().split()) adj = [[] for _ in range(n)] # adjacent list for _ in range(m): u, v = map(int, input().split()) adj[u].append(v) adj[v].append(u) c = ['w']*n # color of each vertex con = [0]*n cnt = 0 def DFS_visit(u): global c global con global cnt c[u] = 'g' con[u] = cnt for v in adj[u]: if c[v] == 'w': DFS_visit(v) c[u] = 'b' for u in range(n): if c[u] == 'w': cnt += 1 DFS_visit(u) q = int(input()) for _ in range(q): u, v = map(int, input().split()) ans = "yes" if (con[u] == con[v]) else "no" print(ans)
s194477615
p02240
u821080069
1559556173
Python
Python3
py
Runtime Error
610
6996
626
n, m = map(int, input().split()) graph = [[] for _ in range(n)] global visited visited = [0 for _ in range(n)] def input_graph(m): for _ in range(m): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) def dfs(node_id): for ad_node in graph[node_id]: if visited[ad_node] == 1: continue visited[ad_node] = 1 dfs(ad_node) if __name__ == "__main__": input_graph(m) q_num = int(input()) for _ in range(q_num): visited = [0 for _ in range(n)] s, t = map(int, input().split()) dfs(s) if visited[t]: print("yes") else: print("no")
s209245233
p02240
u821080069
1559556266
Python
Python3
py
Runtime Error
0
0
655
sys.setrecursionlimit(10000) n, m = map(int, input().split()) graph = [[] for _ in range(n)] global visited visited = [0 for _ in range(n)] def input_graph(m): for _ in range(m): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) def dfs(node_id): for ad_node in graph[node_id]: if visited[ad_node] == 1: continue visited[ad_node] = 1 dfs(ad_node) if __name__ == "__main__": input_graph(m) q_num = int(input()) for _ in range(q_num): visited = [0 for _ in range(n)] s, t = map(int, input().split()) dfs(s) if visited[t]: print("yes") else: print("no")
s062894680
p02240
u821080069
1559556284
Python
Python3
py
Runtime Error
2260
8848
666
import sys sys.setrecursionlimit(10000) n, m = map(int, input().split()) graph = [[] for _ in range(n)] global visited visited = [0 for _ in range(n)] def input_graph(m): for _ in range(m): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) def dfs(node_id): for ad_node in graph[node_id]: if visited[ad_node] == 1: continue visited[ad_node] = 1 dfs(ad_node) if __name__ == "__main__": input_graph(m) q_num = int(input()) for _ in range(q_num): visited = [0 for _ in range(n)] s, t = map(int, input().split()) dfs(s) if visited[t]: print("yes") else: print("no")
s530722488
p02240
u821080069
1559556639
Python
Python3
py
Runtime Error
0
0
1023
import sys sys.setrecursionlimit(1000000) n, m = map(int, input().split()) graph = [[] for _ in range(n)] global visited visited = [0 for _ in range(n)] global Q, S, T S = [0] #訪れた順 T = [] visited[0] = 1 #開始位置はすでに訪れたことにする def input_graph(m): for _ in range(m): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) def dfs(): global Q, S while Q: node_id = Q.pop() for ad_node in graph[node_id]: if visited[ad_node] == 1: continue visited[ad_node] = 1 S.append(ad_node) Q.append(ad_node) """ def dfs(node_id): for ad_node in graph[node_id]: if visited[ad_node] == 1: continue visited[ad_node] = 1 dfs(ad_node) """ if __name__ == "__main__": input_graph(m) q_num = int(input()) for _ in range(q_num): visited = [0 for _ in range(n)] s, t = map(int, input().split()) Q = deque([s]) dfs() if visited[t]: print("yes") else: print("no")
s456597852
p02240
u669284080
1453564250
Python
Python3
py
Runtime Error
30
7716
549
#!/usr/bin/python3 n, m = map(int, input().split()) e = [None] * n for i in range(m): s, t = map(int, input().split()) if e[s] == None and e[t] == None: a = {s, t} e[s] = e[t] = a elif e[s] == None: e[t].add(s) e[s] = e[t] elif e[t] == None: e[s].add(t) e[t] = e[s] else: a = e[s] | e[t] for j in a: e[j] = a q = int(input()) for i in range(q): s, t = map(int, input().split()) if t in e[s]: print('yes') else: print('no')
s556151101
p02240
u669284080
1453606890
Python
Python3
py
Runtime Error
40
10296
599
#!/usr/bin/python3 def set_color(i, ci, e, color): color[i] = ci for next_i in e[i]: if color[next_i] != ci: set_color(next_i, ci, e, color) n, m = map(int, input().split()) e = [set() for i in range(n)] color = [None] * n for i in range(m): s, t = map(int, input().split()) e[s].add(t) e[t].add(s) ci = 0 for i in range(n): if color[i] == None: set_color(i, ci, e, color) ci += 1 q = int(input()) for i in range(q): s, t = map(int, input().split()) if color[s] == color[t]: print('yes') else: print('no')
s988140310
p02240
u885467869
1454080259
Python
Python
py
Runtime Error
70
11244
924
class node: def __init__(self, num): self.number = num self.group = 0 self.link_node = [] self.is_serched = False def DFS(node, group_num): node.is_serched = True node.group = group_num for item in node.link_node: if item.is_serched == False: DFS(item, group_num) n ,m = map(int, raw_input().split()) node_list = [None] * (n) for i in xrange(n): node_list[i] = node(i) for _ in xrange(m): s, t = map(int, raw_input().split()) node_list[s].link_node.append(node_list[t]) node_list[t].link_node.append(node_list[s]) group_num = 1 for item in node_list: if item.is_serched == False: DFS(item, group_num) group_num = group_num + 1 q = input() for _ in xrange(q): s, t = map(int, raw_input().split()) if node_list[s].group == node_list[t].group: print 'yes' else: print 'no'
s021354720
p02240
u885467869
1454080296
Python
Python
py
Runtime Error
30
11240
924
class node: def __init__(self, num): self.number = num self.group = 0 self.link_node = [] self.is_serched = False def DFS(node, group_num): node.is_serched = True node.group = group_num for item in node.link_node: if item.is_serched == False: DFS(item, group_num) n ,m = map(int, raw_input().split()) node_list = [None] * (n) for i in xrange(n): node_list[i] = node(i) for _ in xrange(m): s, t = map(int, raw_input().split()) node_list[s].link_node.append(node_list[t]) node_list[t].link_node.append(node_list[s]) group_num = 1 for item in node_list: if item.is_serched == False: DFS(item, group_num) group_num = group_num + 1 q = input() for _ in xrange(q): s, t = map(int, raw_input().split()) if node_list[s].group == node_list[t].group: print 'yes' else: print 'no'
s662774052
p02240
u920118302
1454089312
Python
Python3
py
Runtime Error
0
0
691
def DFS(s): flag[s] = 1 F[group] += s for i in range(n): if G[s][i] == 1: if flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[0 for i in range(n)] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s][t] = 1 G[t][s] = 1 F = [] flag = [0 for i in range(n)] group = 0 for i in range(n): if flag[i] == 0: F.append([]) DFS(i) group += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for friends in F: if s in friends and t in friends: ans[i] = "yes" for i in range(q): print(ans[i])
s116113560
p02240
u920118302
1454089338
Python
Python3
py
Runtime Error
0
0
701
def DFS(s): flag[s] = 1 F[group] = F[group] + s for i in range(n): if G[s][i] == 1: if flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[0 for i in range(n)] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s][t] = 1 G[t][s] = 1 F = [] flag = [0 for i in range(n)] group = 0 for i in range(n): if flag[i] == 0: F.append([]) DFS(i) group += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for friends in F: if s in friends and t in friends: ans[i] = "yes" for i in range(q): print(ans[i])
s955296528
p02240
u885467869
1454110904
Python
Python
py
Runtime Error
30
11280
924
class node: def __init__(self, num): self.number = num self.group = 0 self.link_node = [] self.is_serched = False def DFS(node, group_num): node.is_serched = True node.group = group_num for item in node.link_node: if item.is_serched == False: DFS(item, group_num) n ,m = map(int, raw_input().split()) node_list = [None] * (n) for i in xrange(n): node_list[i] = node(i) for _ in xrange(m): s, t = map(int, raw_input().split()) node_list[s].link_node.append(node_list[t]) node_list[t].link_node.append(node_list[s]) group_num = 1 for item in node_list: if item.is_serched == False: DFS(item, group_num) group_num = group_num + 1 q = input() for _ in xrange(q): s, t = map(int, raw_input().split()) if node_list[s].group == node_list[t].group: print 'yes' else: print 'no'
s987255488
p02240
u069446126
1454175187
Python
Python
py
Runtime Error
0
0
343
entry = map(int, raw_input()) n = entry[0] m = entry[1] A = [] * n for i in range(m): entry = map(int, raw_input()) A[entry[0]].append(entry[1]) A[entry[1]].append(entry[0]) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if entry[1] in A[entry[0]]: print("yes") else: print("no")
s089517306
p02240
u069446126
1454180814
Python
Python
py
Runtime Error
0
0
857
entry = map(int, raw_input()) n = entry[0] m = entry[1] color = [0] * n affil = [0] * n def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num A = range(n) for i in A: A[i] = list() for i in range(m): entry = friends[i] s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s562897440
p02240
u069446126
1454180961
Python
Python
py
Runtime Error
0
0
870
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) entry = map(int, raw_input()) n = entry[0] m = entry[1] color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s404087651
p02240
u069446126
1454181095
Python
Python
py
Runtime Error
0
0
869
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num entry = map(int, raw_input()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s623957568
p02240
u069446126
1454181523
Python
Python
py
Runtime Error
0
0
868
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num entry = map(int, raw_input()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s157000091
p02240
u069446126
1454181699
Python
Python
py
Runtime Error
0
0
868
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num entry = map(int, raw_input()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s162047564
p02240
u069446126
1454182087
Python
Python
py
Runtime Error
0
0
875
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) return group_num entry = map(int, raw_input()) n = entry[0] m = entry[1] A = [0] * n for i in range(n): A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] affil[i] = group_num + 1 group_num = BFS(i, group_num + 1) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s658795140
p02240
u069446126
1454182657
Python
Python
py
Runtime Error
0
0
867
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input()) n = entry[0] m = entry[1] A = [0] * n for i in range(n): A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s495485933
p02240
u069446126
1454182763
Python
Python3
py
Runtime Error
0
0
867
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input()) n = entry[0] m = entry[1] A = [0] * n for i in range(n): A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s159888119
p02240
u069446126
1454182883
Python
Python
py
Runtime Error
0
0
875
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input()) n = entry[0] m = entry[1] A = [0] * n for i in range(n): A[i] = list((-1, -1)) for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s104945493
p02240
u069446126
1454183370
Python
Python
py
Runtime Error
0
0
861
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s893616899
p02240
u069446126
1454183452
Python
Python
py
Runtime Error
0
0
871
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry1 = map(int, raw_input()) n = entry1[0] m = entry1[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry2 = map(int, raw_input()) s = entry2[0] t = entry2[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry3 = map(int, raw_input()) if affil[entry3[0]] == affil[entry3[1]]: print("yes") else: print("no")
s276839215
p02240
u069446126
1454183563
Python
Python
py
Runtime Error
30
8104
886
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input().split()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input().split()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input().split()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s474808832
p02240
u069446126
1454183668
Python
Python
py
Runtime Error
40
8300
886
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input().split()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input().split()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input().split()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s253304013
p02240
u797673668
1454255068
Python
Python3
py
Runtime Error
310
15224
558
n, m = map(int, input().split()) g = [set() for _ in range(n)] while m: s, t = map(int, input().split()) g[s].add(t) g[t].add(s) m -= 1 def find(s, t): global g visited = [0] * n def dfs(i): visited[i] = 1 if i == t: return True for f in g[i]: if not visited[f]: if dfs(f): return True return False return dfs(s) q = int(input()) while q: s, t = map(int, input().split()) print('yes' if find(s, t) else 'no') q -= 1
s605826810
p02240
u797673668
1454257844
Python
Python3
py
Runtime Error
0
0
877
from collections import deque n, m = map(int, input().split()) g = [set() for _ in range(n)] while m: s, t = map(int, input().split()) g[s].add(t) g[t].add(s) m -= 1 def find(s, t): global g queue = deque() queue.append((0, s)) queue.append((1, t)) visited = (set(), set()) visited[0].add(s) visited[1].add(t) def remember(visited, new): g[new] |= visited for v in visited: g[v].add(new) visited[new] = 1 while queue: st, i = queue.popleft() for f in g[i]: if visited[not st][f]: return True if not visited[st][f]: remember(visited[st], f) queue.append((st, f)) return False q = int(input()) while q: s, t = map(int, input().split()) print('yes' if find(s, t) else 'no') q -= 1
s804329315
p02240
u069446126
1454276543
Python
Python
py
Runtime Error
90
8296
885
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input().split()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input().split()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input().split()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s362635666
p02240
u069446126
1454289524
Python
Python
py
Runtime Error
30
8096
886
def BFS(s = 0, group_num = 0): Q.pop(0) color[s] = 2 for j in range(len(A[s])): if color[A[s][j]] == 0: Q.append(A[s][j]) color[A[s][j]] = 1 affil[A[s][j]] = group_num if len(Q) != 0: BFS(Q[0], group_num) entry = map(int, raw_input().split()) n = entry[0] m = entry[1] A = range(n) for i in A: A[i] = list() for i in range(m): entry = map(int, raw_input().split()) s = entry[0] t = entry[1] A[s].append(t) A[t].append(s) color = [0] * n affil = [0] * n group_num = -1 for i in range(n): if color[i] == 0: Q = [i] group_num = group_num + 1 affil[i] = group_num BFS(i, group_num) q = int(raw_input()) for i in range(q): entry = map(int, raw_input().split()) if affil[entry[0]] == affil[entry[1]]: print("yes") else: print("no")
s500529270
p02240
u920118302
1454304549
Python
Python3
py
Runtime Error
0
0
534
def DFS(s, j): group[s] = j for i in range(n): if i in G[s] and group[i] == 0: DFS(i, j) n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) group = [0 for i in range(n)] j = 1 for i in range(n): if group[i] == 0: DFS(i) j += 1 q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == group[t]: print("yes") else: print("no")
s751436261
p02240
u967035362
1454419351
Python
Python
py
Runtime Error
0
0
904
using namespace std; int n,m; vector<vector<int> > list(MAX); int grp[MAX]; int group; void dfs(int now){ stack<int> next; grp[now]=group; next.push(now); while(!next.empty()){ now=next.top(); next.pop(); for(int i=0;i<(int)list[now].size();i++){ if(grp[list[now][i]]==-1){ grp[list[now][i]]=group; next.push(list[now][i]); } } } } int main(){ cin>>n>>m; int s,t; for(int i=0;i<m;i++){ cin>>s>>t; list[s].push_back(t); list[t].push_back(s); } for(int i=0;i<n;i++) grp[i]=-1; group=1; for(int i=0;i<n;i++){ if(grp[i]==-1){ dfs(i); group++; } } int q; cin>>q; for(int i=0;i<q;i++){ cin>>s>>t; if(grp[s]==grp[t]) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0;
s040768993
p02240
u967035362
1454419378
Python
Python
py
Runtime Error
0
0
906
using namespace std; int n,m; vector<vector<int> > list(MAX); int grp[MAX]; int group; void dfs(int now){ stack<int> next; grp[now]=group; next.push(now); while(!next.empty()){ now=next.top(); next.pop(); for(int i=0;i<(int)list[now].size();i++){ if(grp[list[now][i]]==-1){ grp[list[now][i]]=group; next.push(list[now][i]); } } } } int main(){ cin>>n>>m; int s,t; for(int i=0;i<m;i++){ cin>>s>>t; list[s].push_back(t); list[t].push_back(s); } for(int i=0;i<n;i++) grp[i]=-1; group=1; for(int i=0;i<n;i++){ if(grp[i]==-1){ dfs(i); group++; } } int q; cin>>q; for(int i=0;i<q;i++){ cin>>s>>t; if(grp[s]==grp[t]) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0; }
s130718128
p02240
u047737909
1454419454
Python
Python
py
Runtime Error
0
0
684
,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c while len(que) > 0: u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s456892030
p02240
u563876281
1454419584
Python
Python
py
Runtime Error
0
0
690
x,y = map(int,raw_input().strip().split(' ')) follow = [[] for i in range(n)] for i in range(y): h,c = map(int,raw_input().strip().split(' ')) follow[h].append(c) follow[c].append(h) color = {} u = 0 for i in range(n): if not i in color: que = [i] color[i] = u while len(que) > 0: u = que[0] for v in follow[u]: if not v in color: color[v] = u que.append(v) del que[0] u += 1 q = int(raw_input()) for i in range(q): h,c = map(int,raw_input().strip().split(' ')) if color[h] == color[c]: print 'yes' else: print 'no'
s246416929
p02240
u563876281
1454419639
Python
Python
py
Runtime Error
0
0
690
x,y = map(int,raw_input().strip().split(' ')) follow = [[] for i in range(n)] for i in range(y): h,c = map(int,raw_input().strip().split(' ')) follow[h].append(c) follow[c].append(h) color = {} u = 0 for i in range(x): if not i in color: que = [i] color[i] = u while len(que) > 0: u = que[0] for v in follow[u]: if not v in color: color[v] = u que.append(v) del que[0] u += 1 q = int(raw_input()) for i in range(q): h,c = map(int,raw_input().strip().split(' ')) if color[h] == color[c]: print 'yes' else: print 'no'
s739299923
p02240
u233232390
1454423840
Python
Python
py
Runtime Error
0
0
539
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in range (m): u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1
s442677146
p02240
u233232390
1454423857
Python
Python
py
Runtime Error
0
0
539
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in range (n): u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1
s230549522
p02240
u233232390
1454423876
Python
Python
py
Runtime Error
0
0
538
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in range(n): u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1
s987020908
p02240
u233232390
1454424018
Python
Python
py
Runtime Error
0
0
547
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: // for j in range(len(que)): u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1
s681726724
p02240
u920118302
1454424293
Python
Python3
py
Runtime Error
0
0
654
def DFS(s): flag[s] = 1 F.append(s) for i in range(n): if G[s][i] == 1 and flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s] += t G[t] += s F = [] flag = [0 for i in range(n)] group = 0 for i in range(n): if flag[i] == 0: F.append([]) DFS(i) group += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for friends in F: if s in friends and t in friends: ans[i] = "yes" for i in range(q): print(ans[i])
s152014729
p02240
u920118302
1454424331
Python
Python3
py
Runtime Error
0
0
651
def DFS(s): flag[s] = 1 F.append(s) for i in range(n): if G[s] == i and flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s] += t G[t] += s F = [] flag = [0 for i in range(n)] group = 0 for i in range(n): if flag[i] == 0: F.append([]) DFS(i) group += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for friends in F: if s in friends and t in friends: ans[i] = "yes" for i in range(q): print(ans[i])
s512255667
p02240
u233232390
1454424406
Python
Python
py
Runtime Error
0
0
580
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s153624119
p02240
u233232390
1454424441
Python
Python
py
Runtime Error
0
0
559
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s904423632
p02240
u920118302
1454424445
Python
Python3
py
Runtime Error
0
0
653
def DFS(s): flag[s] = 1 group[j] += s for i in range(n): if G[s] == i and flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s] += t G[t] += s flag = [0 for i in range(n)] group = [] j = 0 for i in range(n): if flag[i] == 0: group.append([]) DFS(i) j += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for friends in F: if s in friends and t in friends: ans[i] = "yes" for i in range(q): print(ans[i])
s203050547
p02240
u920118302
1454424536
Python
Python3
py
Runtime Error
0
0
664
def DFS(s): flag[s] = 1 group[j] += s for i in range(n): if G[s] == i and flag[i] == 0: DFS(i) n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s] += t G[t] += s flag = [0 for i in range(n)] group = [] j = 0 for i in range(n): if flag[i] == 0: group.append([]) DFS(i) j += 1 q = int(input()) ans = ["no" for i in range(q)] for i in range(q): s, t = map(int, input().split()) for j in range(len(group)): if s in group[j] and t in gruop[j]: ans[i] = "yes" for i in range(q): print(ans[i])
s411510123
p02240
u233232390
1454424671
Python
Python
py
Runtime Error
0
0
742
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in len(que): #while len(que) > 0: u[j] = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s417613553
p02240
u233232390
1454424682
Python
Python
py
Runtime Error
0
0
745
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in len(que): #while len(que) > 0: u[j] = que[0] for v in graph[u[j]]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s201234789
p02240
u038005340
1454424876
Python
Python
py
Runtime Error
0
0
681
def UF() int parent; UF uf[100000] def initialize(num) for i in num-1: uf[i].parent = i; def find(a) if a == uf[a].parent: return a return uf[a].parent = find(uf[a].parent) def isSame( a , b ) if find(a) == find(b): return 1 else: return 0; def unite( a , b ) a = find(a) b = find(b) if a == b: return uf[b].parent = a; n = int( raw_input() ) m = int( raw_input() ) initialize(n) for i in m-1: u,v = map( int , raw_input().split() ) unite(u, v) q = int( raw_input() ) for i in q-1: u,v = map( int , raw_input().split() ) if (isSame(u, v)): printf "yes" else: printf "no"
s652273256
p02240
u233232390
1454425046
Python
Python
py
Runtime Error
0
0
764
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in len(que): if len(que) > 0: #while len(que) > 0: u[j] = que[0] for v in graph[u[j]]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s318526187
p02240
u233232390
1454425061
Python
Python
py
Runtime Error
0
0
766
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in len(que): if len(que) > 0: #while len(que) > 0: u[j] = que[0] for v in graph[u[j]]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s968897370
p02240
u233232390
1454425088
Python
Python
py
Runtime Error
0
0
773
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c if len(que) > 0: for j in range(len(que)): if len(que) > 0: #while len(que) > 0: u[j] = que[0] for v in graph[u[j]]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s150008896
p02240
u920118302
1454425162
Python
Python3
py
Runtime Error
0
0
604
n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) group = {} c = 0 for i in range(n): if not i in group: que = [i] group[i] = c while len(que) > 0: u = que[0] for j in G[u]: if not j in group: group[j] = cque.append(j) del que[0] c += 1 q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == grooup[t]: print("yes") else: print("no")
s678675001
p02240
u920118302
1454425201
Python
Python3
py
Runtime Error
0
0
603
n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) group = {} c = 0 for i in range(n): if not i in group: que = [i] group[i] = c while len(que) > 0: u = que[0] for j in G[u]: if not j in group: group[j] = cque.append(j) del que[0] c += 1 q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == group[t]: print("yes") else: print("no")
s761441866
p02240
u920118302
1454425380
Python
Python3
py
Runtime Error
0
0
623
n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) group = [] c = 0 for i in range(n): group.append([]) if not i in group: que = [i] group[i] = c while len(que) > 0: u = que[0] for j in G[u]: if not j in group: group[j] = que.append(j) del que[0] c += 1 q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == group[t]: print("yes") else: print("no")
s024928419
p02240
u920118302
1454425438
Python
Python3
py
Runtime Error
0
0
625
n, m = map(int, input().split()) G = [[] for j in range(n)] for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) group = [[]] c = 0 for i in range(n): if not i in group: que = [i] group[i] = c while len(que) > 0: u = que[0] for j in G[u]: if not j in group: group[j] = que.append(j) del que[0] c += 1 group.append([]) q = int(input()) for i in range(q): s, t = map(int, input().split()) if group[s] == group[t]: print("yes") else: print("no")
s098812779
p02240
u233232390
1454425865
Python
Python
py
Runtime Error
0
0
676
n,m = map(int,raw_input().strip().split(' ')) graph = [[] for i in range(n)] for i in range(m): s,t = map(int,raw_input().strip().split(' ')) graph[s].append(t) graph[t].append(s) color = {} c = 0 for i in range(n): if not i in color: que = [i] color[i] = c do len(que) > 0: u = que[0] for v in graph[u]: if not v in color: color[v] = c que.append(v) del que[0] c += 1 q = int(raw_input()) for i in range(q): s,t = map(int,raw_input().strip().split(' ')) if color[s] == color[t]: print 'yes' else: print 'no'
s230271004
p02240
u408260374
1455859135
Python
Python3
py
Runtime Error
620
72004
538
import sys sys.setrecursionlimit(200000) def dfs(v, cnt): group[v] = cnt for c in edge[v]: if group[c] == -1: dfs(c, cnt) V, E = map(int, input().split()) edge = [[] for _ in range(V)] for _ in range(E): s, t = map(int, input().split()) edge[s].append(t) edge[t].append(s) group = [-1] * V c = 0 for i in range(V): if group[i] == -1: dfs(i, c) c += 1 Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) print('yes' if group[s] == group[t] else 'no')
s620626207
p02240
u408260374
1455859187
Python
Python3
py
Runtime Error
590
72020
537
import sys sys.setrecursionlimit(10**6) def dfs(v, cnt): group[v] = cnt for c in edge[v]: if group[c] == -1: dfs(c, cnt) V, E = map(int, input().split()) edge = [[] for _ in range(V)] for _ in range(E): s, t = map(int, input().split()) edge[s].append(t) edge[t].append(s) group = [-1] * V c = 0 for i in range(V): if group[i] == -1: dfs(i, c) c += 1 Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) print('yes' if group[s] == group[t] else 'no')
s056865318
p02240
u894114233
1459348468
Python
Python
py
Runtime Error
60
7656
534
def dfs(u): global ct if color[u]!=-1: return color[u]=ct for v in fr[u]: if v!=-1 and color[v]==-1: dfs(v) color[u]=ct n,m=map(int,raw_input().split()) fr=[[] for i in xrange(n)] for i in xrange(m): s,t=map(int,raw_input().split()) fr[s].append(t) fr[t].append(s) q=input() ct=0 color=[-1]*n for i in xrange(n): dfs(i) ct+=1 for i in xrange(q): s,t=map(int,raw_input().split()) if color[s]==color[t]: print('yes') else: print('no')
s417284225
p02240
u894114233
1459349591
Python
Python
py
Runtime Error
30
7532
524
def dfs(u): global ct if color[u]!=-1: return color[u]=ct for v in fr[u]: if color[v]==-1: dfs(v) color[u]=ct n,m=map(int,raw_input().split()) fr=[[] for i in xrange(n)] for i in xrange(m): s,t=map(int,raw_input().split()) fr[s].append(t) fr[t].append(s) q=input() ct=0 color=[-1]*n for i in xrange(n): dfs(i) ct+=1 for i in xrange(q): s,t=map(int,raw_input().split()) if color[s]==color[t]: print('yes') else: print('no')
s248929049
p02240
u567281053
1463072418
Python
Python
py
Runtime Error
140
8080
594
import sys def dfs(s, t): global V, d d[s] = 1 if t in V[s]: return True for v in V[s]: if d[v] == 0: if dfs(v, t): return True return False lines = sys.stdin.readlines() n, m = map(int, lines[0].split()) V = [[] for _ in range(n)] for i in range(1, m + 1): c = map(int, lines[i].split()) V[c[0]].append(c[1]) V[c[1]].append(c[0]) q = int(lines[m + 1]) for i in range(m + 2, m + q + 2): c = map(int, lines[i].split()) d = [0] * (n) if dfs(c[0], c[1]): print "yes" else: print "no"
s362355878
p02240
u567281053
1463072574
Python
Python
py
Runtime Error
150
8188
594
import sys def dfs(s, t): global V, d d[s] = 1 if t in V[s]: return True for v in V[s]: if d[v] == 0: if dfs(v, t): return True return False lines = sys.stdin.readlines() n, m = map(int, lines[0].split()) V = [[] for _ in range(n)] for i in range(1, m + 1): c = map(int, lines[i].split()) V[c[0]].append(c[1]) V[c[1]].append(c[0]) q = int(lines[m + 1]) for i in range(m + 2, m + q + 2): c = map(int, lines[i].split()) d = [0] * (n) if dfs(c[0], c[1]): print "yes" else: print "no"
s703109913
p02240
u567281053
1463072828
Python
Python
py
Runtime Error
160
8104
657
import sys def dfs(s, t): global V, d if t in V[s]: return True d[s] = 1 for v in V[s]: if d[v] == 0: if dfs(v, t): return True return False lines = sys.stdin.readlines() if lines[0] == "In preparation.": print "In preparation." n, m = map(int, lines[0].split()) V = [[] for _ in range(n)] for i in range(1, m + 1): c = map(int, lines[i].split()) V[c[0]].append(c[1]) V[c[1]].append(c[0]) q = int(lines[m + 1]) for i in range(m + 2, m + q + 2): c = map(int, lines[i].split()) d = [0] * (n) if dfs(c[0], c[1]): print "yes" else: print "no"
s664430323
p02240
u567281053
1463074037
Python
Python
py
Runtime Error
140
8188
582
import sys def dfs(s, t): global V, d if t in V[s]: return True d[s] = 1 for v in V[s]: if d[v] == 0: if dfs(v, t): return True return False lines = sys.stdin.readlines() n, m = map(int, lines[0].split()) V = [[] for _ in range(n)] for i in range(1, m + 1): s, t = map(int, lines[i].split()) V[s].append(t) V[t].append(s) q = int(lines[m + 1]) for i in range(m + 2, m + q + 2): s, t = map(int, lines[i].split()) d = [0] * (n) if dfs(s, t): print "yes" else: print "no"
s167290030
p02240
u567281053
1463074269
Python
Python
py
Runtime Error
140
7960
526
def dfs(s, t): global V, d if t in V[s]: return True d[s] = 1 for v in V[s]: if d[v] == 0: if dfs(v, t): return True return False n, m = map(int, raw_input().split()) V = [[] for _ in range(n)] for _ in range(m): s, t = map(int, raw_input().split()) V[s].append(t) V[t].append(s) q = int(raw_input()) for _ in range(q): s, t = map(int, raw_input().split()) d = [0] * (n) if dfs(s, t): print "yes" else: print "no"
s667440797
p02240
u567281053
1463574516
Python
Python
py
Runtime Error
30
7792
536
def dfs(i, c): global V, C if C[i] == -1: C[i] = c else: return for v in V[i]: dfs(v, c) n, m = map(int, raw_input().split()) V = [[] for _ in range(n)] C = [-1] * n for _ in range(m): l, r = map(int, raw_input().split()) V[l].append(r) V[r].append(l) c = 0 for i in range(n): if C[i] == -1: dfs(i, c) c += 1 q = int(raw_input()) for _ in range(q): s, t = map(int, raw_input().split()) if C[s] == C[t]: print "yes" else: print "no"
s507747297
p02240
u072053884
1464250761
Python
Python3
py
Runtime Error
40
9204
675
n, m = map(int, input().split()) adj = [[] for i in range(n)] for i in range(m): s, t = map(int, input().split()) adj[s].append(t) adj[t].append(s) isVisited = [False] * n CC = [None] * n def dfs(u, group): isVisited[u] = True CC[u] = group for v in adj[u]: if not isVisited[v]: dfs(v, group) def makeCC(group): for i in range(n): if not isVisited[i]: dfs(i, group) group += 1 def isConnected(v1, v2): if CC[v1] == CC[v2]: print('yes') else: print('no') makeCC(0) q = int(input()) for i in range(q): s, t = map(int, input().split()) isConnected(s, t)
s874918631
p02240
u072053884
1464250884
Python
Python3
py
Runtime Error
40
9284
675
n, m = map(int, input().split()) adj = [[] for i in range(n)] for i in range(m): s, t = map(int, input().split()) adj[s].append(t) adj[t].append(s) isVisited = [False] * n CC = [None] * n def dfs(u, group): isVisited[u] = True CC[u] = group for v in adj[u]: if not isVisited[v]: dfs(v, group) def makeCC(group): for i in range(n): if not isVisited[i]: dfs(i, group) group += 1 def isConnected(v1, v2): if CC[v1] == CC[v2]: print('yes') else: print('no') makeCC(0) q = int(input()) for i in range(q): s, t = map(int, input().split()) isConnected(s, t)