Problem p03805 (python)

Fixed submission:
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
visit[1]=1
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].append(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in node[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
visit[1]=1
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].appedn(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in node[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].appedn(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in node[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
visit=[0]*(n+1)
node=[[] for i in range(n+1)]
for i in number:
  node[i[0]].append(i[1])
  node[i[1]].appedn(i[0])
ans=0
def dfs(x):
  global ans
  if visit.count(1)==n:
    ans+=1
    return 0
  for i in visit[x]:
    if visit[i]==0:
      visit[i]=1
      dfs(i)
      visit[i]=0
  return 0
dfs(1)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20)
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
startwithone=[i for i in number if i[0]==1]
notstartwithone=[i for i in number if i[0]!=1]
if len(startwithone)==0:
  print(0)
  exit()
if len(startwithone)==0:
  if n==2:
    print(1)
    exit()
  print(0)
  exit()
ans=0
flag2=0
def find(x):
  if root[x]==x:
    return x
  return find(root[x])
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  if find(1)==find(x):
    root[y]=x
  else:
    root[x]=y
def dfs(i,flag):
  global ans
  global root
  global flag2
  flag2=flag
  if bin(flag)[2:].count("1")!=n-2 or len(notstartwithone)<i:
    if len(notstartwithone)<i:
      return 0
    dfs(i+1,flag|2**i)
    dfs(i+1,flag)
  root=[i for i in defroot]
  rank=[i for i in defrank]
  for j in range(len(notstartwithone)):
    if flag&2**j>0:
      union(notstartwithone[j][0],notstartwithone[j][1])
  for j in range(1,n):
    if check(j,j+1)==False:
      return 0
  if len(set(root))==n:
    ans+=1
for i in startwithone:
  root=[i for i in range(n+1)]
  rank=[0]*(n+1)
  union(i[0],i[1])
  defroot=[i for i in root]
  defrank=[i for i in rank]
  dfs(0,0)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20)
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
startwithone=[i for i in number if i[0]==1]
notstartwithone=[i for i in number if i[0]!=1]
ans=0
flag2=0
def find(x):
  if root[x]==x:
    return x
  return find(root[x])
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  if find(1)==find(x):
    root[y]=x
  else:
    root[x]=y
def dfs(i,flag):
  global ans
  global root
  global flag2
  flag2=flag
  if bin(flag)[2:].count("1")!=n-2 or len(notstartwithone)<i:
    if len(notstartwithone)<i:
      return 0
    dfs(i+1,flag|2**i)
    dfs(i+1,flag)
  root=[i for i in defroot]
  rank=[i for i in defrank]
  for j in range(len(notstartwithone)):
    if flag&2**j>0:
      union(notstartwithone[j][0],notstartwithone[j][1])
  for j in range(1,n):
    if check(j,j+1)==False:
      return 0
  if len(set(root))==n:
    ans+=1
for i in startwithone:
  root=[i for i in range(n+1)]
  rank=[0]*(n+1)
  union(i[0],i[1])
  defroot=[i for i in root]
  defrank=[i for i in rank]
  dfs(0,0)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
ans=0
root=[i for i in range(n)]
rank=[0]*(n+1)
def find(x):
  if root[x]==x:
    return x
  root[x]=find(root[x])
  return root[x]
def check(x,y):
  return find(x)==find(y)
def union(x,y):
  x=find(x)
  y=find(y)
  if rank[x]>=rank[y]:
    root[y]=x
  else:
    root[x]=y
  if rank[x]==rank[y]:
    rank[x]+=1
def dfs(i,flag):
  if str(flag).count(1)!=n-1:
    if i==m:
      return 0
    dfs(i+1,flag|2**i)
    dfs(i+1|flag)
  root=[i for i in range(n)]
  rank=[0]*(n+1)
  for j in range(m):
    if flag&2**j>0:
      union(number[j][0],number[j][1])
  for j in range(1,n):
    if check(i,i+1)==False:
      return 0
  ans+=1
dfs(0,0)
print(ans)