input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
N, M, Q = list(map(int, input().split()))
bord = [[0 for _ in range(N + 2)] for _ in range(N + 2)]
for _ in range(M):
left, right = list(map(int, input().split()))
bord[left][right] += 1
# print(bord)
for i in range(1, N + 2):
for j in range(1, N + 2):
bord[i][j] += bord[i][j - 1]
# print... | N, M, Q = list(map(int, input().split()))
areas = [[0 for _ in range(N + 2)] for _ in range(N + 2)]
for _ in range(M):
left, right = list(map(int, input().split()))
areas[left][right] += 1
# print(areas)
for i in range(1, N + 2):
for j in range(1, N + 2):
areas[i][j] += areas[i][j - 1]
# ... | p03283 |
import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
N, M, Q = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
l, r = map(int, input().split())
G[l - 1][r - 1] += 1
csum = [[0... | import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
N, M, Q = map(int, readline().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
l, r = map(int, readline().split())
... | p03283 |
import sys
from itertools import accumulate
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
N, M, Q = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
l, r = map(int, input().split())
G[l - 1][r - 1] += 1
csum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
... | import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
N, M, Q = map(int, readline().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
l, r = map(int, re... | p03283 |
n,m,q=list(map(int,input().split()))
A=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
A[a][b]+=1
B=[[0]*(n+1) for i in range(n+1)]
for i in range(n+1):
for j in range(n+1):
if i!=0 and j!=0:
B[i][j]=B[i-1][j]+B[i][j-1]+A[i][j]-B[i-1][j-1]
elif i!=0:
... | n,m,q=list(map(int,input().split()))
A=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
A[a][b]=A[a][b]+1
B=[[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,n+1):
B[i][j]=B[i-1][j]+B[i][j-1]-B[i-1][j-1]+A[i][j]
for i in range(q):
x,y=list... | p03283 |
# ABC106 D - AtCoder Express 2
n,m,q=list(map(int,input().split()))
mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
l,r=list(map(int,input().split()))
mat[l][r]+=1
for i in range(n+1):
for j in range(n+1):
mat[i][j]+=mat[i-1][j]
mat[i][j]+=mat[i][j-1]
mat[i][j]-=ma... | # ABC106 D - AtCoder Express 2
n,m,q=list(map(int,input().split()))
mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
l,r=list(map(int,input().split()))
mat[l][r]+=1
for i in range(n+1):
for j in range(n+1):
mat[i][j]+=mat[i-1][j]
for i in range(n+1):
for j in range(n+1):
... | p03283 |
n,m,q=list(map(int,input().split()))
mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
l,r=list(map(int,input().split()))
mat[l][r]+=1
for i in range(n+1):
for j in range(n+1):
mat[i][j]+=mat[i-1][j]
mat[i][j]+=mat[i][j-1]
mat[i][j]-=mat[i-1][j-1]
for i in range(... | n,m,Q=list(map(int,input().split()))
mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
l,r=list(map(int,input().split()))
mat[l][r]+=1
for i in range(n+1):
for j in range(n+1):
mat[i][j]+=mat[i-1][j]
mat[i][j]+=mat[i][j-1]
mat[i][j]-=mat[i-1][j-1]
for i in range(Q):
p,q=list(map(... | p03283 |
N, M, Q = list(map(int, input().split()))
A = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
l, r = list(map(int, input().split()))
A[l][r] += 1
for i in range(Q):
p, q = list(map(int, input().split()))
cnt = 0
for i in range(p, q + 1):
cnt += sum(A[i][p : q + 1])
... | N, M, Q = list(map(int, input().split()))
A = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
l, r = list(map(int, input().split()))
A[l][r] += 1
for i in range(1, N + 1):
for j in range(1, N + 1):
A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j -1]
for i in rang... | p03283 |
N,M,Q=list(map(int,input().split()))
L,R=[],[]
for i in range(M):
l,r=list(map(int,input().split()))
L.append(l)
R.append(r)
Pl,Ql=[],[]
for i in range(Q):
pq=list(map(int,input().split()))
Pl.append(pq[0])
Ql.append(pq[1])
c=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
c[... | N,M,Q=list(map(int,input().split()))
L,R=[],[]
for i in range(M):
l,r=list(map(int,input().split()))
L.append(l)
R.append(r)
Pl,Ql=[],[]
for i in range(Q):
pq=list(map(int,input().split()))
Pl.append(pq[0])
Ql.append(pq[1])
c=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
c[... | p03283 |
from itertools import accumulate
n,m,q = list(map(int,input().split()))
li = [[0 for i in range(n+1)]for j in range(n+1)]
lin = []
for i in range(m):
l,r = list(map(int,input().split()))
li[l][r] += 1
for i in range(n+1):
lin.append(list(accumulate(li[i])))
for i in range(q):
l,r = lis... | from itertools import accumulate
n,m,q = list(map(int,input().split()))
li = [[0 for i in range(n+1)]for j in range(n+1)]
lin = []
for i in range(m):
l,r = list(map(int,input().split()))
li[l][r] += 1
for i in range(n+1):
lin += [list(accumulate(li[i]))]
for i in range(q):
l,r = list(m... | p03283 |
N, M, Q = list(map(int, input().split()))
LR = [[0 for i in range(2)] for j in range(M)]
pq = [[0 for i in range(2)] for j in range(Q)]
for i in range(M):
LR[i] = list(map(int, input().split()))
for i in range(Q):
pq[i] = list(map(int, input().split()))
x = [[0 for i in range(N)] for j in range(N... | N, M, Q = list(map(int, input().split()))
x = [[0 for i in range(N + 1)] for j in range(N + 1)]
for i in range(M):
l, r = list(map(int, input().split()))
x[l][r] += 1
for i in range(1, N + 1):
for j in range(1, N + 1):
x[i][j] += x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1]
for i in r... | p03283 |
N, M, Q = list(map(int, input().split()))
S = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
l, r = list(map(int, input().split()))
S[l][r] += 1
for i in range(1, N+1):
for j in range(N+1):
S[i][j] += S[i-1][j]
for i in range(N+1):
for j in range(1,... | N, M, Q = list(map(int, input().split()))
train = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
l, r = list(map(int, input().split()))
train[l][r] +=1
for i in range(N+1):
for j in range(N):
train[i][j+1] += train[i][j]
for i in range(N):
for j in ra... | p03283 |
import bisect
import sys
sys.setrecursionlimit(10**9)
def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))
INF=10**20
def main():
N,M,Q=mi()
Ls = []
Rs = []
for i ... | import sys
sys.setrecursionlimit(10**9)
def mi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()
def deb(text): print(("-------\n{}\n-------".format(text)))
INF=10**20
def main():
N,M,Q=mi()
count = [[0] * (N+1) for _ in range(N+1)]... | p03283 |
n=int(input())
il=list(map(int,input().split()))
s=0
t=0
cnt=[]
while t<n-1:
if il[t]==il[t+1]:
cnt.append(t+1-s)
s=t+1
t+=1
if t==n-1:
cnt.append(t+1-s)
ans=0
if len(cnt)<=3:
print((sum(cnt)))
else:
for i in range(len(cnt)-2):
ans=max(ans,cnt[i]+cnt[... | n=int(input())
il=list(map(int,input().split()))
s=0
cnt=[]
for t in range(n):
if t==n-1:
cnt.append(t+1-s)
break
if il[t]==il[t+1]:
cnt.append(t+1-s)
s=t+1
ans=0
if len(cnt)<=3:
print((sum(cnt)))
else:
for i in range(len(cnt)-2):
ans=max(ans,cnt[i... | p00526 |
from heapq import heappush, heappop
INF = 10 ** 20
def search(item_lst):
visited = {}
visited[(0, 0)] = True
que = []
heappush(que, (0, 0, 0))
while que:
score, a, e = heappop(que)
for da, de in item_lst[e]:
na, ne = min(d, a + da), min(100, e + de)
if na == d:
print(... | from heapq import heappush, heappop
INF = 10 ** 20
def search(item_lst, d):
visited = {}
visited[(0, 0)] = True
que = []
heappush(que, (0, 0, 0))
while que:
score, a, e = heappop(que)
for da, de in item_lst[e]:
na = a + da
if na >= d:
print((score + 1))
retur... | p00283 |
N = int(input())
score = [list(map(int, input().split())) for _ in range(N)]
players = [0 for _ in range(N)]
for play in list(zip(*score)):
for i, p in enumerate(play):
if play.count(p) == 1:
players[i] += p
print(*players, sep='\n')
| N = int(input())
score = [input().split() for _ in range(N)]
players = [0]*N
for play in list(zip(*score)):
for i, p in enumerate(play):
if play.count(p) == 1:
players[i] += int(p)
print(*players, sep='\n')
| p00500 |
N,M = list(map(int,input().split()))
atob = []
btoz = []
for _ in range(M):
a, b = list(map(int,input().split()))
if a == 1:
if b in btoz:
print('POSSIBLE')
break
atob.append(b)
elif b == N:
if a in atob:
print('POSSIBLE')
... | N,M = list(map(int,input().split()))
atob = [0] * N
btoz = [0] * N
for _ in range(M):
a, b = list(map(int,input().split()))
if a == 1:atob[b-1] = 1
elif a == N:btoz[b-1] = 1
if b == 1:atob[a-1] = 1
elif b == N:btoz[a-1] = 1
for i in range(N):
if atob[i]*btoz[i] == 1:
print('... | p03645 |
from collections import deque
n, m = list(map(int, input().split()))
x = deque()
y = deque()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
x.append(b)
elif b == n:
y.append(a)
for i in x:
if i in y:
print('POSSIBLE')
break
else:
p... | n, m = list(map(int, input().split()))
x = [[0] * 2 for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
x[b - 1][0] = 1
elif b == n:
x[a - 1][1] = 1
if [1, 1] in x:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
| p03645 |
n, m = list(map(int, input().split()))
l = list(list(map(int, input().split())) for _ in range(m))
c = []
for i in l:
if i[0] == n:
c.append(i[1])
l.remove(i)
elif i[1] == n:
c.append(i[0])
l.remove(i)
elif 1 in i:
continue
else:
l.remove(i)
for i in range(len(l)):
... | n, m = list(map(int, input().split()))
c = [[] for _ in range(n+1)]
for i in range(m):
a, b = list(map(int, input().split()))
c[a].append(b)
c[b].append(a)
for i in c[1]:
if n in c[i]:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | p03645 |
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
d... | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
d... | p03645 |
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
c=0
for j in range(n):
if [j,1] in l or [1,j] in l:
if [j,n] in l or [n,j] in l:
c+=1
break
if c==1:print('POSSIBLE')
else:print('IMPOSSIBLE') | n,m=list(map(int,input().split()))
L=[];l=[]
for k in range(n):
L.append(0)
for i in range(m):
x=list(map(int,input().split()))
l.append(x)
if x[0]==1:
L[x[1]]+=1
if x[1]==1:
L[x[0]]+=1
if x[0]==n:
L[x[1]]+=1
if x[1]==n:
L[x[0]]+=1
if max(L)==2:print('POSSIBLE')
else:print(... | p03645 |
N , M = list(map(int,input().split()))
L = []
transit1 = set()
transit2 = set()
for _ in range(M):
t = tuple(map(int,input().split()))
L.append(t)
for x in L :
if x[1] == N:
transit1.add(x[0])
if x[0] == 1:
transit2.add(x[1])
if transit1 & transit2 == set():
print("IMPOS... | import sys
input = sys.stdin.readline
N , M = list(map(int,input().split()))
L = []
transit1 = set()
transit2 = set()
for _ in range(M):
t = tuple(map(int,input().split()))
L.append(t)
for x in L :
if x[1] == N:
transit1.add(x[0])
if x[0] == 1:
transit2.add(x[1])
if transit... | p03645 |
N, M = list(map(int, input().rstrip().split()))
st = []
tt = []
for i in range(M):
s, t = list(map(int, input().rstrip().split()))
if s == 1:
st.append(t)
if t == N:
tt.append(s)
st.sort()
tt.sort()
result = 'IMPOSSIBLE'
for s in st:
if s in tt:
result =... | N, M = list(map(int, input().rstrip().split()))
st = []
dic = {}
for i in range(M):
s, t = list(map(int, input().rstrip().split()))
if s == 1:
st.append(t)
if t == N:
dic[s] = 0
result = 'IMPOSSIBLE'
for s in st:
if s in dic:
result = 'POSSIBLE'
b... | p03645 |
import sys
from collections import deque
N, M = list(map(int, sys.stdin.readline().strip().split()))
paths = [[] for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, sys.stdin.readline().strip().split()))
paths[a].append(b)
paths[b].append(a)
q = deque([(1, 0)])
while q:
p, c = q... | import sys
from collections import deque
N, M = list(map(int, sys.stdin.readline().strip().split()))
paths = [[] for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, sys.stdin.readline().strip().split()))
paths[a].append(b)
paths[b].append(a)
q = deque([(1, 0)])
visited = set()
while... | p03645 |
import sys
from collections import deque
N, M = list(map(int, sys.stdin.readline().strip().split()))
paths = [[] for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, sys.stdin.readline().strip().split()))
paths[a].append(b)
paths[b].append(a)
q = deque([(1, 0)])
visited = set()
while... | import sys
N, M = list(map(int, sys.stdin.readline().strip().split()))
paths = [[] for _ in range(N+1)]
for _ in range(M):
a, b = list(map(int, sys.stdin.readline().strip().split()))
paths[a].append(b)
paths[b].append(a)
for i in paths[1]:
for j in paths[i]:
if j == N:
... | p03645 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
fr... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
fr... | p03645 |
import collections
n,m=list(map(int,input().split()))
a,b,c=[],[],[]
for i in range(m):
A=list(map(int,input().split()))
a.append(A)
for i in range(m):
if a[i][1]==n:
b.append(a[i][0])
elif a[i][0]==1:
c.append(a[i][1])
if len(b)>0:
b=list(set(b))
c=list(set(c))
... | import collections
n,m=list(map(int,input().split()))
a,b,c=[],[],[]
for i in range(m):
A=list(map(int,input().split()))
a.append(A)
for i in range(m):
if a[i][1]==n:
b.append(a[i][0])
elif a[i][0]==1:
c.append(a[i][1])
if len(set(b)&set(c))>0:
print("POSSIBLE")
else:
... | p03645 |
N,M = list(map(int, input().split()))
es = [[] for _ in range(N+1)]
for i in range(M):
a,b = list(map(int, input().split()))
es[a].append(b)
for i in range(2,N):
if i in es[1] and N in es[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") |
N,M = list(map(int, input().split()))
s = set()
g = set()
for i in range(M):
a,b = list(map(int, input().split()))
if a == 1:
s.add(b)
elif b == N:
g.add(a)
ans = len(s & g) > 0
print(("POSSIBLE" if ans else "IMPOSSIBLE")) | p03645 |
import sys
def possible():
print("POSSIBLE")
sys.exit()
def main():
N, M = list(map(int, input().split()))
hashdict = dict()
for i in range(157):
hashdict[i] = list()
alist = list()
for i in range(M):
a, b = list(map(int, input().split()))
if a == 1:
... | import sys
def possible():
print("POSSIBLE")
sys.exit()
def main():
N, M = list(map(int, input().split()))
hashdict = dict()
for i in range(1009):
hashdict[i] = list()
alist = list()
for i in range(M):
a, b = list(map(int, input().split()))
if a == 1:
... | p03645 |
n,m=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(m):
c,d=list(map(int,input().split()))
if c==1:
a[d-1]=1
if d==n:
b[c-1]=1
success=0
for i in range(1,n):
if a[i]*b[i]==1:
success=1
if success==1:
print('POSSIBLE')
else:
print('IMPOSSIBLE') | n,m=list(map(int,input().split()))
a=[0]*(n+1)
b=[0]*(n+1)
for i in range(m):
x,y=list(map(int,input().split()))
if x==1:
a[y]=1
if y==n:
b[x]=1
ans=0
for i in range(n+1):
ans+=a[i]*b[i]
if ans==0:
print('IMPOSSIBLE')
else:
print('POSSIBLE') | p03645 |
N, M = [int(x) for x in input().split()]
S = []
from1 = []
fromN = []
ans = "IMPOSSIBLE"
for i in range(M):
S.append([int(x) for x in input().split()])
if S[i][0] == 1:
from1.append(S[i][1])
if S[i][1] == N:
fromN.append(S[i][0])
for x in from1:
if x in fromN:
ans = "POSSIBLE"
print(ans) | N, M = [int(x) for x in input().split()]
S1 = []
S2 = []
for i in range(M):
S1 = [int(x) for x in input().split()]
if S1[0] == 1:
S2.append(S1[1])
if S1[1] == N:
S2.append(S1[0])
if len(S2) == len(set(S2)):
print("IMPOSSIBLE")
else:
print("POSSIBLE")
| p03645 |
n, m = list(map(int, input().split()))
s = []
e = []
for i in range(m):
x, y = list(map(int, input().split()))
if x == 1:
s.append(y)
elif y == n:
e.append(x)
s.sort()
e.sort()
flag = False
for i in s:
for j in e:
if i < j:
break
if i == j:
... | n, m = list(map(int, input().split()))
s = [0 for i in range(n)]
e = [0 for i in range(n)]
for i in range(m):
x, y = list(map(int, input().split()))
if x == 1:
s[y] = 1
elif y == n:
e[x] = 1
flag = False
for i in range(n):
if s[i] == 1 and e[i] == 1:
flag = True
... | p03645 |
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
N,M = list(map(int,input().split()))
a = []
for i in range(M):
x,y = list(map(int,input().split()))
a.append([x,y])
ans = False
routes = {}
for i in range(N):
... | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
N,M = list(map(int,input().split()))
a = []
for i in range(M):
x,y = list(map(int,input().split()))
a.append([x,y])
ans = False
routes_s = []
routes_g = []
for a... | p03645 |
n,m = list(map(int,input().split()))
ahoge = []
hanege = []
for i in range(m):
ai,bi = list(map(int,input().split()))
if ai == 1:
ahoge.append(bi)
if bi == n:
hanege.append(ai)
flag = 0
for i in ahoge:
if i in hanege:
print("POSSIBLE")
flag = 1
break... | n,m = list(map(int,input().split()))
ahoge = []
hanege = []
for i in range(m):
ai,bi = list(map(int,input().split()))
if ai == 1:
ahoge.append(bi)
if bi == n:
hanege.append(ai)
ahoge.sort()
hanege.sort()
def bis(i):
under = 0
upper = len(hanege)-1
while under <= upp... | p03645 |
n,m = list(map(int,input().split()))
ahoge = []
hanege = []
for i in range(m):
ai,bi = list(map(int,input().split()))
if ai == 1:
ahoge.append(bi)
if bi == n:
hanege.append(ai)
ahoge.sort()
hanege.sort()
def bis(i):
under = 0
upper = len(hanege)-1
while under <= upp... | N,M = list(map(int,input().split()))
l = []
r = []
for i in range(M):
a,b = list(map(int,input().split()))
if a == 1:
l.append(b)
elif b == N:
r.append(a)
s = set(l).intersection(set(r))
print(("POSSIBLE" if len(s) else "IMPOSSIBLE")) | p03645 |
N, M = list(map(int, input().split()))
a = [0] * M
b = [0] * M
for i in range(M):
a[i], b[i] = list(map(int, input().split()))
# N in b
indices = [i for i, x in enumerate(b) if x == N]
# matched b of a in b
for i in range(len(indices)):
# print(a[indices[i]])
# print(b[indices[i]])
... | a=[]
b={}
n,m=list(map(int,input().split()))
for _ in range(m):
i,j=list(map(int,input().split()))
if i==1:
a.append(j)
elif j==n:
b[i]=1
for i in a:
if i in b:
print('POSSIBLE')
break
else:
print('IMPOSSIBLE') | p03645 |
n, m = list(map(int, input().split()))
dat_m = [[]] * (n+1)
dat_finish = [False] * (n+1)
for i in range(m):
a,b = list(map(int, input().split()))
dat_m[a] = dat_m[a] + [b]
if b == n:
dat_finish[a] = True
#print(dat_m)
#print(dat_finish)
c = False
for i in dat_m[1]:
if dat_finis... | n, m = list(map(int, input().split()))
dat = []
dat_m = [[]] * (n+1)
dat_finish = [False] * (n+1)
for i in range(m):
a,b = list(map(int, input().split()))
dat.append( (a,b) )
#print(dat)
for i in range(m):
a,b = dat[i]
if b == n:
dat_finish[a] = True
#print(dat_finish)
c = Fal... | p03645 |
from collections import deque
n, m = list(map(int, input().split()))
dat = deque([])
dat_finish = [False] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
dat.append((a, b))
for i in range(m):
a, b = dat[i]
if b == n:
dat_finish[a] = True
c = False
for i in r... | from collections import deque
n, m = list(map(int, input().split()))
dat = deque([])
dat2 = deque([])
dat_finish = [False] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
dat.append((a, b))
dat2.append((a, b))
for i in range(m):
a, b = dat.pop()
if b == n:
... | p03645 |
from collections import deque
n, m = list(map(int, input().split()))
dat = deque([])
dat2 = deque([])
dat_finish = [False] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
dat.append((a, b))
dat2.append((a, b))
for i in range(m):
a, b = dat.pop()
if b == n:
... | n, m = list(map(int, input().split()))
dat_m = [[] for x in range(n+1)]
for i in range(m):
a, b = list(map(int, input().split()))
dat_m[a].append(b)
c = False
for i in dat_m[1]:
if n in dat_m[i]:
c = True
print(("POSSIBLE" if c else "IMPOSSIBLE")) | p03645 |
import collections
N, M = list(map(int, input().split()))
graph = collections.defaultdict(lambda:set())
for _ in range(M):
a, b = list(map(int, input().split()))
graph[a-1].add(b-1)
graph[b-1].add(a-1)
def bfs(v, goal, graph, seen, next_v, rank):
for x in graph[v]:
if x == goal:
... | N, M = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def bfs(goal, graph, seen, next_v):
for x in graph[next_v[0][0]]:
if x == goal:
return True
... | p03645 |
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
toN = list([x for x in AB if N in x])
toN = [flatten for inner in toN for flatten in inner]
frm_first = list([x for x in AB if 1 in x])
frm_first = [flatten for inner in frm_first for flatten in inner]
for v in frm... | N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]
toN = list([x for x in AB if N in x])
toN = set([flatten for inner in toN for flatten in inner])
frm_first = list([x for x in AB if 1 in x])
frm_first = set([flatten for inner in frm_first for flatten in inner])
if... | p03645 |
import sys
input=sys.stdin.readline
import collections
def main():
N,M = list(map(int, input().split()))
A = []
for _ in range(M):
A.append(list(map(int, input().split())))
X1 = []
for a in A:
if a[0] == 1:
X1.append(a)
X2 = []
for a in A:
... | import sys
input=sys.stdin.readline
def main():
N,M = list(map(int, input().split()))
A = []
for _ in range(M):
A.append(list(map(int, input().split())))
p1 = set()
for a in A:
if a[0] == 1:
p1.add(a[1])
for a in A:
if a[1] == N and a[0] in p1:
... | p03645 |
import sys
input=sys.stdin.readline
def main():
N,M = list(map(int, input().split()))
A = []
for _ in range(M):
A.append(list(map(int, input().split())))
p1 = set()
for a in A:
if a[0] == 1:
p1.add(a[1])
for a in A:
if a[1] == N and a[0] in p1:
... | import sys
input=sys.stdin.readline
def main():
N,M = list(map(int, input().split()))
A = []
for _ in range(M):
A.append(list(map(int, input().split())))
p1 = [0]*N
for a in A:
if a[0] == 1:
p1[a[1]] = 1
for a in A:
if a[1] == N and p1[a[0]]:
... | p03645 |
# ABC068C - Cat Snuke and a Voyage (ARC079C)
def main():
N, M = tuple(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(M))
S, D = set(), set() # start, destination
for a, b in A:
if a == 1:
S |= {b}
if b == N:
D |= {a}... | # ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline
def main():
N, M = input().split()
A = tuple(input().split() for _ in range(int(M)))
S, D = set(), set() # start, destination
for a, b in A:
if a == "1":
S |= {b}
if b == N:
... | p03645 |
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline
def main():
N, M = tuple(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(M))
S, D = set(), set() # start, destination
for a, b in A:
if a == 1:
S |= {b}... | # ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline
def main():
N, M = tuple(map(int, input().split()))
A = tuple(tuple(map(int, input().split())) for _ in range(M))
S, D = set(), set() # start, destination
for a, b in A:
if a == 1:
S.add(b)... | p03645 |
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline
def dijkstra(s: int) -> int:
D = [float("inf")] * (N + 1) # distance
D[s] = 0
used = [0] * (N + 1)
while True:
v = -1
for i in range(1, N + 1):
if not used[i] and (v == -1 or D[i] ... | # ABC068C - Cat Snuke and a Voyage (ARC079C)
# DFS O(N + M)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int) -> None:
for u in G[v]: # search vertices available from v recursively
if dist[u] > dist[v] + 1:
dist[u] = dist[v] + 1
dfs(... | p03645 |
# ABC068C - Cat Snuke and a Voyage (ARC079C)
# DFS O(N + M)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int) -> None:
for u in G[v]: # search vertices available from v recursively
if dist[u] > dist[v] + 1:
dist[u] = dist[v] + 1
dfs(... | # ABC068C - Cat Snuke and a Voyage (ARC079C)
def main():
N, M, *AB = list(map(int, open(0).read().split()))
sources, targets = set(), set()
for a, b in zip(*[iter(AB)] * 2):
if a == 1:
sources.add(b)
if b == N:
targets.add(a)
flg = sources & targets # in... | p03645 |
N, M = list(map(int, input().split()))
edges = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
edges[a].append(b)
for i in edges[0]:
if N-1 in edges[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | N, M = list(map(int, input().split()))
edges = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
edges[a].append(b)
for i in edges[1]:
if N in edges[i]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | p03645 |
N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(M)]
G = [[] for _ in range(N)]
for x, y in L:
x, y = x-1, y-1
G[x].append(y)
G[y].append(x)
for v in G[0]:
for nv in G[v]:
if nv == N-1:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(M)]
G = [[] for _ in range(N)]
for x, y in L:
x, y = x-1, y-1
G[x].append(y)
G[y].append(x)
for v in G[0]:
if N-1 in G[v]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | p03645 |
N, M = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(M)]
G = [[] for _ in range(N)]
for x, y in L:
x, y = x-1, y-1
G[x].append(y)
G[y].append(x)
for v in G[0]:
if N-1 in G[v]:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
a, b = [int(x)-1 for x in input().split()]
G[a].append(b)
for v in G[0]:
for nv in G[v]:
if nv == N-1:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | p03645 |
from sys import stdin
from collections import deque
def main():
#入力
readline=stdin.readline
n,m=list(map(int,readline().split()))
G=[[] for _ in range(n+1)]
for _ in range(m):
a,b=list(map(int,readline().split()))
G[a].append(b)
G[b].append(a)
#bfs
q=deq... | from sys import stdin
def main():
#入力
readline=stdin.readline
n,m=list(map(int,readline().split()))
G=[[] for _ in range(n+1)]
for _ in range(m):
a,b=list(map(int,readline().split()))
G[a].append(b)
G[b].append(a)
s=set(G[1])
ans=False
while len(s)>0... | p03645 |
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ship_list1 = []
ship_list2 = []
count = 0
loop = False
for i in range(m):
if ab[i][0] == 1:
ship_list1.append(ab[i])
if ab[i][1] == n:
ship_list2.append(ab[i])
for ship1 in ship_list1... | n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
ship_list1 = []
ship_list2 = []
count = 0
loop = False
for i in range(m):
if ab[i][0] == 1:
ship_list1.append(ab[i][1])
if ab[i][1] == n:
ship_list2.append(ab[i][0])
if len(set(ship_l... | p03645 |
#21:06
N,M=list(map(int,input().split()))
l=[]
for i in range(M):
l.append(list(map(int,input().split())))
first=[]
last=[]
for t in l:
if t[0]==1:
first.append(t[1])
elif t[1]==N:
last.append(t[0])
flag=False
for s in first:
if s in last:
flag=True
brea... | #21:06
N,M=list(map(int,input().split()))
l=[]
for i in range(M):
l.append(list(map(int,input().split())))
first=[]
last=[]
H=[[] for i in range(N)]
for t in l:
H[t[0]-1].append(t[1])
H[t[1]-1].append(t[0])
#if H[0][0]==H[N-1][0]
#print(any(N in H[0]))
#for v in H[0]:
if any(N in H[v-1] for v ... | p03645 |
import math
def solve(n, m, a, b):
islands = []
for i in range(m):
if(a[i] == 1):
islands.append(b[i])
if(b[i] == 1):
islands.append(a[i])
for i in range(m):
if(a[i] == n and b[i] in islands):
return "POSSIBLE"
if(b[i] == n... | def solve(n, m, a, b):
islands = set()
for i in range(m):
if(a[i] == 1):
islands.add(b[i])
if(b[i] == 1):
islands.add(a[i])
for i in range(m):
if(a[i] == n and b[i] in islands):
return "POSSIBLE"
if(b[i] == n and a[i] in islan... | p03645 |
n, m = list(map(int, input().split()))
s = []
e = []
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
s.append((a, b))
if b == n:
e.append((a, b))
for a, b in s:
for a2, b2 in e:
if b == a2:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | n, m = list(map(int, input().split()))
s = []
e = []
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
s.append(b)
if b == n:
e.append(a)
if set(s) & set(e):
print('POSSIBLE')
else:
print('IMPOSSIBLE') | p03645 |
N,M = list(map(int,input().split()))
a=[0]*M
b=[0]*M
c=[] #最初の候補地
for i in range(M):
a[i],b[i]=list(map(int,input().split()))
if a[i]==1:
if b[i] not in c:
c.append(b[i])
for j in range(M):
if a[j]!=1:
if a[j] in c:
if b[j]==N:
print("POSSIBLE")
break
els... | N,M = list(map(int,input().split()))
a=[0]*M
b=[0]*M
c=set() #最初の候補地
for i in range(M):
a[i],b[i]=list(map(int,input().split()))
if a[i]==1:
if b[i] not in c:
c.add(b[i])
for j in range(M):
if a[j]!=1:
if a[j] in c:
if b[j]==N:
print("POSSIBLE")
break
els... | p03645 |
from collections import deque
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
sx=0
gx=n-1
tree=[[] for i in range(n)]
for i in l:
tree[i[0]-1].append(i[1]-1)
tree[i[1]-1].append(i[0]-1)
dist=[-1 for i in range(n)]
dist[sx]=0
que=deque()
que.append(sx... | n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
tree=[[] for i in range(n)]
for i in l:
tree[i[0]-1].append(i[1]-1)
tree[i[1]-1].append(i[0]-1)
for i in tree:
if 0 in i and n-1 in i:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | p03645 |
n,m=list(map(int,input().split()))
tree=[[] for i in range(n)]
for i in range(m):
a,b=list(map(int,input().split()))
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
exit()
print('IMPOSS... | p03645 |
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
exit()
print('IMPOSS... | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
def main():
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('PO... | p03645 |
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
def main():
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a]+=[b]
tree[b]+=[a]
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('POSSIBLE')
... | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
def main():
n,m=nii()
tree=[[] for i in range(n)]
for i in range(m):
a,b=nii()
a-=1
b-=1
tree[a].append(b)
tree[b].append(a)
for i in tree[0]:
for j in tree[i]:
if j==n-1:
print('PO... | p03645 |
#!/usr/bin/env python3
from collections import deque
n, m = list(map(int, input().split()))
graph = [deque([]) for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
for i in graph[1]:
if n in graph[i]:
print("POSSIBLE")... | #!/usr/bin/env python3
n, m = input().split()
a = set()
b = set()
for _ in range(int(m)):
r = set(input().split())
if "1" in r:
a |= r
if n in r:
b |= r
print(("POSSIBLE" if len(a & b) > 0 else "IMPOSSIBLE"))
| p03645 |
# coding: utf-8
N,M=list(map(int,input().split()))
G=[[] for i in range(N+1)]
for i in range(M):
a,b=list(map(int,input().split()))
G[a].append(b)
G[b].append(a)
flg=False
near=[]
for i in range(len(G[1])):
near.append(G[1][i])
for i in range(len(G[N])):
if G[N][i] in near:
... | # coding: utf-8
N,M=list(map(int,input().split()))
G=[[] for i in range(N+1)]
for i in range(M):
a,b=list(map(int,input().split()))
G[a].append(b)
G[b].append(a)
flg=False
near=[False for i in range(N+1)]
for i in range(len(G[1])):
near[G[1][i]]=True
for i in range(len(G[N])):
... | p03645 |
#!/usr/bin/python
import sys
def main(argv):
line = sys.stdin.readline()
while line:
N, M = [int(x) for x in line.split(" ", 2)]
services_1 = []
services_n = []
for i in range(M):
a, b = [int(x) for x in sys.stdin.readline().split(" ", 2)]
... | #!/usr/bin/python
import sys
def main(argv):
line = sys.stdin.readline()
while line:
N, M = [int(x) for x in line.split(" ", 2)]
services_1 = {}
services_n = []
for i in range(M):
a, b = [int(x) for x in sys.stdin.readline().split(" ", 2)]
... | p03645 |
import sys
import collections
input = sys.stdin.readline
def main():
N, M = [int(x) for x in input().split()]
ab = [[] for j in range(N + 1)]
distance = [0] * (N + 1)
for _ in range(M):
a, b = [int(x) for x in input().split()]
ab[a].append(b)
ab[b].append(a)
... | N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]
x = set()
for a, b in AB:
if a == 1:
x.add(b)
if b == 1:
x.add(a)
f = False
for a, b in AB:
if (a in x and b == N) or (b in x and a == N):
f = True
if f:
pri... | p03645 |
n,m = list(map(int,input().split()))
one_li = []
to_n_li = []
for _ in range(m):
a,b = list(map(int,input().split()))
if a == 1:
one_li.append(b)
if b == n:
to_n_li.append(a)
#print(one_li,to_n_li)
for o in list(set(one_li)):
if o in list(set(to_n_li)):
print('POSSIBL... | n,m = list(map(int,input().split()))
one_li = []
to_n_li = []
for _ in range(m):
a,b = list(map(int,input().split()))
if a == 1:
one_li.append(b)
if b == n:
to_n_li.append(a)
ll = len(set(one_li) & set(to_n_li))
if ll == 0:
print('IMPOSSIBLE')
else:
print('POSSIBLE') | p03645 |
N, M = list(map(int,input().split( )))
l = []
for i in range(M):
a,b = list(map(int,input().split( )))
l.append([a, b])
ans = 'IMPOSSIBLE'
for i in range(M):
if l[i][0] == 1:
t = l[i][1]
for j in range(M):
if l[j][0] == t and l[j][1] == N:
ans = 'POSSIBLE'
print(ans) | N, M = list(map(int,input().split( )))
l = []
for i in range(M):
a,b = list(map(int,input().split( )))
l.append([a, b])
t_a = []
t_b = []
ans = 'IMPOSSIBLE'
for i in range(M):
if l[i][0] == 1:
t_a.append(l[i][1])
elif l[i][1] == N:
t_b.append(l[i][0])
t_and = set(t_a) & set(t_b)
t_and_l = list... | p03645 |
arr = input().split()
n = int(arr[0])
m = int(arr[1])
a = [0] * m
b = [0] * m
mat = [[0] * n for i in range(n)]
path = []
for i in range(m):
tmp = input().split()
a[i] = int(tmp[0])
b[i] = int(tmp[1])
mat[a[i]-1][b[i]-1] = 1
if a[i] == 1:
path.append(b[i]-1)
flag = False
... | arr = input().split()
n = int(arr[0])
m = int(arr[1])
x = []
y = []
for i in range(m):
a,b = list(map(int, input().split()))
if a == 1:
x.append(b)
if b == n:
y.append(a)
if len(set(x+y)) < len(x) + len(y):
print('POSSIBLE')
else:
print('IMPOSSIBLE')
| p03645 |
island, fune = map(int, input().split(" "))
route = []
for i in range(fune):
route.append(list(map(int, input().split(" "))))
pos = False
temp = []
for i in range(fune):
if route[i][0] == 1:
temp.append(route[i][1])
for j in range(fune):
if route[j][1] == island:
if route[j][0] in... | island, fune = map(int, input().split(" "))
route = []
for i in range(fune):
route.append(list(map(int, input().split(" "))))
temp = []
for i in range(fune):
if route[i][0] == 1:
temp.append(route[i][1])
for j in range(fune):
if route[j][1] == island:
temp.append(route[j][0])
... | p03645 |
n,m = list(map(int,input().split()))
a = [set(map(int,input().split())) for i in range(m)]
for i in range(m-1):
for j in range(i+1,m):
if ((a[i]|a[j])-(a[i]&a[j])) == {1,n}:
print("POSSIBLE")
exit()
else:
print("IMPOSSIBLE") | n,m = list(map(int,input().split()))
X = set()
Y = set()
for i in range(m):
a,b = list(map(int,input().split()))
if a == 1:
X.add(b)
if b == n:
Y.add(a)
print(("IMPOSSIBLE" if not X&Y else "POSSIBLE")) | p03645 |
n, m = list(map(int, input().split()))
arr = []
for i in range(m):
a, b = list(map(int, input().split()))
arr.append((a,b))
one = set([b for a, b in arr if a == 1])
last = set([a for a, b in arr if b == n])
connect = one & last
if len(connect) >= 1:
print("POSSIBLE")
else:
print("IMPOSSIBLE... | n, m = list(map(int, input().split()))
arr_ = [tuple(map(int, input().split())) for _ in range(m)]
one = set([b for a, b in arr_ if a == 1])
last = set([a for a, b in arr_ if b == n])
connect = one & last
if len(connect) >= 1:
print("POSSIBLE")
else:
print("IMPOSSIBLE") | p03645 |
N,M = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
b = []
c = []
for i in a:
if i[0]==1:
b.append(i)
elif i[1]==N:
c.append(i)
for i in b:
for j in c:
if i[1]==j[0]:
print('POSSIBLE')
exit()
print('IMPOSSIBLE') | N,M = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
b = set()
for i in a:
if i[0]==1 or i[1]==N:
b.add((i[0],i[1]))
for i in range(2,N):
if (1,i) in b and (i,N) in b:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
| p03645 |
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1, i) in m and (i, N) in m:
print("POSS... | import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1... | p03645 |
import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1... | import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
m = set()
for _ in range(M):
a, b = list(map(int, input().split()))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1, i) i... | p03645 |
n, m = list(map(int, input().split()))
c = [False for i in range(200001)]
d = [False for i in range(200001)]
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
c[b] = True
if b == n:
d[a] = True
for i in range(200001):
if c[i] and d[i]:
print ("POSSIBLE")
exit()
print ("IMPOSS... | n, m = list(map(int, input().split()))
c = [False for i in range(200000)]
d = [False for i in range(200000)]
for i in range(m):
a, b = list(map(int, input().split()))
if a == 1:
c[b] = True
if b == n:
d[a] = True
for i in range(200000):
if c[i] and d[i]:
print ("POSSIBLE")
exit()
print ("IMPOSS... | p03645 |
n,m=list(map(int,input().split()))
ab=[]
for i in range(m):
a,b=list(map(int,input().split()))
ab.append((a,b))
#print(ab)
mid=[]
for (i,j) in ab:
if i==1:
mid.append(j)
for (i,j) in ab:
if i in mid and j==n:
print("POSSIBLE");exit()
print("IMPOSSIBLE")
| n,m=list(map(int,input().split()))
c=[]
d=[]
for i in range(m):
a,b=list(map(int,input().split()))
if a==1:
c.append(b)
if b==n:
d.append(a)
#O(m)
if len(set(c)&set(d))!=0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| p03645 |
n, m = list(map(int, input().split()))
ships = [[int(x) for x in input().split()] for x in range(m)]
judge = False
relay = []
goal = []
for ship in ships:
if n in ship:
goal.append(ship[0])
elif 1 in ship:
relay.append(ship[1])
res = False
if len(goal) == 0 or len(relay) == 0:
... | n, m = list(map(int, input().split()))
ships = [[int(x) for x in input().split()] for x in range(m)]
judge = False
relay = []
goal = []
for ship in ships:
if n in ship:
goal.append(ship[0])
elif 1 in ship:
relay.append(ship[1])
res = False
if len(goal) == 0 or len(relay) == 0:
... | p03645 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
A = [b for a, b in AB if a == 1]
B = [a for a, b in AB if b == N]
result = 'IMPOSSIBLE'
for a in A:
if a in B:
... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
N, M = list(map(int, input().split()))
# AB = [list(map(int, input().split())) for _ in range(M)]
from_1 = [False] * N
to_N = [False] * N
for _ in range(M):
a, b = list(map(int, input().split()))
if a == 1:
... | p03645 |
# C - Cat Snuke and a Voyage
N,M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
if A[i][1] == N:
goal2.append(A[i][0])
elif A[i][0] == 1:
goal1.append(A[i][1])
else:
pass
for k in range(... | # C - Cat Snuke and a Voyage
N,M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]
goal2 = []
goal1 = []
for i in range(M):
if A[i][1] == N:
goal2.append(A[i][0])
elif A[i][0] == 1:
goal1.append(A[i][1])
else:
pass
if len(set(goal... | p03645 |
N,M=[int(x) for x in input().split()]
set1=set()
setn=set()
for i in [None]*M:
ipt=[int(x) for x in input().split()]
if 1 in ipt:
set1 = set1.union(ipt)
if N in ipt:
setn = setn.union(ipt)
if set1 & setn:
print("POSSIBLE")
else:
print("IMPOSSIBLE") | N,M=[int(x) for x in input().split()]
set1=[]
setn=[]
for i in [None]*M:
ipt=[int(x) for x in input().split()]
if 1 in ipt:
set1 += ipt
if N in ipt:
setn += ipt
if set(set1) & set(setn):
print("POSSIBLE")
else:
print("IMPOSSIBLE") | p03645 |
import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
Set = set()
for i in range(M):
a,b = list(map(int,input().split()))
Set.add((a,b))
Set.add((b,a)) #ADD
for j in range(2,N):
if (1,j) in Set and (j,N) in Set:
... | import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
Set = set()
for i in range(M):
a,b = list(map(int,input().split()))
Set.add((a,b))
Set.add((b,a)) #condition
for j in range(2,N):
if (1,j) in Set and (j,N) in Set:
... | p03645 |
N, M = list(map(int, input().split()))
ab=[]
for _ in range(M):
ab.append(tuple(map(int, input().split())))
#print(ab)
for island in range(2,N):
if (1,island) in ab and (island,N) in ab:
print('POSSIBLE')
break
else:
print('IMPOSSIBLE') | N, M = list(map(int, input().split()))
ab=[]
for _ in range(M):
ab.append(tuple(map(int, input().split())))
#print(ab)
from_1=set([el[1] for el in ab if el[0]==1])
from_N=set([el[0] for el in ab if el[1]==N])
#print(from_1, from_N)
if from_1 & from_N:
print('POSSIBLE')
else:
print('IMPOSSIBLE')... | p03645 |
N, M = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(M)]
c = []
d = []
ans = "IMPOSSIBLE"
for i in range(M):
if ab[i][0] == 1:
c.append(ab[i][1])
elif ab[i][1] == N:
d.append(ab[i][0])
for i in range(len(c)):
if c[i] in d:
ans = "POSSI... | N, M = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(M)]
c = []
d = []
ans = "IMPOSSIBLE"
for i in range(M):
if ab[i][0] == 1:
c.append(ab[i][1])
elif ab[i][1] == N:
d.append(ab[i][0])
e = list(set(c + d))
if len(e) < len(c)+ len(d):
ans = "PO... | p03645 |
N,M = list(map(int,input().split()))
root1 = []
root2 = []
for i in range(M):
ai,bi = list(map(int,input().split()))
if ai==1:
tmp = [ai,bi]
root1.append(tmp)
else:
tmp = [ai,bi]
root2.append(tmp)
for i in range(len(root1)):
for j in range(len(root2)):
... | N,M = list(map(int,input().split()))
root1 = set()
root2 = set()
for i in range(M):
ai,bi = list(map(int,input().split()))
if ai==1:
root1.add(bi)
if bi==N:
root2.add(ai)
if set(root1) & set(root2):
print('POSSIBLE')
else:
print('IMPOSSIBLE') | p03645 |
N, M = list(map(int, (input().split())))
L = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
L[a - 1][b - 1] = 1
L[b - 1][a - 1] = 1
#print(L)
for i in range(N):
if L[0][i] == 1:
if L[i][N - 1] == 1:
print("POSSIBLE")
... | N, M = list(map(int, (input().split())))
L1 = [0 for i in range(N)]
L2 = [0 for j in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
if a == 1:
L1[b - 1] = 1
elif b == N:
L2[a - 1] = 1
for i in range(N):
if L1[i] == L2[i] == 1:
print("POSSIBLE")
... | p03645 |
from sys import stdin
input = stdin.readline
N,M = list(map(int,(input().split())))
ans = "IMPOSSIBLE"
seta,setb = set(),set()
af,bf = [False]*M,[False]*M
for m in range(M):
a,b = list(map(int,(input().split())))
if a-1 == 0:
af[m] = True
seta.add(b-1)
if b-1 == N-1:
... | from sys import stdin
input = stdin.readline
N,M = list(map(int,(input().split())))
ans = "IMPOSSIBLE"
seta,setb = set(),set()
for m in range(M):
a,b = list(map(int,(input().split())))
if a == 1:
seta.add(b)
if b == N:
setb.add(a)
if seta & setb:
print("POSS... | p03645 |
import fileinput
input = fileinput.input().readline
N,M = list(map(int,(input().split())))
seta,setb = set(),set()
for m in range(M):
a,b = list(map(int,(input().split())))
if a == 1:
seta.add(b)
if b == N:
setb.add(a)
if seta & setb:
print("POSSIBLE")
else:... | import sys
lines = sys.stdin.readlines()
N,M = list(map(int,(lines[0].split())))
seta,setb = set(),set()
for m in range(1,M+1):
a,b = list(map(int,(lines[m].split())))
if a == 1:
seta.add(b)
if b == N:
setb.add(a)
if seta & setb:
print("POSSIBLE")
else:
print("IM... | p03645 |
n,m=list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
g[a].append(b)
g[b].append(a)
flag=False
for i in g[1]:
for j in g[i]:
if j==n:
flag=True
if flag==True:
print('POSSIBLE')
else:
print('IMPOSSIBLE') | n,m=list(map(int,input().split()))
s1=set()
s2=set()
for _ in range(m):
a,b=list(map(int,input().split()))
if a==1:
s1.add(b)
if b==n:
s2.add(a)
if len(s1&s2)!=0:
print('POSSIBLE')
else:
print('IMPOSSIBLE') | p03645 |
import sys
from collections import Counter
# sys.stdin = open('c1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
n, m = read_int_l... | import sys
from collections import Counter
# sys.stdin = open('c1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def solve():
... | p03645 |
from collections import deque
def solve(n, m, AB):
g = [[] for _ in range(n)]
for a, b in AB:
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
q = deque(maxlen = n)
q.append((0, 0))
used = {0}
while len(q) > 0:
i, d = q.popleft()
if d >= 2:
... | n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)]
cands = set(b if a == 1 else a for a, b in AB if a == 1 or b == 1)
if any(a in cands and b == n or b in cands and a == n for a, b in AB):
print('POSSIBLE')
else:
print('IMPOSSIBLE')
| p03645 |
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(m)]
pot_starts = []
pot_ends = []
for i in a:
if i[0] == 1:
pot_starts.append(i[1])
elif i[1] == n:
pot_ends.append(i[0])
for i in set(pot_starts):
if i in pot_ends:
print("POS... | n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(m)]
# n, m = 3, 2
# a = [[1, 2], [2, 3]]
pot_starts = []
pot_ends = []
for i in a:
if i[0] == 1:
pot_starts.append(i[1])
elif i[1] == n:
pot_ends.append(i[0])
if set(pot_starts).intersec... | p03645 |
N, M = [int(i) for i in input().split()]
ab = []
possible = False
for _ in range(M):
ab.append([int(i) for i in input().split()])
c = []
e = []
for d in ab:
if d[1] == N:
c.append(d[0])
elif d[0] == 1:
e.append(d[1])
for f in e:
if f in c:
possible = Tru... | N, M = [int(i) for i in input().split()]
ab = []
possible = False
for _ in range(M):
ab.append([int(i) for i in input().split()])
c = []
e = []
for d in ab:
if d[1] == N:
c.append(d[0])
elif d[0] == 1:
e.append(d[1])
if len(set(c) & set(e)):
print('POSSIBLE')
el... | p03645 |
n,m = list(map(int,input().split()))
first = []
second = []
for i in range(m):
a,b = list(map(int,input().split()))
if a == 1:
first.append(b)
if b == n:
second.append(a)
for i in range(len(first)):
if first[i] in second:
print('POSSIBLE')
exit()
else:
... | n,m = list(map(int,input().split()))
c = []
for i in range(m):
a,b = list(map(int,input().split()))
if a == 1:
c.append(b)
if b == n:
c.append(a)
if len(c) == len(set(c)):
print('IMPOSSIBLE')
else:
print('POSSIBLE') | p03645 |
N, M = list(map(int,input().split()))
AB = []
for m in range(M):
a,b = list(map(int,input().split()))
AB.append((a,b))
AB = sorted(AB)
first = []
for a,b in AB:
if a == 1:
first.append(b)
else:
break
AB = sorted(AB, key=lambda x:x[1], reverse=True)
sec = []
for a,b in... | import bisect
N, M = list(map(int,input().split()))
AB = []
for m in range(M):
a,b = list(map(int,input().split()))
AB.append((a,b))
AB = sorted(AB)
first = []
for a,b in AB:
if a == 1:
first.append(b)
else:
break
AB = sorted(AB, key=lambda x:x[1], reverse=True)
sec... | p03645 |
N,M = list(map(int,input().split()))
one_to = []
to_N = []
for _ in range(M):
a,b = list(map(int,input().split()))
if a == 1:
one_to.append(b)
if b == N:
to_N.append(a)
one_to.sort()
to_N.sort()
ans = 0
for i in one_to:
count = 0
for j in range(len(to_N)):
if ... | N,M = list(map(int,input().split()))
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
a,b = list(map(int,input().split()))
if a == 1:
dic[str(b)] += 1
if dic[str(b)] == 2:
ans = 1
if b == N:
dic[str(a)] += 1
if dic[str(a)] == 2:
... | p03645 |
N, M = list(map(int,input().split()))
ABs = list([list(map(int,input().split())) for _ in range(M)])
ship1 =[]
shipn =[]
for ab in ABs:
if ab[0]==1:ship1.append(ab[1])
elif ab[1]==N:shipn.append(ab[0])
jdg=False
for j in ship1:
if j in shipn:jdg=True
if jdg:print('POSSIBLE')
... | import sys
input = sys.stdin.readline
N, M = list(map(int,input().split()))
ABs = list([list(map(int,input().split())) for _ in range(M)])
ship1 =[]
shipn =[]
for ab in ABs:
if ab[0]==1:ship1.append(ab[1])
elif ab[1]==N:shipn.append(ab[0])
if list(set(ship1) & set(shipn)) ==[]:print('I... | p03645 |
n, m = list(map(int, input().split()))
ab, c, d = [], [], []
for i in range(m):
ab.append(list(map(int, input().split())))
for i in range(m):
if(ab[i][0] == n):
c.append(ab[i][1])
elif(ab[i][1] == n):
c.append(ab[i][0])
elif(ab[i][0] == 1):
d.append(ab[i][1])
elif(... | n, m = list(map(int, input().split()))
ab, c, d = [], set(), set()
for i in range(m):
ab.append(list(map(int, input().split())))
for i in range(m):
if(ab[i][0] == n):
c.add(ab[i][1])
elif(ab[i][1] == n):
c.add(ab[i][0])
elif(ab[i][0] == 1):
d.add(ab[i][1])
elif(ab[... | p03645 |
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
g[a].append(b)
g[b].append(a)
from collections import deque
queue = deque([])
queue.append(0)
visited = [-1]*n
visited[0] = 0
while queue:
x = queu... | n, m = list(map(int, input().split()))
l1 = [0]*n
l2 = [0]*n
for i in range(m):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
if a == 0:
l1[b] = 1
elif b == n-1:
l2[a] = 1
else:
continue
for j in range(n):
if l1[j] == 1 and l2[j] == 1:
print('POSSIBLE')
exit()... | p03645 |
n, m = list(map(int, input().split()))
l1 = [0]*n
l2 = [0]*n
for i in range(m):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
if a == 0:
l1[b] = 1
elif b == n-1:
l2[a] = 1
else:
continue
for j in range(n):
if l1[j] == 1 and l2[j] == 1:
print('POSSIBLE')
exit()... | n, m = list(map(int, input().split()))
S = set()
for i in range(m):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
S.add((a, b))
for i in range(1, n-1):
if (0, i) in S and (i, n-1) in S:
print('POSSIBLE')
exit()
else:
print('IMPOSSIBLE')
| p03645 |
n,m = list(map(int, input().split()))
ab = [[] for _ in range(n)]
for _ in range(m):
a,b = [int(i)-1 for i in input().split()]
ab[a].append(b)
ab[b].append(a)
for i in ab[0]:
if ab[i].count(n-1) >= 1:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | n,m = list(map(int, input().split()))
ab = [[] for _ in range(n+1)]
for _ in range(m):
a,b = list(map(int, input().split()))
ab[a].append(b)
ab[b].append(a)
for i in ab[1]:
for j in ab[i]:
if j == n:
print("POSSIBLE")
exit()
print("IMPOSSIBLE") | p03645 |
n,m = list(map(int, input().split()))
lsta = []
lstb = []
for i in range(m):
a,b = list(map(int, input().split()))
if a==1:
lsta.append(b)
if b==n:
lstb.append(a)
for i in lsta:
if i in lstb:
print("POSSIBLE")
exit()
print("IMPOSSIBLE")
| n,m = list(map(int, input().split()))
lsta = [0 for i in range(n+1)]
lstb = [0 for i in range(n+1)]
for i in range(m):
a,b = list(map(int, input().split()))
if a==1:
lsta[b]=1
if b==n:
lstb[a]=1
for i in range(n+1):
if lsta[i]==1 and lstb[i]==1:
print("POSSIBLE")
... | p03645 |
import queue
n,m = list(map(int,input().split()))
adj = [[] for i in range(n)]
dist = [-1]*n
for i in range(m):
a,b = list(map(int,input().split()))
adj[a-1].append(b-1)
adj[b-1].append(a-1)
q = queue.Queue()
dist[0] = 0
q.put(0)
while not q.empty():
x = q.get()
for f in... | from collections import deque
n,m = list(map(int,input().split()))
adj = [[] for i in range(n)]
dist = [-1]*n
for i in range(m):
a,b = list(map(int,input().split()))
adj[a-1].append(b-1)
adj[b-1].append(a-1)
q = deque()
dist[0] = 0
q.append(0)
while len(q) > 0:
x = q.popleft()
... | p03645 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.