problem_id stringlengths 6 6 | user_id stringlengths 10 10 | time_limit float64 1k 8k | memory_limit float64 262k 1.05M | problem_description stringlengths 48 1.55k | codes stringlengths 35 98.9k | status stringlengths 28 1.7k | submission_ids stringlengths 28 1.41k | memories stringlengths 13 808 | cpu_times stringlengths 11 610 | code_sizes stringlengths 7 505 |
|---|---|---|---|---|---|---|---|---|---|---|
p02761 | u901582103 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m=map(int,input().split())\nL=[10]*n\nprint(L)\nfor i in range(m):\n\ts,c=map(int,input().split())\n\tif L[s-1]==10 or L[s-1]==c:\n\t\tL[s-1]=c\n\t\tprint(L)\n\telse:\n\t\tprint(-1)\n\t\texit()\nif n==1:\n\tif L[0]==10:\n\t\tprint(0)\n\t\texit()\n\telse:\n\t\tprint(L[0])\n\t\texit()\nelse:\n\tif L[0]==10:\n\t\tL[0]=1\n\telif L[0]==0:\n\t\tprint(-1)\n\t\texit()\n\telse:\n\t\tfor i in range(1,n):\n\t\t\tif L[i]==10:\n\t\t\t\tL[i]=0\n\tprint(''.join(map(str,L)))", "n,m=map(int,input().split())\nL=[10]*n\nfor i in range(m):\n\ts,c=map(int,input().split())\n\tif L[s-1]==10 or L[s-1]==c:\n\t\tL[s-1]=c\n\telse:\n\t\tprint(-1)\n\t\texit()\nif n==1:\n\tif L[0]==10:\n\t\tprint(0)\n\t\texit()\n\telse:\n\t\tprint(L[0])\n\t\texit()\nelse:\n\tif L[0]==10:\n\t\tL[0]=1\n\telif L[0]==0:\n\t\tprint(-1)\n\t\texit()\n\tfor i in range(1,n):\n\t if L[i]==10:\n\t L[i]=0\n\tprint(''.join(map(str,L)))"] | ['Wrong Answer', 'Accepted'] | ['s463350755', 's718745218'] | [3064.0, 3064.0] | [17.0, 17.0] | [397, 376] |
p02761 | u903699277 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["def main():\n \n \n \n N, N = map(int, input().split())\n SC = [list(map(int, input().split())) for _ in [0]*N ]\n SC.sort()\n\n num = (10 ** N) - 1\n keta = 1\n\n if SC[0][0] != 0:\n print('-1')\n exit()\n\n for S,C in SC:\n if S == 1 and C == 0:\n print('-1')\n exit()\n\n if S == keta:\n tmp = C * (10 ** (N - S))\n if tmp < num:\n num = tmp\n elif S > keta:\n keta = S\n tmp = C * (10 ** (N - S))\n num += tmp\n\n print(num)\n\n\nmain()", 'n,m,*z=map(int,open(0).read().split())\nfor i in range(10**n):\n S=str(i)\n if len(S)==n:\n if all(S[s-1]==str(c)for s,c in zip(z[0::2],z[1::2])):\n print(S)\n quit()\nprint(-1)'] | ['Runtime Error', 'Accepted'] | ['s030275297', 's482499214'] | [3064.0, 3060.0] | [18.0, 23.0] | [640, 185] |
p02761 | u904081717 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import sys\n\nnmlist = list(map(int, input().split()))\nN = nmlist[0]\nM = nmlist[1]\norder_list = [list(map(int, input().split())) for _ in range(M)]\n\ncnt = 0\n\nfor k in range(M):\n if order_list[k] == [1,0]:\n cnt += 1\n\nif cnt == M:\n print(0)\n sys.exit()\n\nfor j in range(M):\n if order_list[j][0] > N:\n print(-1)\n sys.exit()\n if order_list[j][0] == 1 and order_list[j][1] == 0:\n print(-1)\n sys.exit()\n\nfor i in range(M):\n if Number[order_list[i][0]-N+2] != 0 and Number[order_list[i][0]-N+2] != order_list[i][1]:\n print(-1)\n sys.exit()\n Number[order_list[i][0]-N+2] = order_list[i][1]\n\nif Number[3-N] == 0:\n Number[3-N] = 1\n\nprint(100*Number[0]+10*Number[1]+Number[2])', 'import sys\n \nnmlist = list(map(int, input().split()))\nN = nmlist[0]\nM = nmlist[1]\norder_list = [list(map(int, input().split())) for _ in range(M)]\n \nNumber = [0,0,0]\ncnt = 0\n\nfor k in range(M):\n if N==1 and order_list[k] == [1,0]:\n cnt += 1\n \nif cnt == M and cnt>0:\n print(0)\n sys.exit()\nfor j in range(M):\n if order_list[j][0] > N:\n print(-1)\n sys.exit()\n if order_list[j][0] == 1 and order_list[j][1] == 0:\n print(-1)\n sys.exit()\n \nfor i in range(M):\n if Number[order_list[i][0]-N+2] != 0 and Number[order_list[i][0]-N+2] != order_list[i][1]:\n print(-1)\n sys.exit()\n Number[order_list[i][0]-N+2] = order_list[i][1]\n \nif N == 1 and Number[0]+Number[1]+Number[2] == 0:\n print(0)\n sys.exit()\n \nif Number[3-N] == 0:\n Number[3-N] = 1\n \nprint(100*Number[0]+10*Number[1]+Number[2])'] | ['Runtime Error', 'Accepted'] | ['s788143120', 's280161558'] | [3064.0, 3064.0] | [20.0, 17.0] | [734, 855] |
p02761 | u905329882 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = map(int,input().split())\ns = []\nc = []\nif N == 1:\n minn = "0"\nelif N == 2:\n minn = "00"\nelif N == 3:\n minn = "000"\ncount = 0\nminnlist = list(minn)\nfor i in range(M):\n am, pm = map(int,input().split())\n s.append(am)\n c.append(pm)\n\nfor i in range(M):\n if minnlist[s[i]-1] != "0" and minnlist[s[i]-1] != str(c[i]):\n count = -1\n break\n else:\n minnlist[s[i]-1] = str(c[i])\n\nif not 0 in s:\n minnlist[0]=1\nelif minnlist[0] == "0" and N>=2:\n count = -1\n\nhiku = \'\'.join(map(str,minnlist))\n#print(int(hiku))\n\nif count == -1 and M >=1:\n print(-1)\nelif M==0:\n if N==1:\n print(0)\n elif N==2:\n print(10)\n else:\n print(100)\nelse:\n print(hiku)\n', 'N,M = map(int,input().split())\ns = []\nc = []\nif N == 1:\n minn = "0"\nelif N == 2:\n minn = "00"\nelif N == 3:\n minn = "000"\ncount = 0\nminnlist = list(minn)\nfor i in range(M):\n am, pm = map(int,input().split())\n s.append(am)\n c.append(pm)\n\nfor i in range(M):\n if minnlist[s[i]-1] != "0" and minnlist[s[i]-1] != str(c[i]):\n count = -1\n break\n else:\n minnlist[s[i]-1] = str(c[i])\n\nif not 1 in s:\n minnlist[0]=1\nelif minnlist[0] == "0" and N>=2:\n count = -1\n\nhiku = \'\'.join(map(str,minnlist))\n#print(int(hiku))\n\nif count == -1 and M >=1:\n print(-1)\nelif M==0:\n if N==1:\n print(0)\n elif N==2:\n print(10)\n else:\n print(100)\nelse:\n print(hiku)\n'] | ['Wrong Answer', 'Accepted'] | ['s021871982', 's431736501'] | [3064.0, 3064.0] | [18.0, 17.0] | [721, 721] |
p02761 | u907223098 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m=(int(i) for i in input.split())\nl=[None,None,None]\nanswer='unknown'\nfor i in range(m):\n a,b=(int(i) for i in input().split())\n if l[a-1]==None:\n l[a-1]=b\n elif l[a-1]!=b:\n answer='-1'\n break\nfor i in range(3):\n if l[i]==None:\n if i!=3-n:\n l[i]=0\n else:\n l[i]=1\nr=l[0]*10**2+l[1]*10+l[2]\nif len(str(r))!=n:\n answer='-1'\nif answer=='-1':\n print('-1')\nelse:\n print(r)\n", "n,m=(int(i) for i in input().split())\nl=[0,None,None]\nanswer='unknown'\nfor i in range(m):\n a,b=(int(i) for i in input().split())\n if l[n-a]==None:\n l[n-a]=b\n elif l[n-a]!=b:\n answer='-1'\n break\nfor i in range(3):\n if l[i]==None:\n if i!=n-1:\n l[i]=0\n else:\n l[i]=1\nr=l[2]*10**2+l[1]*10+l[0]\nif len(str(r))!=n:\n answer='-1'\nif answer=='-1':\n print('-1')\nelse:\n print(r)", "n,m=(int(i) for i in input().split())\nl=[None,None,None]\nanswer='unknown'\nfor i in range(m):\n a,b=(int(i) for i in input().split())\n if l[n-a]==None:\n l[n-a]=b\n elif l[n-a]!=b:\n answer='-1'\n break\nif l[0]==None:\n l[0]=0\nfor i in range(3):\n if l[i]==None:\n if i!=n-1:\n l[i]=0\n else:\n l[i]=1\nr=l[2]*10**2+l[1]*10+l[0]\nif len(str(r))!=n:\n answer='-1'\nif answer=='-1':\n print('-1')\nelse:\n print(r)"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s199499178', 's270642131', 's568092643'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 17.0] | [401, 399, 426] |
p02761 | u910632349 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m=map(int,input().split())\nq=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(10**n):\n i=str(i)\n f=1\n for j in q:\n if i[j[0]-1]!=str(j[1]):\n f=0\n break\n if f:\n print(i)\n exit()\nprint("-1")', 'n,m=map(int,input().split())\nq=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(10**n):\n i=str(i)\n if len(i)!=n:\n continue\n f=1\n for j in q:\n if i[j[0]-1]!=str(j[1]):\n f=0\n break\n if f:\n print(i)\n exit()\nprint("-1")'] | ['Runtime Error', 'Accepted'] | ['s056818118', 's121527538'] | [9012.0, 9156.0] | [28.0, 29.0] | [262, 297] |
p02761 | u912650255 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = map(int,input().split())\nsc = list([list(map(int,input().split())) for _ in range(M)])\n\n\nfor i in range(10**(N-1)-1,10**N):\n count = 0\n str_i = str(i)\n for j in range(M):\n if str_i[sc[j][0]-1] == str(sc[j][1]):\n count += 1\n if count == M:\n print(i)\n exit()\nprint(-1)\n', 'N,M = map(int,input().split())\nsc = list([list(map(int,input().split())) for _ in range(M)])\n\n\nfor i in range(10**(N-1)-1,10**N):\n count = 0\n str_i = str(i)\n for j in range(M):\n if str_i[sc[j][0]-1] == str(sc[j][1]):\n count += 1\n if count == M:\n print(i)\n exit()\nprint(-1)\n', 'N,M = map(int,input().split())\nsc = list([list(map(int,input().split())) for _ in range(M)])\n\nif N == 1:\n a = 0\nelif N != 1:\n a = 10 **(N-1)\n\nfor i in range(a,10**N):\n count = 0\n str_i = str(i)\n for j in range(M):\n if str_i[sc[j][0]-1] == str(sc[j][1]):\n count += 1\n if count == M:\n print(i)\n exit()\nprint(-1)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s154908843', 's713759563', 's803084264'] | [9140.0, 9164.0, 9120.0] | [28.0, 25.0, 29.0] | [317, 317, 360] |
p02761 | u913662443 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["stdin = open(0).read().split('\\n')\nN, M = map(int,stdin[0].split())\nif N==0:\n list=['0']\n for j in range(M):\n s, c = stdin[j+1].split()\n if list[int(s)-1]!=c:flag=False\n if flag:\n print(i)\n exit()\nelse:\n for i in range(10**(N-1),10**N):\n list=[str(i)]\n flag=True\n for j in range(M):\n s, c = stdin[j+1].split()\n if list[int(s)-1]!=c:flag=False\n if flag:\n print(i)\n exit()\nprint(-1) ", "stdin = open(0).read().split('\\n')\nN, M = map(int,stdin[0].split())\nflag=False\nif N==1:\n l=['0']\n flag=True\n for j in range(M):\n s, c = stdin[j+1].split()\n if l[int(s)-1]!=c:flag=False\n if flag:\n print(0)\nif not flag:\n for i in range(10**(N-1),10**N):\n l=[str(i)[_] for _ in range(len(str(i)))]\n flag=True\n for j in range(M):\n s, c = stdin[j+1].split()\n if l[int(s)-1]!=c:flag=False\n if flag: \n print(i)\n break\n if not flag:print(-1)"] | ['Runtime Error', 'Accepted'] | ['s667127222', 's327977589'] | [3064.0, 3064.0] | [19.0, 20.0] | [495, 555] |
p02761 | u915879510 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n, m = list(map(int, input().split()))\n\nd = [0] * n\nr = 0\n\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if (d[s-1] != 0) and (d[s-1] <= c):\n r = -1\n break\n else:\n d[s-1] = c\n\nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)\n", "n, m = list(map(int, input().split()))\n\nd = [10] * n\nr = 0\n\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if d[s-1]==c:\n d[s-1]=c\n else:\n print(-1)\n exit()\n\nif n==1:\n if d[0]==10:\n d[0] = 0\nif n==2:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\nif n==3:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\n if d[2]==10:\n d[2] = 0\n \nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)\n", "n, m = list(map(int, input().split()))\n\nd = [10] * n\nr = 0\n\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if d[s-1]>=c:\n if d[s-1]!=c:\n print(-1)\n exit()\n d[s-1]=c\n else:\n print(-1)\n exit()\n\nif n==1:\n if d[0]==10:\n d[0] = 0\nif n==2:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\nif n==3:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\n if d[2]==10:\n d[2] = 0\n \nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)\n", "n, m = list(map(int, input().split()))\n\nd = [0] * n\nr = 0\n\nd[0] = 1\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if (d[s-1] != 0) and (d[s-1] < c):\n print(-1)\n exit()\n else:\n d[s-1] = c\n\nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)", "n, m = list(map(int, input().split()))\n\nd = [10] * n\nr = 0\n\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if d[s-1]>c:\n d[s-1]=c\n else:\n print(-1)\n exit()\n\nif n==1:\n if d[0]==10:\n d[0] = 0\nif n==2:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\nif n==3:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\n if d[2]==10:\n d[2] = 0\n \nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)\n", "n, m = list(map(int, input().split()))\n\nd = [10] * n\nr = 0\n\nfor i in range(m):\n s, c = list(map(int, input().split()))\n if d[s-1]>=c:\n if d[s-1]!=10 and d[s-1]!=c:\n print(-1)\n exit()\n d[s-1]=c\n else:\n print(-1)\n exit()\n\nif n==1:\n if d[0]==10:\n d[0] = 0\nif n==2:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\nif n==3:\n if d[0]==10:\n d[0] = 1\n if d[1]==10:\n d[1] = 0\n if d[2]==10:\n d[2] = 0\n \nif (r==-1):\n print(r)\nelse:\n dd = int(''.join(map(str, d)))\n if len(str(dd))==n:\n print(dd)\n else:\n print(-1)\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s038481505', 's109078686', 's148303227', 's413966672', 's553417891', 's238354426'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [18.0, 17.0, 18.0, 17.0, 17.0, 17.0] | [322, 507, 554, 333, 506, 569] |
p02761 | u917558625 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["s=list(map(int,input().split()))\nt=[list(map(int,input().split())) for i in range(s[1])]\na=''\nb=0\nu=list(map(list,set(map(tuple,t))))\nu=(sorted(u,key=lambda x: x[0]))\nx=[0]*s[0]\nfor i in range(len(u)):\n c=t[i][0]-1\n if x[c]==0:\n x[c]+=t[i][1]+10\n else:\n b=1\nif b==1:\n print(-1)\nelse:\n x.reverse()\n for j in range(s[0]):\n if x[j]==0:\n if j==0:\n a=a+'1'\n else:\n a=a+'0'\n else:\n x[j]=x[j]-10\n if j==0 and x[j]==0:\n a=a+'1'\n else:\n a=a+str(x[j])\n print(a)", "s=list(map(int,input().split()))\nt=[list(map(int,input().split())) for i in range(s[1])]\na=''\nb=0\nu=list(map(list,set(map(tuple,t))))\nu=(sorted(u,key=lambda x: x[0]))\nx=[0]*s[0]\nfor i in range(len(u)):\n c=t[i][0]-1\n if x[c]==0:\n x[c]+=t[i][1]+10\n else:\n b=1\nif b==1:\n print(-1)\nelse:\n if len(x)>=2 and x[0]==10:\n print(-1)\n else:\n if len(x)==1 and (x[0]==10 or x[0]==0):\n print(0)\n else:\n x.reverse()\n for j in range(s[0]):\n if x[j]==0:\n if j+1==s[0]:\n a='1'+a\n else:\n a='0'+a\n else:\n x[j]=x[j]-10\n if j+1==s[0] and x[j]==0:\n a='1'+a\n else:\n a=str(x[j])+a\n print(a)"] | ['Wrong Answer', 'Accepted'] | ['s280542209', 's206867920'] | [3064.0, 3064.0] | [17.0, 17.0] | [523, 709] |
p02761 | u917872021 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m = list(map(int, input().split()))\n\njouken = {}\nans = ''\nfor i in range(m):\n s, t = list(map(int, input().split()))\n if s in jouken.keys():\n if jouken[s] != t:\n ans = -1\n break\n else:\n jouken[s] = t\n \nif ans != -1:\n for j in range(n):\n keta = j+1\n if keta in jouken.keys():\n if keta == 1 and jouken[keta] != 0:\n ans += str(jouken[keta])\n else:\n ans = -1\n break\n elif keta == 1:\n ans += '1'\n else:\n ans += '0'\n \nprint(int(ans))\n", "n,m = list(map(int, input().split()))\n\njouken = {}\nans = ''\nfor i in range(m):\n s, t = list(map(int, input().split()))\n if s in jouken.keys():\n if jouken[s] == 0:\n jouken[s] = t\n if jouken[s] != t:\n ans = -1\n break\n else:\n jouken[s] = t\n \nif ans != -1:\n for j in range(n):\n keta = j+1\n if keta in jouken.keys():\n if keta == 1 and jouken[keta] != 0:\n ans += str(jouken[keta])\n else:\n ans = -1\n break\n elif keta == 1:\n ans += '1'\n else:\n ans += '0'\n \nprint(int(ans))\n", "n,m = list(map(int, input().split()))\n\njouken = {}\nans = ''\nfor i in range(m):\n s, t = list(map(int, input().split()))\n if s in jouken.keys():\n if jouken[s] != t:\n ans = -1\n break\n else:\n jouken[s] = t\n \nif ans != -1:\n for j in range(n):\n keta = j+1\n if keta in jouken.keys():\n if keta == 1 and jouken[keta] == 0 and n != 1:\n ans = -1\n break\n else:\n ans += str(jouken[keta])\n elif keta == 1 and n != 1:\n ans += '1'\n else:\n ans += '0'\n \nprint(int(ans))\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s442003994', 's983232358', 's314957496'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 17.0] | [609, 662, 631] |
p02761 | u918601425 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,K=[int(s) for s in input().split()]\nls=[-1 for _ in range(N+1)]\nfor _ in range(K):\n a,b=[int(s) for s in input().split()]\n if ls[a]==-1:\n ls[a]=b\n else:\n ls[0]=0\n \nprint(ls)\n\nif ls[0]==0:\n print(-1)\nelse:\n if N==1:\n ans=max([ls[1],0]) \n if N==2:\n for i in range(10,100):\n a=i//10\n b=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):\n ans=i\n break\n if N==3:\n for i in range(100,1000):\n a=i//100\n b=(i//10)%10\n c=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):\n ans=i\n break\nprint(ans)', 'N,K=[int(s) for s in input().split()]\nls=[-1 for _ in range(N+1)]\nfor _ in range(K):\n a,b=[int(s) for s in input().split()]\n if ls[a]==-1:\n ls[a]=b\n else:\n ls[0]=0\nans=0\nif ls[0]==0:\n print(-1)\nelse:\n if N==1:\n ans=max([ls[1],0]) \n if N==2:\n for i in range(10,100):\n a=i//10\n b=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):\n ans=i\n break\n if N==3:\n for i in range(100,1000):\n a=i//100\n b=(i//10)%10\n c=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):\n ans=i\n break\n print(ans)\n', 'N,K=[int(s) for s in input().split()]\nls=[-1 for _ in range(N+1)]\nfor _ in range(K):\n a,b=[int(s) for s in input().split()]\n if ls[a]==-1:\n ls[a]=b\n elif ls[a]==b:\n continue\n else:\n ls[0]=0\nans=0\n\n\nif ls[0]==0:\n print(-1)\nelse:\n if N==1:\n ans=max([ls[1],0]) \n if N==2:\n for i in range(10,100):\n if ls[1]==0:\n ans=-1\n else:\n a=i//10\n b=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):\n ans=i\n break\n if N==3:\n for i in range(100,1000):\n if ls[1]==0:\n ans=-1\n else:\n a=i//100\n b=(i//10)%10\n c=i%10\n if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):\n ans=i\n break\n print(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s074715156', 's577907505', 's310899540'] | [3064.0, 3064.0, 3192.0] | [18.0, 18.0, 18.0] | [630, 623, 769] |
p02761 | u920204936 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = map(int,input().split())\nsc = [list(map(int,input().split())) for i in range(M)]\nfor i in range(10**N):\n stop = True\n for t in sc:\n if i//(10**(N-t[0]))%10 != t[1]:\n stop = False\n if stop:\n print(i)\n break\nif stop:\n print(-1)\n', 'N,M = map(int,input().split())\nsc = [list(map(int,input().split())) for i in range(M)]\nfor i in range(10**N):\n stop = True\n for t in sc:\n if i//(10**(N-t[0]))%10 != t[1]:\n stop = False\n if stop:\n if i//(10**(N-1)) > 0 or (N==1 and i==0):\n print(i)\n break\n else:\n stop = True\nif not stop:\n print(-1)\n'] | ['Wrong Answer', 'Accepted'] | ['s443642545', 's511193309'] | [3060.0, 3064.0] | [19.0, 18.0] | [276, 376] |
p02761 | u923712635 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = [int(i) for i in input().split()]\ndi = {}\nflag = True\nfor _ in range(M):\n s, c = [int(i) for i in input().split()]\n if(s in di):\n if(di[s] != c):\n print(-1)\n flag = False\n break\n else:\n di[s] = c\n\nif(1 in di):\n if(di[1]==0):\n print(-1)\n break\n\nif(flag):\n for i in range(10**(N-1), 10**N):\n x = str(i)\n ok = True\n for ind, s in enumerate(x):\n if(ind+1 in di):\n if(di[ind+1] != int(s)):\n ok = False\n continue\n if(ok):\n print(i)\n break\n else:\n print(-1)\n\n\n', 'N, M = [int(i) for i in input().split()]\ndi = {}\nflag = True\nfor _ in range(M):\n s, c = [int(i) for i in input().split()]\n if(s in di):\n if(di[s] != c):\n print(-1)\n flag = False\n break\n else:\n di[s] = c\n\nif(1 in di):\n if(di[1]==0):\n if(N==1):\n print(0)\n else:\n print(-1)\n flag = False\n\nif(N==1 and M==0):\n print(0)\n flag=False\n\nif(flag):\n for i in range(10**(N-1), 10**N):\n x = str(i)\n ok = True\n for ind, s in enumerate(x):\n if(ind+1 in di):\n if(di[ind+1] != int(s)):\n ok = False\n continue\n if(ok):\n print(i)\n break\n else:\n print(-1)\n'] | ['Runtime Error', 'Accepted'] | ['s491048225', 's881313894'] | [3064.0, 3064.0] | [18.0, 18.0] | [660, 770] |
p02761 | u926080943 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["def main():\n n, m = map(int, input().split())\n digit = {}\n for i in range(m):\n s, c = map(int, input().split())\n if digit.get(s) is not None and digit.get(s) != c:\n print(-1)\n return\n digit[s] = c\n ans = ''\n for i in range(1, n+1):\n ans += str(digit.get(i, '1'))\n\n if ans == str(int(ans)):\n print(ans)\n else:\n print(-1)\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n n, m = map(int, input().split())\n digit = {}\n for i in range(m):\n s, c = map(int, input().split())\n if digit.get(s) is not None and digit.get(s) != c:\n print(-1)\n return\n digit[s] = c\n ans = ''\n for i in range(1, n+1):\n ans += str(digit.get(i, '0'))\n\n if ans == str(int(ans)):\n print(ans)\n elif ans[0] == '0' and digit.get(1) is None:\n print('1' + ans[1:])\n else:\n print(-1)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s363990246', 's391419210'] | [3064.0, 3064.0] | [17.0, 17.0] | [445, 523] |
p02761 | u929996201 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = map(int,input().split())\nans = [-1]*N\nflg = 0\nflg2 = 0\n\nfor i in range(M):\n s,c = map(int, input().split())\n s -= 1\n if ans[s] == -1 or ans[s] == c:\n ans[s] = c\n else:\n flg = 1\n \nif flg == 0:\n if N == 1 and ans[0] == -1:\n print("0")\n elif ans[0] == 0:\n print("-1")\n else:\n for i in range(N):\n if ans[i] == -1:\n ans[i] = 0\n else:\n flg2 = i\n for i in range(flg2):\n ans[i] = ""\n print(int("".join(map(str,ans))))\nelse:\n print("-1")', 'N,M=map(int,input().split())\nsc=[]\nfor i in range(M):\n sc.append(list(map(int,input().split())))\n\nans=-1\ncnt=10**(N-1)\nif cnt==1:cnt-=1\nwhile True:\n if len(str(cnt))>N:break\n if len(str(cnt))!=N:continue\n ret=True\n for i in range(M):\n if str(cnt)[sc[i][0]-1]!=str(sc[i][1]):\n ret=False\n break\n if ret:\n ans=cnt\n break\n cnt+=1\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s554670576', 's468525941'] | [9224.0, 9216.0] | [31.0, 30.0] | [493, 362] |
p02761 | u931118906 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\nl = [-1] * n\nans = 0\nfor _ in range(m):\n a, b = map(int, input().split())\n a = a - 1\n if l[a] == -1 or l[a] == b:\n l[a] = b\n else:\n print(-1)\n exit()\n\nif n > 1 and l[0] == 0:\n print(-1)\nelif n == 1:\n print(l[0])\nelse:\n for i in range(n):\n if i == 0 and l[0] == -1:\n l[0] = 1\n elif l[i] == -1:\n l[i] = 0\n \n ans += str(l[i])\n print(int(ans))\n', 'n, m = map(int, input().split())\nsl = []\ncl = []\nans = [-1] * n\na = ""\nfor _ in range(m):\n s, c = map(int, input().split())\n sl.append(s)\n cl.append(c)\n if ans[s - 1] == -1:\n ans[s - 1] = c\n elif ans[s - 1] == c:\n continue\n else:\n ans[s - 1] = -10\n break\n\nif ans.count(-10) > 0:\n print(-1)\nelse:\n if n == 1:\n if ans[0] == -1:\n print(0)\n else:\n print(ans[0])\n else:\n for i in range(n):\n if i != n - 1 and ans[i] == 0:\n print(-1)\n exit()\n elif ans[i] == -1 and i == 0:\n ans[i] = 1\n elif ans[i] == -1 and i != 0:\n ans[i] = 0\n for i in ans:\n a += str(i)\n print(a)\n'] | ['Runtime Error', 'Accepted'] | ['s381343471', 's389931777'] | [3064.0, 3064.0] | [17.0, 18.0] | [503, 776] |
p02761 | u932868243 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n\nfor t in range(1,m+1):\n if sc[t][0]>=2 and sc[t][1]==0:\n print(-1)\n exit()\n\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]==sc[j-1][1]:\n sc.remove(sc[i-1])\n\nans=[]\nsc.sort(key=lambda x:x[0])\nfor t in range(1,m+1):\n ans.append(sc[t][1])\nprint(*ans,sep='')", "n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n \nfor t in range(1,m+1):\n if n>=2 and sc[t-1]==[1,0]:\n print(-1)\n exit()\n \nans=[]\nsc.sort(key=lambda x:x[0])\nfor t in range(1,m+1):\n if not sc[t-1][1] in ans:\n ans.append(sc[t-1][1])\nprint(*ans,sep='')", "n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n \nfor t in range(1,m+1):\n if n>=2 and sc[t-1]==[1,0]:\n print(-1)\n exit()\n \nans=[0]*n\nfor t in range(1,m+1):\n if ans[t-1]==0:\n ans[t-1]+=sc[t-1][1]\n\nprint(*ans,sep='')", "n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n \nfor t in range(1,m+1):\n if sc[t-1][0]>=2 and sc[t-1][1]==0:\n print(-1)\n exit()\n \nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]==sc[j-1][1]:\n sc.remove(sc[i-1])\n \nans=[]\nsc.sort(key=lambda x:x[0])\nfor t in range(1,m+1):\n ans.append(sc[t-1][1])\nprint(*ans,sep='')", "n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n \nfor t in range(1,m+1):\n if n>=2 and sc[t-1]==[1,0]:\n print(-1)\n exit()\n \nif m>=1:\n ans=[]\n sc.sort(key=lambda x:x[0])\n for t in range(1,m+1):\n if not sc[t-1][1] in ans:\n ans.append(sc[t-1][1])\n print(*ans,sep='')\nelse:\n print(0)", "n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nfor i in range(1,m):\n for j in range(i+1,m+1):\n if sc[i-1][0]==sc[j-1][0] and sc[i-1][1]!=sc[j-1][1]:\n print(-1)\n exit()\n \nfor t in range(1,m+1):\n if n>=2 and sc[t-1]==[1,0]:\n print(-1)\n exit()\n \nans=[0]*n\nfor t in range(1,m+1):\n if ans[sc[t-1][0]-1]==0:\n ans[sc[t-1][0]-1]+=sc[t-1][1]\n \nif ans[0]==0 and n>=2:\n ans[0]=1\nprint(*ans,sep='')"] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s089594804', 's159870105', 's377559574', 's626175580', 's899155502', 's027534076'] | [2940.0, 3064.0, 3192.0, 3064.0, 3064.0, 3064.0] | [18.0, 17.0, 18.0, 19.0, 18.0, 17.0] | [527, 430, 395, 541, 468, 451] |
p02761 | u933129390 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\nans = [0 for i in range(n)]\nbad = False\nfor i in range(m):\n s, c = map(int, input().split())\n if s==1 and c==0:\n if n==1:\n pass\n else:\n print(-1)\n bad = True\n break\n elif ans[s-1]!="0" and int(ans[s-1])!=c:\n print(-1)\n bad = True\n break\n else:\n ans[s-1] = c\nif ans[0] == 0:\n ans[0] = 1\nif bad == False:\n a = ""\n for i in range(n):\n a += str(ans[i])\n print(int(a))\n', 'n, m = map(int, input().split())\nsc = []\nfor i in range(m):\n sc.append(list(map(int, input().split())))\ni = 10**(n-1)\nif n==1:\n i = 0\nno = False\nwhile i<10**n:\n for j in range(m):\n if int(str(i)[sc[j][0]-1])==sc[j][1]:\n pass\n else:\n no = True\n if no == False:\n print(i)\n break\n else:\n i+=1\n no = False\nelse:\n print(-1)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s977941214', 's147253721'] | [3064.0, 3064.0] | [17.0, 19.0] | [514, 398] |
p02761 | u934052933 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['def main():\n n, m = map(int, input().split())\n s, c = []*m, []*m\n for i in range(m):\n a, b = map(int, input())\n s.append(a), c.append(b)\n for i in range(0, 10 ** n):\n loop = True\n string = str(i)\n if len(string) != n:\n continue\n for j in range(m):\n if string[s[j] - 1] != str(c[j]):\n loop = False\n if loop:\n print(string)\n quit()\n print(-1)\nif __name__ == "__main__":\n main()', 'def main():\n n, m = map(int, input().split())\n s, c = []*m, []*m\n for i in range(m):\n a, b = map(int, input().split())\n s.append(a), c.append(b)\n for i in range(0, 10 ** n):\n loop = True\n string = str(i)\n if len(string) != n:\n continue\n for j in range(m):\n if string[s[j] - 1] != str(c[j]):\n loop = False\n if loop:\n print(string)\n quit()\n print(-1)\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s578824200', 's712495685'] | [3064.0, 3064.0] | [17.0, 18.0] | [501, 509] |
p02761 | u934442292 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = [int(i) for i in input().split()]\ns = [0] * M\nc = [0] * M\nfor i in range(N):\n s[i], c[i] = map(int, input().split())\n\nans = 1000\nfor i in range(1000):\n S = str(i)\n if len(S) != N:\n continue\n \n is_ok = True\n for j in range(M):\n if S[s[j]] != c[j]:\n is_ok = False\n \n if is_ok:\n ans = min(ans, i)\n\nif ans == 1000:\n print(-1)\nelse:\n print(ans)\n', 'N, M = [int(i) for i in input().split()]\ns = [0] * M\nc = [0] * M\nfor i in range(M):\n s[i], c[i] = map(int, input().split())\n\nans = 1000\nfor i in range(1000):\n S = str(i)\n if len(S) != N:\n continue\n \n is_ok = True\n for j in range(M):\n if S[s[j]] != c[j]:\n is_ok = False\n \n if is_ok:\n ans = min(ans, i)\n\nif ans == 1000:\n print(-1)\nelse:\n print(ans)\n', 'N, M = [int(i) for i in input().split()]\ns = [0] * M\nc = [0] * M\nfor i in range(N):\n s[i], c[i] = map(int, input().split())\n\nans = 1000\nfor i in range(1000):\n S = str(i)\n if len(S) != N:\n continue\n \n is_ok = True\n for j in range(N):\n if S[s[j]] != c[j]:\n is_ok = False\n \n if is_ok:\n ans = min(ans, i)\n\nif ans == 1000:\n print(-1)\nelse:\n print(ans)\n', 'N, M = [int(i) for i in input().split()]\ns = [0] * M\nc = [0] * M\nfor i in range(M):\n s[i], c[i] = map(int, input().split())\n\nans = 1000\nfor i in range(1000):\n S = str(i)\n if len(S) != N:\n continue\n \n is_ok = True\n for j in range(M):\n if S[s[j]-1] != c[j]:\n is_ok = False\n \n if is_ok:\n ans = min(ans, i)\n\nif ans == 1000:\n print(-1)\nelse:\n print(ans)\n', 'N, M = [int(i) for i in input().split()]\ns = [0] * M\nc = [0] * M\nfor i in range(M):\n s[i], c[i] = map(int, input().split())\n\nans = 1000\nfor i in range(1000):\n S = str(i)\n if len(S) != N:\n continue\n \n is_ok = True\n for j in range(M):\n if S[s[j]-1] != str(c[j]):\n is_ok = False\n \n if is_ok:\n ans = min(ans, i)\n\nif ans == 1000:\n print(-1)\nelse:\n print(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s056000559', 's156088843', 's688609474', 's800546975', 's878647707'] | [3064.0, 3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 18.0, 17.0, 19.0, 19.0] | [375, 375, 375, 377, 382] |
p02761 | u934740772 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M=map(int,input().split())\nans=10**(N-1)\nif M==0:\n print(ans)\nelse:\n S=[]\n C=[]\n for i in range(M):\n s,c=map(int,input().split())\n S.append(s)\n C.append(c)\n for i in range(1000):\n flag=True\n I=str(i)\n for j in range(M):\n if N<S[j]:\n flag=False\n else:\n if I[S[j]-1]!=str(C[j]):\n flag=False\n if flag==True:\n print(i)\n exit()\n print(-1)', 'N,M=map(int,input().split())\nif M==0:\n if N==1:\n print(0)\n else:\n print(10**(N-1))\nelse:\n S=[]\n C=[]\n for i in range(M):\n s,c=map(int,input().split())\n S.append(s)\n C.append(c)\n if N==1:\n o=0\n else:\n o=10**(N-1)\n for i in range(o,10**N):\n flag=True\n I=str(i)\n for j in range(M):\n if N<S[j]:\n flag=False\n else:\n if I[S[j]-1]!=str(C[j]):\n flag=False\n if flag==True:\n print(i)\n exit()\n print(-1)\n'] | ['Runtime Error', 'Accepted'] | ['s527675224', 's384347247'] | [3064.0, 3064.0] | [18.0, 18.0] | [495, 590] |
p02761 | u935642171 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m = map(int, input().split())\nnum = [0]*n\ntf = True\nfor _ in range(m):\n d = list(map(int, input().split()))\n if d[0]==1 and n>1:\n tf = False\n break\n if num[d[0]-1] == 0:\n num[d[0]-1] = d[1]\n continue\n if num[d[0]-1] != d[1]: \n tf = False\nif num[0]==0 and n>1:\n num[0] = 1\nif tf:\n ans = 0\n for i in range(n-1,-1,-1):\n ans += num[(n-1)-i]*(10**i)\n print(ans)\nelse: print(-1)', 'n,m = map(int, input().split())\nnum = [0]*n\ntf = True\nfor _ in range(m):\n d = list(map(int, input().split()))\n if d[0]==1 and d[1]==0 and n>1:\n tf = False\n break\n if num[d[0]-1] == 0:\n num[d[0]-1] = d[1]\n continue\n if num[d[0]-1] != d[1]: \n tf = False\nif num[0]==0 and n>1:\n num[0] = 1\nif tf:\n ans = 0\n for i in range(n-1,-1,-1):\n ans += num[(n-1)-i]*(10**i)\n print(ans)\nelse: print(-1)'] | ['Wrong Answer', 'Accepted'] | ['s274470750', 's208734780'] | [9236.0, 9188.0] | [28.0, 27.0] | [400, 412] |
p02761 | u936050991 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = list(map(int, input().split()))\n\n \nout = [\'a\']*n\nerr_flg = False\n\nfor i in range(m):\n s = list(map(int, input().split()))\n\n if s[0]==1 and s[1]==0 and n > 1:\n err_flag = True\n elif s[0]==1 and s[1]==0 and n==1:\n print(\'0\')\n elif m==0 and n==1:\n print(\'0\')\n\n if out[s[0]-1]==\'a\':\n out[s[0]-1] = s[1]\n elif out[s[0]-1]==s[1]:\n out[s[0]-1] = s[1]\n # elif out[s[0]-1]!=s[1]:\n elif out[s[0]-1]!=s[1]:\n err_flg = True\n\n\nif out[0]==\'a\' and n>1:\n out[0]=1\n \nout.replace(\'a\',\'0\')\nout_s = "".join(map(str,out))\n\nif err_flg:\n print(\'-1\')\n# elif m==0 and n==1:\n# print(0)\nelse:\n print(out_s)', 'n, m = list(map(int, input().split()))\n\n \nout = [\'a\']*n\nerr_flg = False\n\nfor i in range(m):\n s = list(map(int, input().split()))\n\n if s[0]==1 and s[1]==0 and n > 1:\n err_flag = True\n elif s[0]==1 and s[1]==0 and n==1:\n print(\'0\')\n elif m==0 and n==1:\n print(\'0\')\n\n if out[s[0]-1]==\'a\':\n out[s[0]-1] = s[1]\n elif out[s[0]-1]==s[1]:\n out[s[0]-1] = s[1]\n # elif out[s[0]-1]!=s[1]:\n elif out[s[0]-1]!=s[1]:\n err_flg = True\n\n\nif out[0]==\'a\' and n>1:\n out[0]=1\n \n\nout_s = "".join(map(str,out))\nout_s.replace(\'a\',\'0\')\n\nif err_flg:\n print(\'-1\')\n# elif m==0 and n==1:\n# print(0)\nelse:\n print(out_s)', 'n, m = list(map(int, input().split()))\n\n \nout = [a]*n\nerr_flg = False\n\nfor i in range(m):\n s = list(map(int, input().split()))\n\n if s[0]==1 and s[1]==0 and n > 1:\n err_flag = True\n elif s[0]==1 and s[1]==0 and n==1:\n print(\'0\')\n elif m==0 and n==1:\n print(\'0\')\n\n if out[s[0]-1]==0:\n out[s[0]-1] = s[1]\n elif out[s[0]-1]==s[1]:\n out[s[0]-1] = s[1]\n # elif out[s[0]-1]!=s[1]:\n elif out[s[0]-1]!=s[1]:\n err_flg = True\n\n\nif out[0]==\'a\' and n>1:\n out[0]=1\nout_s = "".join(map(str,out))\n\nif err_flg:\n print(\'-1\')\n# elif m==0 and n==1:\n# print(0)\nelse:\n print(out_s)', 'n, m = list(map(int, input().split()))\n\n \nout = [\'a\']*n\nerr_flg = False\n\nfor i in range(m):\n s = list(map(int, input().split()))\n\n if s[0]==1 and s[1]==0 and n > 1:\n err_flag = True\n elif s[0]==1 and s[1]==0 and n==1:\n print(\'0\')\n elif m==0 and n==1:\n print(\'0\')\n\n if out[s[0]-1]==\'a\':\n out[s[0]-1] = s[1]\n elif out[s[0]-1]==s[1]:\n out[s[0]-1] = s[1]\n # elif out[s[0]-1]!=s[1]:\n elif out[s[0]-1]!=s[1]:\n err_flg = True\n\n\nif out[0]==\'a\' and n>1:\n out[0]=1\nout_s = "".join(map(str,out))\n\nif err_flg:\n print(\'-1\')\n# elif m==0 and n==1:\n# print(0)\nelse:\n print(out_s)', 'n, m = list(map(int, input().split()))\n\n \nout = [\'a\']*n\nerr_flg = False\nerr_flg2 = False \n\nfor i in range(m):\n s = list(map(int, input().split()))\n # print(s)\n\n if s[0]==1 and s[1]==0 and n==1:\n err_flg2 = True\n elif m==0 and n==1:\n err_flg2 = True\n elif s[0]==1 and s[1]==0 and n > 1:\n # print(\'kore\')\n err_flg = True\n\n if out[s[0]-1]==\'a\':\n out[s[0]-1] = s[1]\n elif out[s[0]-1]==s[1]:\n out[s[0]-1] = s[1]\n # elif out[s[0]-1]!=s[1]:\n elif out[s[0]-1]!=s[1]:\n err_flg = True\n\n\nif out[0]==\'a\' and n>1:\n out[0]=1\n \n\nout_s = "".join(map(str,out))\n\nif err_flg2:\n print(\'0\')\n # print(\'err2\')\nelif err_flg:\n print(\'-1\')\n # print(\'err\')\nelse:\n print(out_s.replace(\'a\',\'0\'))'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s041417750', 's228226817', 's683001260', 's719472577', 's767527580'] | [3064.0, 3064.0, 3188.0, 3064.0, 3064.0] | [18.0, 18.0, 18.0, 18.0, 20.0] | [671, 674, 641, 645, 766] |
p02761 | u936985471 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M=map(int,input().split())\nC=[-1]*N\nfor i in range(M):\n s,c=map(int,input().split())\n s-=1\n if C[s]!=-1:\n if C[s]!=c:\n print(-1)\n exit(0)\n C[s]=c\n \nif N>1 and C[0]==0:\n print(-1)\n exit(0)\n \nans=""\nfor i in range(len(C)):\n if C[i]==-1:\n if i==0:\n ans+="1"\n else:\n ans+="0"\n else:\n if i==0:\n ans+="1"\n else:\n ans+=str(C[i])\n \nprint(ans)\n', 'N,M=map(int,input().split())\nD=[-1]*N\nfor i in range(M):\n s,c=map(int,input().split())\n s-=1\n if s==0 and c==0 and N>1: \n print(-1)\n exit(0)\n if D[s]!=-1: \n if D[s]!=c: \n print(-1)\n exit(0)\n D[s]=c\n \nans=""\nif D[0]==-1: \n if N==1:\n print(0)\n else:\n ans+="1"\nelif D[0]==0:\n if N==1:\n print(0)\n exit(0)\n else:\n ans+="1"\nelse:\n ans+=str(D[0])\n \nfor i in range(1,N):\n if D[i]==-1:\n ans+="0"\n else:\n ans+=str(D[i])\n \nprint(ans)\n\n \n \n'] | ['Wrong Answer', 'Accepted'] | ['s106051905', 's866617901'] | [3064.0, 3064.0] | [17.0, 18.0] | [395, 588] |
p02761 | u940533000 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import numpy as np\nN, M = map(int, input().split())\ns, c = [], []\nfor i in range(M):\n tmp_s, tmp_c = map(int, input().split())\n s.append(tmp_s)\n c.append(tmp_c)\n\nflag = 0\nv_set = np.zeros(N)\n#print(v_set)\nfor i in range(M):\n if len(v_set) != 1 and s[i] == 1 and c[i] == 0:\n flag = 0\n break\n else:\n if v_set[s[i]-1] == 0 or v_set[s[i]-1] == c[i]:\n v_set[s[i]-1] = c[i]\n flag = 1\n else:\n flag = 0\n break\nif flag == 0:\n print(-1)\nelse:\n print(v_set)\n print(str(int(v_set[0]))+str(int(v_set[1]))+str(int(v_set[2])))\n ', "import numpy as np\nN, M = map(int, input().split())\ns, c = [], []\nfor i in range(M):\n tmp_s, tmp_c = map(int, input().split())\n s.append(tmp_s)\n c.append(tmp_c)\n\nv_set = [999 for i in range(N)]\nif N == 1:\n if M == 0:\n print(0)\n else:\n for i in range(M):\n if v_set[0] == 999 or v_set[0] == c[i]:\n v_set[0] = c[i]\n else:\n v_set[0] = -1\n break\n print(v_set[0])\nelif N >= 2:\n for i in range(M):\n if v_set[s[i]-1] == 999 or v_set[s[i]-1] == c[i]:\n v_set[s[i]-1] = c[i]\n else:\n v_set[0] = 0\n break\n if v_set[0] == 0:\n print(-1)\n else:\n if v_set[0] == 999:\n v_set[0] = 1\n for i in range(1,N):\n if v_set[i] == 999:\n v_set[i] = 0\n out = ''\n for i in range(N):\n out += str(int(v_set[i]))\n print(out)\n "] | ['Runtime Error', 'Accepted'] | ['s242802892', 's502529997'] | [12508.0, 12500.0] | [151.0, 149.0] | [554, 801] |
p02761 | u940765148 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["import numpy as np\ndef getLine():\n return list(map(int, input().split()))\nn,m = getLine()\nr = np.full(n,-1)\nfor i in range(m):\n a,b = getLine()\n \n if r[a - 1] == -1:\n r[a - 1] = b\n elif r[a - 1] != b:\n print(-1)\n break\nelse:\n if (n > 1 and r[0] <= 0) or (n == 1 and r[0] < 0):\n print(-1)\n else:\n print(r)\n r[r == -1] = 0\n print(r)\n r = r.astype(str)\n print(int(''.join(r)))", "import numpy as np\ndef getLine():\n return list(map(int, input().split()))\nn,m = getLine()\nr = np.full(n,-1,dtype=int)\nfor i in range(m):\n a,b = getLine()\n \n if r[a - 1] == -1:\n r[a - 1] = b\n elif r[a - 1] != b:\n print(-1)\n break\nelse:\n if n > 1 and r[0] == 0:\n print(-1)\n else:\n if r[0] == 0 and n == 1:\n print('0')\n else:\n if n > 1 and r[0] == -1:\n r[0] = 1\n r[r == -1] = 0\n r = r.astype(str)\n print(''.join(r))"] | ['Runtime Error', 'Accepted'] | ['s251827604', 's599193613'] | [14540.0, 12452.0] | [149.0, 157.0] | [457, 545] |
p02761 | u941644149 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = map(int, input().split())\nans_l = [0 for i in range(N)]\nans = ""\nbool_list = [False for i in range(N)]\nflag = 0\nS = []\nC = []\n\nfor m in range(M):\n s, c = map(int, input().split())\n if (bool_list[s-1] == True) & (ans_l[s-1] != c):\n ans = "-1"\n flag = 1\n break\n else:\n ans_l[s-1] = c\n S.append(s)\n C.append(c)\n \n\nif flag == 0:\n if (bool_list[0]==False) & (N==3):\n ans_l[0]=1\n elif (bool_list[0]==False) & (N==2):\n ans_l[0]=1\nif flag == 0:\n if (N==3) & (ans_l[0] == 0):\n ans = "-1"\n flag = 1\n elif (N==2) & (ans_l[0] == 0):\n ans = "-1"\n flag =1\nif flag == 0:\n for i in ans_l:\n ans += str(i)\n\nans = int(ans)\n\nif len(str(ans)) != N:\n ans\nprint(ans)', 'N, M = map(int, input().split())\nans_list=[]\nS=[]\nC=[]\nans=0\nfor i in range(M):\n s,c = map(int, input().split())\n S.append(s)\n C.append(c)\n \nfor n in range(1000):\n if n < N:\n break\n for i, s in enumerate(S):\n n = str(n)\n if n[s-1] == C[i]:\n continue\n else:\n ans = -1\n break\n \n ans_list.append(int(n))\n \nif ans != -1:\n ans=min(ans_list)\n \nprint(ans)\n ', 'N, M = map(int, input().split())\nans_list=[]\nS=[]\nC=[]\nans=0\n\nfor i in range(M):\n s,c = map(int, input().split())\n S.append(s)\n C.append(c)\n#print(S,C)\nfor n in range(1000):\n flag=0\n if len(str(n)) != N:\n continue\n for i, s in enumerate(S):\n n = str(n)\n if int(n[s-1]) == C[i]:\n continue\n else:\n flag=1\n break\n if flag == 0:\n ans_list.append(int(n))\n#print(ans_list)\nif len(ans_list) == 0:\n ans = -1\nif ans != -1:\n ans=min(ans_list)\n \nprint(ans)\n \n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s055731989', 's456799148', 's115801016'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 18.0] | [775, 393, 489] |
p02761 | u943057856 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nans=-1\nfor i in range(10**3):\n if (len(str(i))==n):\n flag=1\n for s,c in sc:\n if str(i)[s-1] != str(c):\n flag=0\n if flag==1:\n ans =i\n break\nprint(ans)', 'n,m=map(int,input().split())\nsc=[list(map(int,input().split())) for _ in range(m)]\nans=-1\nfor i in range(10**3):\n if (len(str(i))==n):\n flag=1\n for s,c in sc:\n if str(i)[s-1] != str(c):\n flag=0\n if flag==1:\n ans =i\n break\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s137490411', 's203142052'] | [3060.0, 3060.0] | [19.0, 19.0] | [316, 304] |
p02761 | u944643608 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["N, M = map(int, input().split())\nsc = [list(map(int, input().split())) for i in range(M)]\nsc.sort()\nif N == 1:\n tmp = sc[0][1]\n for i in range(M):\n if tmp != sc[i][1]:\n print(-1)\n break\n print(tmp)\nelse:\n ans_lis = [0] * N\n tmp_s = sc[0][0]\n tmp_c = sc[0][1]\n for i in range(M):\n if sc[i][0] == 1 and sc[i][1] == 0:\n print(-1)\n break\n if tmp_s == sc[i][0]:\n if tmp_c != sc[i][1]:\n print(-1)\n break\n else:\n ans_lis[tmp_s -1] = tmp_c\n tmp_s = sc[i][0]\n tmp_c = sc[i][1]\n if ans_lis[0] == 0:\n ans_lis[0] = 1\n lis = map(str, ans_lis)\n mojiretsu = ''\n for x in lis:\n mojiretsu += x\n print(mojiretsu)\n \n ", "N, M = map(int, input().split())\nif M == 0:\n if N == 1:\n print(0)\n elif N==2:\n print(10)\n else:\n print(100)\nelse:\n sc = [list(map(int, input().split())) for i in range(M)]\n sc.sort()\n pin = 0\n if N == 1:\n tmp = sc[0][1]\n for i in range(M):\n if tmp != sc[i][1]:\n print(-1)\n pin = 1\n break\n if pin == 0:\n print(tmp)\n else:\n pin = 0\n ans_lis = [0] * N\n tmp_s = sc[0][0]\n tmp_c = sc[0][1]\n for i in range(M):\n if sc[i][0] == 1 and sc[i][1] == 0:\n print(-1)\n pin = 1\n break\n if tmp_s == sc[i][0]:\n if tmp_c != sc[i][1]:\n print(-1)\n pin = 1\n break\n else:\n ans_lis[tmp_s -1] = tmp_c\n tmp_s = sc[i][0]\n tmp_c = sc[i][1]\n if pin == 0:\n ans_lis[tmp_s -1] = tmp_c\n if ans_lis[0] == 0:\n ans_lis[0] = 1\n lis = map(str, ans_lis)\n mojiretsu = ''\n for x in lis:\n mojiretsu += x\n print(mojiretsu)\n \n \n"] | ['Runtime Error', 'Accepted'] | ['s083629389', 's602920742'] | [3064.0, 3064.0] | [17.0, 17.0] | [722, 1005] |
p02761 | u947101138 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M=map(int,input().split(" "))\n\nlisting=[]\nfor i in range(M):\n a=list(map(int,input().split(" ")))\n listing.append(a)\n\n\naa=list(map(list, set(map(tuple, listing))))\n\nfor i in aa:\n \n\n\n\nif(N==1 and aa[0][0]==1):\n print(aa[0][1])\n exit()\n\n\n\na1=[]\na2=[]\nfor i in aa:\n a1.append(i[0])\n a2.append(i[0])\nif(len(a1)!=len(set(a2))):\n print(-1)\n exit()\n\nnum=""\n#print(aa)\ndigit=1\ndigit1=1\nfor i in range(N):\n digit=1\n for j in aa:\n if(j[0]==1 and j[1]==0):\n print(-1)\n exit()\n if(j[0]==digit):\n num+=str(j[1])\n digit1=digit+1\n break\n if(digit1==digit):\n if(digit==1):\n num+="1"\n else:\n num+="0"\n digit+=1\nprint(num)\n \n', 'N,M=map(int,input().split(" "))\n\nlisting=[]\nfor i in range(M):\n a=list(map(int,input().split(" ")))\n listing.append(a)\n\n\naa=list(map(list, set(map(tuple, listing))))\n\nfor i in aa:\n \n\n\n\nif(N==1 and aa[0][0]==1):\n print(aa[0][1])\n exit()\n\n\n\na1=[]\na2=[]\nfor i in aa:\n a1.append(i[0])\n a2.append(i[0])\nif(len(a1)!=len(set(a2))):\n print(-1)\n exit()\n\nnum=""\n#print(aa)\ndigit=1\ndigit1=1\nfor i in range(N):\n digit1=1\n for j in aa:\n if(j[0]==1 and j[1]==0):\n print(-1)\n exit()\n if(j[0]==digit):\n num+=str(j[1])\n digit1=digit+1\n break\n if(digit1==digit):\n if(digit==1):\n num+="1"\n else:\n num+="0"\n digit+=1\nprint(num)\n \n', 'N,M=map(int,input().split(" "))\n\nif(M==0):\n if(N==1):\n print(0)\n elif(N==2):\n print(10)\n elif(N==3):\n print(100)\n exit()\n\n\n\nlisting=[]\n\nfor i in range(M):\n a=list(map(int,input().split(" ")))\n listing.append(a)\n\n\naa=list(map(list, set(map(tuple, listing))))\n\n\n\n\na1=[]\na2=[]\nfor i in aa:\n a1.append(i[0])\n a2.append(i[0])\nif(len(a1)!=len(set(a2))):\n print(-1)\n exit()\n\nif(N==1 and aa[0][0]==1):\n print(aa[0][1])\n exit()\nnum=""\n#print(aa)\ndigit=1\ndigit1=1\nfor i in range(N):\n digit1=digit\n for j in aa:\n if(j[0]==1 and j[1]==0):\n print(-1)\n exit()\n if(j[0]==digit):\n num+=str(j[1])\n digit1=digit+1\n break\n if(digit1==digit):\n if(digit==1):\n num+="1"\n else:\n num+="0"\n digit+=1\nprint(num)\n \n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s543582162', 's876836575', 's562743654'] | [2940.0, 2940.0, 3064.0] | [17.0, 17.0, 17.0] | [764, 765, 873] |
p02761 | u948521599 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N , M =map(int,input())\n\nketa_list=[]\nnum_list=[]\nfor x in range(M):\n s,c =map(int,input().split())\n keta_list.append(s)\n num_list.append(c)\nsiteilist=[0]*N\nsiteilist[0]=1\nerrer =0\napperlist =[]\n\nfor i,x in enumerate(keta_list):\n siteilist[x-1]=num_list[i]\n if x == 1 and num_list[i]==0:\n errer= 1\n if x in apperlist:\n z =[]\n z = [l for l,i in enumerate(keta_list) if x == i ]\n if len(z)!=0:\n firest = num_list[z[0]]\n for b in z:\n if num_list[b] != firest:\n errer = 1\n \n apperlist.append(x)\nout =0\nif errer ==1:\n out =-1\nelse:\n for x in range(N):\n out += siteilist[x]*10**(N-x-1)\nprint(out)', 'N , M =map(int,input().split())\n\nketa_list=[]\nnum_list=[]\nfor x in range(M):\n s,c =map(int,input().split())\n keta_list.append(s)\n num_list.append(c)\nsiteilist=[0]*N\nif len(siteilist)!=1:\n siteilist[0]=1\nerrer =0\napperlist =[]\n\nfor i,x in enumerate(keta_list):\n siteilist[x-1]=num_list[i]\n if x == 1 and num_list[i]==0 and len(siteilist)!=1:\n errer= 1\n if x in apperlist:\n z =[]\n z = [l for l,i in enumerate(keta_list) if x == i ]\n if len(z)!=0:\n firest = num_list[z[0]]\n for b in z:\n if num_list[b] != firest:\n errer = 1\n \n apperlist.append(x)\nout =0\nif errer ==1:\n out =-1\nelse:\n for x in range(N):\n out += siteilist[x]*10**(N-x-1)\nprint(out)'] | ['Runtime Error', 'Accepted'] | ['s575354049', 's288891597'] | [3064.0, 3064.0] | [20.0, 17.0] | [727, 783] |
p02761 | u949115942 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\n\nscs = []\nfor i in range(m):\n scs.append(list(map(int, input().split())))\n \nnumber = [-1] * n\nfor sc in scs:\n if number[sc[0] - 1] == -1:\n number[sc[0] - 1] = sc[1]\n elif number[sc[0] - 1] != sc[1]:\n number = []\n break\n\nif len(number) > 1 and number[0] != 0:\n guess = 0\n for i in range(n):\n if number[i] != -1: \n guess += number[i] * (10 ** (n - i - 1))\n else:\n guess += (10 ** (n - i - 1))\n\nelse:\n guess = -1\n \n\nprint(guess)', 'n, m = map(int, input().split())\nscs = []\nfor i in range(m):\n scs.append(list(map(int, input().split())))\n \ndef set_number(scs):\n number = [-1] * n\n for sc in scs:\n if number[sc[0] - 1] == -1:\n number[sc[0] - 1] = sc[1]\n elif number[sc[0] - 1] != sc[1]:\n return None\n return number\n \ndef guess_number(number):\n if number is None:\n return -1\n\n if number[0] == 0:\n return -1\n \n guess = 0\n for i in range(n):\n if i == 0 and number[i] == 0:\n guess += (10 ** (n - i - 1))\n else:\n guess += number[i] * (10 ** (n - i - 1))\n\n return guess\n \nnumber = set_number(scs)\nprint(guess_number(number))', 'n, m = map(int, input().split())\nscs = []\nfor i in range(m):\n scs.append(list(map(int, input().split())))\n \ndef set_number(scs):\n number = [-1] * n\n for sc in scs:\n if number[sc[0] - 1] == -1:\n number[sc[0] - 1] = sc[1]\n elif number[sc[0] - 1] != sc[1]:\n return None\n return number\n \ndef guess_number(number):\n if number is None:\n return -1\n\n if number[0] == 0 and n > 1:\n return -1\n \n guess = 0\n for i in range(n):\n if i == 0 and number[i] == -1 and n == 1:\n return 0\n elif i == 0 and number[i] == -1:\n guess += (10 ** (n - i - 1))\n elif number[i] != -1:\n guess += number[i] * (10 ** (n - i - 1))\n\n return guess\n\nnumber = set_number(scs)\nprint(guess_number(number))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s491262765', 's834189282', 's177092165'] | [3064.0, 3064.0, 3188.0] | [18.0, 19.0, 19.0] | [539, 707, 806] |
p02761 | u951480280 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m=map(int,input().split())\nnum=["0"]*n\nans=0\nfor i in range(m):\n s,c=input().split()\n s=int(s)\n if s==0 and c=="0":\n ans=-1\n elif num[s-1] != "0":\n num[s-1] = c\n else:\n if num[s-1] != c:\n ans=-1\n\nif num[0] == 0:\n num[0] = "1"\nif ans==-1:\n print(ans)\nelse:\n print(int("".join(num)))\n', 'n,m=map(int,input().split())\nnum=["0"]*n\nans=0\nfor i in range(m):\n s,c=input().split()\n s=int(s)\n if s==0 and c=="0":\n ans=-1\n elif num[s-1] != "0":\n num[s-1] = c\n else:\n if num[s-1] != c:\n ans=-1\n\nif num[0] == "0":\n num[0] = "1"\nif ans==-1:\n print(ans)\nelse:\n print(int("".join(num)))\n', 'n,m=map(int,input().split())\nnum=["0"]*n\nans=0\nfor i in range(m):\n s,c=input().split()\n s=int(s)\n if s==1 and c=="0":\n ans=-1\n break\n if num[s-1] != "0":\n num[s-1] = c\n else:\n if num[s-1] != c:\n ans=-1\n break\n\nif num[0] == 0:\n num[0] = "1"\nif ans==-1:\n print(ans)\nelse:\n print(int("".join(num)))\n', 'n,m=map(int,input().split())\nnum=["-1"]*n\nans=0\nfor i in range(m):\n s,c=input().split()\n s=int(s)\n if s==1 and c=="0" and n!=1:\n ans=-1\n elif num[s-1] == "-1":\n num[s-1] = c\n else:\n if num[s-1] != c:\n ans=-1\n\nif num[0] == "-1":\n if n>1:\n num[0] = "1"\n else:\n num[0] = "0"\n\nfor i in range(n):\n if num[i]=="-1":\n num[i]="0"\n\nif ans==-1:\n print(ans)\nelse:\n print(int("".join(num)))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s250310847', 's745137923', 's987126285', 's196314315'] | [3064.0, 3064.0, 3064.0, 3064.0] | [18.0, 17.0, 17.0, 17.0] | [340, 342, 370, 461] |
p02761 | u954153335 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import sys\nn,m=map(int,input().split())\nans=[0]*n\nfor _ in range(m):\n s,c=map(int,input().split())\n if ans[s-1]!=0 and ans[s-1]!=c:\n print(-1)\n sys.exit()\n if s==1 and c==0 and n!=1:\n print(-1)\n sys.exit()\n ans[s-1]=c\nif ans[0]==0 and n!=0:\nnum=0\nfor i in range(n):\n num+=ans[i]*(10**(n-i-1))\nprint(num)', 'import sys\nn,m=map(int,input().split())\ndata=[0]*n\nfor i in range(m):\n s,c=map(int,input().split())\n if data[s-1]!=0:\n print(-1)\n sys.exit()\n if s==1 and c==0:\n print(-1)\n sys.exit()\n data[s-1]=c\nif data[0]==0:\n data[0]=1\nans=0\nfor i in range(n):\n ans+=data[i]*10**(n-i-1)\nprint(ans)', 'import sys\nn,m=map(int,input().split())\nans=[0]*n\nfor _ in range(m):\n s,c=map(int,input().split())\n if ans[s-1]!=0 and ans[s-1]!=c:\n print(-1)\n sys.exit()\n if s==1 and c==0 and n!=1:\n print(-1)\n sys.exit()\n ans[s-1]=c\nif ans[0]==0 and n!=1:\n ans[0]=1\nnum=0\nfor i in range(n):\n num+=ans[i]*(10**(n-i-1))\nprint(num)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s378841860', 's565950076', 's611801681'] | [9000.0, 9128.0, 9220.0] | [27.0, 27.0, 28.0] | [346, 329, 359] |
p02761 | u955125992 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["from operator import itemgetter\n\nn, m = map(int, input().split())\n\nnum = [''] * n\n\nif m == 0:\n for i in range(n):\n num[i] = '0'\n if n != 1:\n num[0] = '1'\n print(''.join(num))\n exit()\n\nsc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))\n\nlast = sc[0][0]\nnum[last-1] = str(sc[i][1])\nnumber = True\n\nif last != 1:\n num[0] = '1'\n\nfor i in range(m):\n if sc[i][0] == 1 and sc[i][1] == 0:\n number = False\n if sc[i][0] == last and num[last-1] != '':\n if num[last-1] != sc[i][1]:\n number = False\n last = sc[i][0]\n num[last-1] = str(sc[i][1])\n\nfor i in range(n):\n if num[i] == '':\n num[i] = '0'\n \nif number:\n print(''.join(num))\nelse:\n print(-1)\n", "from operator import itemgetter\n\nn, m = map(int, input().split())\n\nnum = [''] * n\n\nif m == 0:\n for i in range(n):\n num[i] = '0'\n if n != 1:\n num[0] = '1'\n print(''.join(num))\n exit()\n\nsc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))\n\nlast = sc[0][0]\nnum[last-1] = str(sc[0][1])\nnumber = True\n\nif last != 1:\n num[0] = '1'\n\nfor i in range(m):\n if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:\n number = False\n if sc[i][0] == last and num[last-1] != '':\n if num[last-1] != str(sc[i][1]):\n number = False\n last = sc[i][0]\n num[last-1] = str(sc[i][1])\n\nfor i in range(n):\n if num[i] == '':\n num[i] = '0'\n\nif number:\n print(''.join(num))\nelse:\n print(-1)"] | ['Runtime Error', 'Accepted'] | ['s276843999', 's037591527'] | [3188.0, 3064.0] | [19.0, 18.0] | [758, 765] |
p02761 | u956811090 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = map(int, input().split())\ns = []\nc = []\na = [10, 10, 10]\nflag = 0\nans = 0\n \nfor i in range(M):\n s1,c1=[int(i) for i in input().split()]\n s.append(s1)\n c.append(c1)\n \nfor i in range(M):\n if a[s[i] - 1] == 10 or a[s[i] - 1] == c[i] :\n a[s[i] - 1] = c[i]\n else:\n flag = 1\n \nfor i in range(3):\n if a[i] == 10:\n if i == 3 - N:\n a[i] = 1\n else:\n a[i] = 0\n \nif flag == 1:\n print(-1)\nelse:\n if N == 1:\n print(a[2])\n elif a[3 - N] == 0:\n print(-1)\n else:\n for i in range(N):\n ans = ans + a[2 - i] * (10 ** i)\n print(ans)', 'N, M = map(int, input().split())\ns = []\nc = []\na = [10, 10, 10]\nflag = 0\nans = 0\n\nfor i in range(M):\n s1,c1=[int(i) for i in input().split()]\n s.append(s1)\n c.append(c1)\n \nfor i in range(M):\n if a[s[i] - 1] != 10:\n a[s[i] - 1] = c[i]\n else:\n flag = 1\n \nfor i in range(3):\n if a[i] == 10:\n if i == 3 - N:\n a[i] = 1\n else:\n a[i] = 0\n\nif flag == 1:\n print(-1)\nelse:\n if N == 1:\n print(a[2])\n elif a[3 - N] == 0:\n print(-1)\n else:\n for i in range(N):\n ans = ans + a[2 - i] * (10 ** i)\n print(ans)', 'print(-1)', 'def judge(num):\n l = len(num)\n if N != l:\n return False\n\n for i in range(M):\n if int(num[s[i] - 1]) != c[i]:\n return False\n\n return True \n\nN, M = map(int, input().split())\ns = []\nc = []\n\nfor i in range(M):\n a, b = map(int, input().split())\n s.append(a)\n c.append(b)\n \nfor i in range(1000):\n if judge(str(i)):\n print(i)\n exit()\n \nprint(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s017636523', 's761302473', 's860572654', 's833315718'] | [3064.0, 3064.0, 2940.0, 3064.0] | [17.0, 17.0, 17.0, 18.0] | [589, 558, 9, 368] |
p02761 | u960250266 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n, m = map(int, input().split())\nlst = [x for x in range(n)]\ndic = {}\nnot_found = False\nspecial_case = False\nfor i in range(m):\n a, b = map(int, input().split())\n if str(a) not in list(dic.keys()):\n dic[str(a)] = b\n else:\n if dic[str(a)] != b:\n not_found = True\n lst[a - 1] = b\nif m == 0:\n special_case = True\nif not_found:\n print(-1)\nelif special_case:\n if n == 1:\n print(0)\n elif n == 2:\n print(10)\n else:\n print(100)\nelse:\n for i in range(n):\n if str(i + 1) not in list(dic.keys()):\n if i + 1 == 1:\n lst[i] = 1\n else:\n lst[i] = 0\n lst = list(map(str, lst))\n res = ''.join(lst)\n if res[0] == '0' and len(res) > 1:\n print(-1)\n else:\n print(int(res))\nSeen by Sokun Deborey at 8:27 PM\nAng Sivhour", "n, m = map(int, input().split())\nlst = [x for x in range(n)]\ndic = {}\nnot_found = False\nspecial_case = False\nfor i in range(m):\n a, b = map(int, input().split())\n if str(a) not in list(dic.keys()):\n dic[str(a)] = b\n else:\n if dic[str(a)] != b:\n not_found = True\n lst[a - 1] = b\nif m == 0:\n special_case = True\nif not_found:\n print(-1)\nelif special_case:\n if n == 1:\n print(0)\n elif n == 2:\n print(10)\n else:\n print(100)\nelse:\n for i in range(n):\n if str(i + 1) not in list(dic.keys()):\n if i + 1 == 1:\n lst[i] = 1\n else:\n lst[i] = 0\n lst = list(map(str, lst))\n res = ''.join(lst)\n if res[0] == '0' and len(res) > 1:\n print(-1)\n else:\n print(int(res))"] | ['Runtime Error', 'Accepted'] | ['s315285641', 's809311338'] | [3064.0, 3188.0] | [18.0, 18.0] | [856, 811] |
p02761 | u962535482 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = map(int, input().split())\nsc = []\ntf = True\nfor i in range(M):\n sc.append(list(map(int, input().strip().split()))\nnum = []\nfor i in range(N):\n num.append(0)\nfor i in sc:\n if i[0] == N and i[1] == 0:\n tf = False\n else:\n num[i[0]-1] = i[1]\nif tf:\n num[0] = 1\nstring = ""\nfor i in num:\n string += str(i)\nif tf:\n print(string)\nelse:\n print(-1)', 'N, M = map(int, input().split())\nsc = []\ntf = True\ntff = False\nfor i in range(M):\n sc.append(list(map(int, input().strip().split())))\nif len(sc) == 0:\n if N == 1:\n print(0)\n else:\n print("1"+"0"*(N-1))\nelse:\n num = []\n for i in range(N):\n num.append(0)\n sc.sort()\n if N == 1 and sc[0][0] == 1 and sc[0][1] == 0:\n tff = True\n for i in range(M-1):\n if sc[i][0] == sc[i+1][0] and sc[i][1] != sc[i+1][1]:\n tf = False\n for i in sc:\n if i[0] == 1 and i[1] == 0:\n tf = False\n else:\n num[i[0]-1] = i[1]\n if tf and num[0] == 0:\n num[0] = 1\n string = ""\n for i in num:\n string += str(i)\n if tff == True:\n print(0)\n elif tf == True:\n print(string)\n else:\n print(-1)'] | ['Runtime Error', 'Accepted'] | ['s024006269', 's231190711'] | [2940.0, 3064.0] | [17.0, 18.0] | [360, 720] |
p02761 | u963764813 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = map(int,input().split())\n\nlst = [-1]*N\nflag = False\n\nfor _ in range(M):\n s,c = map(int,input().split())\n if lst[s-1] > -1:\n flag = True\n elif s == 1 and c== 0:\n flag = True\n else:\n lst[s-1] = c\nif flag:\n print("-1")\nelse:\n for i in range(N):\n if i == 0 & lst[i] == -1:\n lst[i] = 1\n elif lst[i] == -1:\n lst[i] = 0\n print("".join(map(str,lst)))\n \n ', 'N,M = map(int,input().split())\n \nlst = [-1]*N\nflag = False\n \nfor _ in range(M):\n s,c = map(int,input().split())\n if lst[s-1] != -1 and lst[s-1] != c:\n flag = True\n elif s == 1 and c == 0 and N != 1:\n flag = True\n else:\n lst[s-1] = c\n \n \nif flag:\n print("-1")\nelif N == 1 and (lst[0] == 0 or lst[0] == -1):\n print("0")\nelse:\n for i in range(N):\n if i == 0 and lst[i] == -1:\n lst[i] = 1\n elif lst[i] == -1:\n lst[i] = 0\n print("".join(map(str,lst)))'] | ['Wrong Answer', 'Accepted'] | ['s016161506', 's372612714'] | [3064.0, 3064.0] | [17.0, 19.0] | [386, 482] |
p02761 | u966836999 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["#157\ndef main():\n N, M = map(int,input().split())\n num = [-1]*N\n for i in range(M):\n s, c = map(int,input().split())\n if(s==1 and c==0 and N!=1):\n print(-1)\n return\n if(num[s-1]==-1 or num[s-1]==c):\n num[s-1] = c\n else:\n print(-1)\n return\n result = ''\n for i in ramge(N):\n if(num[i]!=-1):\n result+=str(num[i])\n else:\n if(N==1):\n result+='0'\n elif(i==0):\n result+='1'\n else:\n result+='0'\n print(result)\n\nmain()", "#157\ndef main():\n N, M = map(int,input().split())\n num = [-1]*N\n for i in range(M):\n s, c = map(int,input().split())\n if(s==1 and c==0 and N!=1):\n print(-1)\n return\n if(num[s-1]==-1 or num[s-1]==c):\n num[s-1] = c\n else:\n print(-1)\n return\n result = ''\n for i in range(N):\n if(num[i]!=-1):\n result+=str(num[i])\n else:\n if(N==1):\n result+='0'\n elif(i==0):\n result+='1'\n else:\n result+='0'\n print(result)\n\nmain()"] | ['Runtime Error', 'Accepted'] | ['s208368481', 's882342829'] | [3064.0, 3064.0] | [18.0, 18.0] | [613, 613] |
p02761 | u968404618 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\nSC = [list(map(int, input().split())) for _ in range(m)]\n\nNUM = [0]*n\nfor s, c in SC:\n if NUM[n-s] == 0:\n NUM[n - s] = c\n elif NUM[n-s] != 0 and NUM[n-s] != c:\n print("-1")\n exit()\n\nif NUM[n-1] == 0:\n print(-1)\n exit()\n\nfor s in NUM[::-1]:\n print(s, end ="")\n ', 'n, m = map(int, input().split())\nSC = [list(map(int, input().split())) for _ in range(m)]\n\nNUM = [0] * n\nfor s, c in SC:\n if (s == n-1) and (c == 0):\n print(-1)\n exit()\n\n if NUM[n - s] == 0:\n NUM[n - s] = c\n elif (NUM[n - s] != 0) and (NUM[n - s] != c):\n print(-1)\n exit()\n\nif NUM[n - 1] == 0:\n print(-1)\n exit()\n\nfor s in NUM[::-1]:\n print(s, end="")', 'n, m = map(int, input().split())\nSC = [list(map(int, input().split())) for _ in range(m)]\n\nNUM = [0] * n\nfor s, c in SC:\n if n != 1:\n if s == n-1 and c == 0:\n print(-1)\n exit()\n\n if NUM[n - s] == 0:\n NUM[n - s] = c\n elif (NUM[n - s] != 0) and (NUM[n - s] != c):\n print(-1)\n exit()\nif n != 1 and NUM[n - 1] == 0:\n print(-1)\n exit()\n\nfor s in NUM[::-1]:\n print(s, end="")\n', 'n, m = map(int, input().split())\nSC = [list(map(int, input().split())) for _ in range(m)]\n\nNUM = [0] * n\nCheck = [0] * n\nfor s, c in SC:\n if (n != 1) and (s == n-1) and (c == 0):\n print(-1)\n exit()\n\n if (NUM[n-s] == 0) and (Check[n-s] != 0) and (c != 0):\n print(-1)\n exit()\n\n if NUM[n-s] == 0:\n NUM[n-s] = c\n\n elif (NUM[n-s] != 0) and (NUM[n-s] != c):\n print(-1)\n exit()\n\n Check[n-s] += 1\n\nif (n != 1) and (NUM[n-1] == 0):\n print(-1)\n exit()\n\nfor s in NUM[::-1]:\n print(s, end="")', 'import copy\n\nn, m = map(int, input().split())\nans = [0]*n\nbns = copy.deepcopy(ans)\n\nfor _ in range(m):\n s, c = map(int, input().split())\n if ans[s-1] == 0:\n bns[s-1] = c\n elif ans[s-1] != 0 and ans[s-1] > c and s!=1:\n bns[s-1] = c\n \nif n == 1:\n L=[str(a) for a in ans]\n print("".join(L))\n exit()\n\nif n >= 2 and ans[0] != 0:\n L=[str(a) for a in ans]\n print("".join(L))\n exit()\n\nprint(-1)', 'import copy\n\nn, m = map(int, input().split())\nans = [0]*n\nans_list = []\nbns = copy.deepcopy(ans)\n\nfor _ in range(m):\n s, c = map(int, input().split())\n if ans[s-1] == 0:\n bns[s-1] = c\n\n elif ans[s-1] != 0 and ans[s-1] > c:\n bns[s-1] = c\n ans_list.append(bns)\n bns = copy.deepcopy(bns)\n \nif n == 1:\n L=[str(a) for a in ans]\n print("".join(L))\n exit()\n\nans_list.sort()\nif n >= 2:\n for ans in ans_list:\n if ans[0] != 0:\n L=[str(a) for a in ans]\n print("".join(L))\n exit()\n\nprint(-1)', 'n, m = map(int, input().split())\nSC = [list(map(int, input().split())) for _ in range(m)]\n\nfor x in range(1000):\n keta = 1\n nx = x//10\n d = [x%10]\n\n while nx:\n keta += 1\n d.append(nx%10)\n nx //= 10\n\n if keta != n: continue\n\n flg = True\n d.reverse()\n for s, c in SC:\n if d[s-1] != c:\n flg = False\n if flg:\n print(x)\n exit()\n\nprint(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s268552545', 's325257544', 's341450088', 's411971378', 's428488630', 's812399960', 's171099631'] | [9108.0, 9160.0, 9152.0, 9160.0, 3444.0, 3444.0, 9132.0] | [27.0, 29.0, 28.0, 29.0, 22.0, 22.0, 28.0] | [324, 404, 438, 553, 405, 513, 413] |
p02761 | u968846084 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import sys\nn,m=map(int,input().split())\nif m==0:\n if n==1:\n print(0)\n elif n==2:\n print(10)\n elif n==3:\n print(100)\n sys.exit()\nA=[0]*n\nB=[[0]*2 for i in range(m)]\nfor i in range(m):\n B[i]=list(map(int,input().split()))\nB.sort()\nif B[0]==[1,0]:\n print(-1)\n sys.exit()\nfor i in range(m-1):\n if B[i][0]==B[i+1][0]:\n if B[i][1]!=B[i+1][1]:\n print(-1)\n sys.exit()\nfor i in range(m):\n A[B[i][0]-1]=B[i][1]\nif A[0]==0:\n A[0]=1\nprint(A)\nans=0\nfor i in range(n):\n ans=ans+A[i]*10**(n-i-1)\nprint(ans)', 'import sys\nn,m=map(int,input().split())\nif m==0:\n if n==1:\n print(0)\n elif n==2:\n print(10)\n elif n==3:\n print(100)\n sys.exit()\nA=[0]*n\nB=[[0]*2 for i in range(m)]\nfor i in range(m):\n B[i]=list(map(int,input().split()))\nB.sort()\nif n!=1 and B[0]==[1,0]:\n print(-1)\n sys.exit()\nif n==1 and B[0]==[1,0]:\n print(0)\n sys.exit()\nfor i in range(m-1):\n if B[i][0]==B[i+1][0]:\n if B[i][1]!=B[i+1][1]:\n print(-1)\n sys.exit()\nfor i in range(m):\n A[B[i][0]-1]=B[i][1]\nif A[0]==0:\n A[0]=1\nans=0\nfor i in range(n):\n ans=ans+A[i]*10**(n-i-1)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s122269693', 's303809278'] | [3064.0, 3064.0] | [18.0, 18.0] | [524, 573] |
p02761 | u969211566 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m = map(int,input().split())\nsc = [list(map(int,input().split())) for i in range(m)]\nans = [0]*(n+1)\nanswer = 0\nfor i in range(m):\n dig = sc[i][0]\n if ans[dig] == 0 or ans[dig] == sc[i][1]:\n ans[dig] = sc[i][1]\n else:\n print("-1")\n exit()\nfor i in range(1,n+1):\n answer += ans[i]*10**(n-i)\nif answer == 0 and n != 1:\n print("-1")\nelif answer/(10**n) < 1:\n print("-1")\nelse:\n print(answer)\n', 'n,m = map(int,input().split())\nsc = [list(map(int,input().split())) for i in range(m)]\nans = [0]*(n+1)\nanswer = 0\nfor i in range(m):\n dig = sc[i][0]\n if ans[dig] == 0 or ans[dig] == sc[i][1]:\n ans[dig] = sc[i][1]\n else:\n print("-1")\n exit()\nfor i in range(1,n+1):\n answer += ans[i]*10**(n-i)\nif answer == 0 and n != 1:\n print("-1")\nelif answer < 10**n:\n print("-1")\nelse:\n print(answer)\n', 'n,m = map(int,input().split())\nsc = [list(map(int,input().split())) for _ in range(m)]\n \nfor i in range(1000):\n s = str(i)\n if len(s) != n:\n continue\n if all(s[a - 1] == str(b) for a, b in sc):\n print(i)\n exit()\n \nprint(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s306306072', 's591478409', 's566444338'] | [3064.0, 3064.0, 3060.0] | [18.0, 17.0, 18.0] | [407, 403, 251] |
p02761 | u969708690 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m=map(int,input().split())\nL=[-1]*n\nfor i in range(m):\n a,b=map(int,input().split())\n if L[a-1]!=-1:\n if L[a-1]!=b:\n print(-1)\n exit()\n else:\n L[a-1]=b\n if a==1 and b==0:\n print(-1)\n exit()\nfor i in range(len(L)):\n if L[i]==-1:\n L[i]=0\nL=list(map(int,L))\nprint("".join(L))', 'A=list()\nB=list()\nn,m=map(int,input().split())\nif m==0:\n print([0, 10, 100][n - 1])\n exit()\nfor i in range(m):\n a,b=map(int,input().split())\n A.append(a)\n B.append(b)\n if a==1 and b==0 and n!=1:\n print(-1)\n exit()\nfor i in range(1000):\n c=str(i)\n if len(c)==n:\n for j in range(m):\n if c[A[j]-1]!=str(B[j]):\n break\n if j==m-1:\n print(i)\n exit()\nprint(-1)'] | ['Runtime Error', 'Accepted'] | ['s786563681', 's173461360'] | [9200.0, 9184.0] | [30.0, 30.0] | [304, 401] |
p02761 | u969850098 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["N, M = map(int, input().split())\nS, C = [], []\nfor _ in range(M):\n s, c = map(int, input().split())\n if s == 1 and c == 0:\n print(-1)\n exit()\n if s in S:\n if C[S.index(s)] != c:\n print(-1)\n exit()\n else:\n continue\n S.append(s)\n C.append(c)\n\nz = zip(S, C)\nz = sorted(z)\nS, C = zip(*z)\nfor i in range(1, max(S)+1):\n if i != 1 and i not in S:\n print(0, end='')\n if i in S:\n print(C[S.index(i)], end='')", 'N, M = map(int, input().split())\nS, C = [], []\nfor _ in range(M):\n s, c = map(int, input().split())\n s -= 1\n if s in S:\n if C[S.index(s)] != c:\n print(-1)\n exit()\n else:\n continue\n S.append(s)\n C.append(c)\n\nz = zip(S, C)\nz = sorted(z)\nS, C = zip(*z)\n\nans = [-1] * N\nfor i in range(len(S)):\n ans[S[i]] = C[i]\n\nif ans[0] == 0:\n print(-1)\n exit()\n\nwhile len(ans) > 0:\n if ans[0] == -1:\n ans = ans[1:]\n else:\n break\n\nif ans == [-1]:\n print(-1)\n exit()\n\nans = [a if a != -1 else 0 for a in ans]\nprint(ans)', "N, M = map(int, input().split())\nS, C = [], []\nfor _ in range(M):\n s, c = map(int, input().split())\n s -= 1\n if s in S:\n if C[S.index(s)] != c:\n print(-1)\n exit()\n else:\n continue\n S.append(s)\n C.append(c)\n\nif len(S) == 0:\n if N == 1:\n print(0)\n elif N == 2:\n print(10)\n else:\n print(100)\n exit()\n\nans = [-1] * N\nfor i in range(len(S)):\n ans[S[i]] = C[i]\n\nif N == 1:\n if ans[0] == 0:\n print(0)\n exit()\n\nif ans[0] == -1:\n ans[0] = 1\nelif ans[0] == 0:\n print(-1)\n exit()\n\nans = [a if a != -1 else 0 for a in ans]\nprint(''.join(list(map(str, ans))))"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s269476653', 's364076574', 's200122291'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 18.0] | [495, 597, 670] |
p02761 | u971091945 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\n\nli = [0]*n\n\nfor i in range(m):\n s, c = map(int, input().split())\n if li[s-1] != 0 and li[s-1] != c:\n print(-1)\n exit(0)\n if s==1 and c==0:\n print(-1)\n exit(0)\n li[s-1]=c\n\nif n>1 and li[0]==0:\n li[0]=1\n\nfor i in range(n):\n print(li[i], end="")', 'n, m = map(int, input().split())\n\nli = [0]*n\n\nfor i in range(m):\n s, c = map(int, input().split())\n if li[s-1] != 0 and li[s-1] != c:\n print(-1)\n exit(0)\n if s==1 and c==0:\n print(-1)\n exit(0)\n li[s-1]=c\n\nif li[0]==0:\n li[0]=1\n\nfor i in range(n):\n print(li[i], end="")', 'n, m = map(int, input().split())\n\nli = [0]*n\n\nfor i in range(n):\n s, c = map(int, input().split())\n if li[s-1] != 0 and li[s-1] != c:\n print(-1)\n exit(0)\n if s==1 and c==0:\n print(-1)\n exit(0)\n li[s-1]=c\n\nif li[0]==0:\n li[0]=1\n\nfor i in range(n):\n print(li[i], end="")', 'n, m = map(int, input().split())\nsc_li = [list(map(int,input().split())) for _ in range(m)]\nsc = []\nans = ""\n\nfor i in range(1000):\n flag = True\n ans = str(i)\n if len(ans) != n:\n continue\n for j in range(m):\n si, ci = sc_li[j]\n if int(ans[si-1]) != ci:\n flag = False\n if flag:\n print(ans)\n exit(0)\n\nprint(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s247997567', 's257783450', 's672423772', 's428557819'] | [3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 20.0, 18.0, 19.0] | [322, 314, 314, 369] |
p02761 | u971124021 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M = list(map(int,input().split()))\nSC = [0]*(N+1)\nfor m in range(M):\n sc = list(map(int,input().split()))\n if SC[sc[0]] == 0:\n if sc[0] != 1:\n SC[sc[0]] = sc[1]\n else:\n print(-1)\n exit()\n else:\n if SC[sc[0]] != sc[1]:\n print(-1)\n exit()\n\nif SC[1]==0:\n SC[1] = 1\nans = 0\nfor i in range(N):\n ans += 10**(N-i-1)*SC[i+1]\n\nprint(ans)\n', 'N,M = list(map(int,input().split()))\nSC = [0]*(N+1)\nif M == 0:\n if N==1:\n print(0)\n exit()\n else:\n print(1*10**(N-1))\n exit()\n\nfor m in range(M):\n sc = list(map(int,input().split()))\n if (sc[0] == 1) and (sc[1] == 0):\n if N==1:\n continue\n else:\n print(-1)\n exit()\n elif sc[0] > N:\n print(-1)\n exit()\n elif SC[sc[0]] == 0:\n SC[sc[0]] = sc[1]\n else:\n if SC[sc[0]] != sc[1]:\n print(-1)\n exit()\n\nif (SC[1]==0) and (N > 1):\n SC[1] = 1\nans = 0\nfor i in range(N):\n ans += 10**(N-i-1)*SC[i+1]\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s835436083', 's702000345'] | [3064.0, 3064.0] | [18.0, 17.0] | [370, 561] |
p02761 | u973758681 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = map(int, input().split())\nnum = [None]*N\nres = 0\nfor i in range(M):\n s, c = map(int, input().split())\n s -= 1\n if n > 1 and s == 0 and c == 0:\n res = -1\n break \n if num[s] == None:\n num[s] = c\n elif num[s] != c:\n res = -1\n break\n\nprint(res) if res == -1 else print(0) if M == 0 else print(*[e if e!=None else 0 if i != 0 else 1 for i, e in enumerate(num)], sep="")', 'N, M = map(int, input().split())\nnum = [None]*N\nres = 0\nfor i in range(M):\n s, c = map(int, input().split())\n s -= 1\n if N > 1 and s == 0 and c == 0:\n res = -1\n break \n if num[s] == None:\n num[s] = c\n elif num[s] != c:\n res = -1\n break\n\nprint(res) if res == -1 else print(*[e if e!=None else 0 if i != 0 or N == 1 else 1 for i, e in enumerate(num)], sep="")\n'] | ['Runtime Error', 'Accepted'] | ['s064360070', 's829411681'] | [3064.0, 3064.0] | [19.0, 17.0] | [424, 411] |
p02761 | u973972117 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N,M =map(int,input().split())\njudge = [list(map(int,input().split())) for i in range(M)]\ndef Num(x):\n return list(str(x))\nAn = -1\nfor j in range(10**(N-1),10**N):\n if An != -1:\n break\n Numi = Num(j)\n A = 0\n for i in range(M):\n if Numi[judge[i][0]-1] != judge[i][1]:\n break\n A += 1\n if A == M:\n An = j\nprint(An)', "N,M=map(int,input().split())\nFirst = 10**N-1\nbox = []\nfor j in range(M):\n box.append(list(map(int,input().split())))\ndef f(x):\n if x >=100:\n return str(x)\n elif x>=10:\n return '0'+str(x)\n else:\n return'0'+'0'+str(x)\nAnswer = -1\nfor i in range(First):\n if Answer != -1:\n break\n Aqu = f(First - i)\n for m in range(M):\n if Aqu[box[m][0]-1] != str(box[m][1]):\n break\n elif m == M-1:\n Answer = Aqu\n break\nfor m in range(M):\n if box[m] == [1,0] and Answer =='099':\n Answer = -1\n elif box[m] == [2,0] and Answer =='009':\n Answer = -1\nif Answer != -1:\n if Answer[0] =='0':\n if Answer [1] =='0':\n print(Answer[2])\n else:\n print(Answer[1]+Answer[2])\n else:\n print(Answer)\nelse:\n print(Answer)", "N,M = map(int,input().split())\nS = {}\nAnswer = 2\nfor i in range(M):\n s,c = map(int,input().split())\n s = str(s)\n if s not in S:\n S[s] = str(c)\n else:\n if str(c) != S[s]:\n Answer = -1\n break\n else:\n continue\nif N >= 2:\n if '1' in S:\n if N== 2 and S['1'] == '0':\n Answer = -1\n elif N == 3 and S['1'] == '0':\n Answer = -1\nif Answer != -1:\n if '1' not in S and N >=2:\n Answer = '1'\n elif '1' not in S and N == 1:\n Answer ='0'\n else:\n Answer = S['1']\n for i in range(1,N):\n stri = str(i+1)\n if stri in S:\n Answer = Answer + S[stri]\n else:\n Answer = Answer + '0'\nprint(int(Answer))"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s329986074', 's469705314', 's993399865'] | [9108.0, 3064.0, 9248.0] | [28.0, 18.0, 29.0] | [375, 850, 756] |
p02761 | u974792613 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\n\nconds = []\n\nfor i in range(m):\n s, c = map(int, input().split())\n conds.append([s, c])\n\n\nconds = sorted(conds)\nfor i in range(len(conds)):\n if i + 1 < len(conds) and (\n conds[i][0] == conds[i + 1][0] and conds[i][1] != conds[i + 1][1]\n ):\n print(-1)\n exit(0)\n\n# list to check conditions.If -1, no condition\nfix = [-1] * n\n\nfor i in range(len(conds)):\n fix[conds[i][0] - 1] = conds[i][1]\n\nans = 0\nisTopNumFixd = False\nfor i in range(n):\n if fix[i] == -1:\n fix[i] = 1\n isTopNumFixd = True\n elif fix[i] == 0 and isTopNumFixd is False:\n print(-1)\n exit(0)\nfor i in range(n):\n ans = ans * 10 + fix[i]\n\nprint(ans)\n\n', 'n, m = map(int, input().split())\n \nconds = []\n \nfor i in range(m):\n s, c = map(int, input().split())\n conds.append([s, c])\n \n\nconds = sorted(conds)\nfor i in range(len(conds)):\n if i + 1 < len(conds) and (conds[i][0] == conds[i + 1][0]\n and conds[i][1] != conds[i + 1][1]):\n print(-1)\n exit(0)\n \n# list to check conditions.If -1, no condition\nfix = [-1] * n\n \nfor i in range(len(conds)):\n fix[conds[i][0] - 1] = conds[i][1]\n \nans = 0\nfor i in range(n):\n if fix[i] == -1 and (i == 0 and n != 1):\n fix[i] = 1\n elif fix[i] == -1:\n fix[i] = 0\n else:\n print(-1)\n exit(0)\n \nfor i in range(n):\n ans = ans * 10 + fix[i]\n \nprint(ans)\nn, m = map(int, input().split())\n\nconds = []\n\nfor i in range(m):\n s, c = map(int, input().split())\n conds.append([s, c])\n\n\nconds = sorted(conds)\nfor i in range(len(conds)):\n if i + 1 < len(conds) and (conds[i][0] == conds[i + 1][0]\n and conds[i][1] != conds[i + 1][1]):\n print(-1)\n exit(0)\n\n# list to check conditions.If -1, no condition\nfix = [-1] * n\n\nfor i in range(len(conds)):\n fix[conds[i][0] - 1] = conds[i][1]\n\nans = 0\nisTopNumFixd = False\nfor i in range(n):\n if fix[i] == -1 and (i == 0 and n != 1):\n fix[i] = 1\n isTopNumFixd = True\n elif fix[i] == -1:\n fix[i] = 0\n isTopNumFixd = True\n\nfor i in range(n):\n ans = ans * 10 + fix[i]\n\nprint(ans)', 'n, m = map(int, input().split())\n\nconds = []\n\nfor i in range(m):\n s, c = map(int, input().split())\n conds.append([s, c])\n\n\nconds = sorted(conds)\nfor i in range(len(conds)):\n if i + 1 < len(conds) and (conds[i][0] == conds[i + 1][0]\n and conds[i][1] != conds[i + 1][1]):\n print(-1)\n exit(0)\n\n# list to check conditions.If -1, no condition\nfix = [-1] * n\n\nfor i in range(len(conds)):\n fix[conds[i][0] - 1] = conds[i][1]\n\nans = 0\nisTopNumFixd = False\nfor i in range(n):\n if fix[i] == -1 and (i == 0 and n != 1):\n fix[i] = 1\n isTopNumFixd = True\n elif fix[i] == -1:\n fix[i] = 0\n isTopNumFixd = True\n elif fix[i] == 0 and (i == 0 and n != 1):\n print(-1)\n exit(0)\n\nfor i in range(n):\n ans = ans * 10 + fix[i]\n\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s148839267', 's392930142', 's040190438'] | [3064.0, 3192.0, 3064.0] | [17.0, 17.0, 17.0] | [734, 1496, 842] |
p02761 | u975039852 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n, m = map(int, input().split())\nlst = [-1] * n\nflag = False\nfor i in range(m):\n s, c = map(int, input().split())\n if c != lst[s-1] or (n != 1 and s == 1 and c == 0):\n flag = True\n lst[s-1] = c\nif flag:\n print(-1)\nelse:\n for i in range(n):\n if lst[i] == -1:\n lst[i] = '1' if n != 1 and i == 0 else '0'\n else:\n lst[i] = str(lst[i])\n print(''.join(lst))", 'n, m = map(int, input().split())\nlst = []\nfor i in range(m):\n s, c = map(int, input().split())\n lst.append([s, c])\nans = -1\nfor j in range(10 ** n):\n if len(str(j)) != n:\n continue\n for i in range(m):\n if int(str(j)[lst[i][0]-1]) != lst[i][1]:\n break\n else:\n ans = j\n break\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s844678447', 's446784620'] | [3064.0, 3064.0] | [17.0, 18.0] | [376, 306] |
p02761 | u977771109 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["import sys\nrl = sys.stdin.readline\n\nn, m = [int(x) for x in rl().split(' ')]\n\ndigits = [-1 for x in range(n)]\nfor i in range(m):\n s, c = [int(x) for x in rl().split(' ')]\n digits[s-1] = c\n\nhasNonZero = False\nfor i in range(len(digits)):\n if digits[i] > 0:\n hasNonZero = True\n elif digits[i] < 0:\n if hasNonZero:\n digits[i] = 0\n else:\n digits[i] = 1\n\nprint(digits)\n\nans = 0\nfor d in digits:\n ans = ans*10 + d\nprint(ans)\n", "#!/usr/bin/env python\nimport sys\nfrom io import StringIO\n\ndef guess(rl=sys.stdin.readline):\n n, m = [int(x) for x in rl().split(' ')]\n\n digits = [-1 for x in range(n)]\n for i in range(m):\n s, c = [int(x) for x in rl().split(' ')]\n if digits[s-1] >= 0 and digits[s-1] != c:\n return -1\n else:\n digits[s-1] = c\n\n if n == 1 and digits[0] < 0:\n return 0\n if n > 1 and digits[0] == 0:\n return -1\n\n for i in range(len(digits)):\n if digits[i] < 0:\n if i == 0:\n digits[i] = 1\n else:\n digits[i] = 0\n\n ans = 0\n for d in digits:\n ans = ans*10 + d\n return ans\n\nprint(guess())\n"] | ['Wrong Answer', 'Accepted'] | ['s335647239', 's565564531'] | [3064.0, 3064.0] | [17.0, 17.0] | [477, 713] |
p02761 | u979038517 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['\ndef main():\n N, M = [int(x) for x in input().split()]\n expected_num_ary = [0] * N\n\n digit = []\n value = []\n for _ in range(M):\n d, v = [int(x) for x in input().split()]\n if d > N:\n print("-1")\n return\n if expected_num_ary[d - 1] != 0:\n print("-1")\n return\n expected_num_ary[d - 1] = v\n\n num_str = ""\n for num in expected_num_ary:\n num_str += str(num)\n\n print(-1 if len(num_str) != len(num_str.lstrip("0")) else num_str)\n\n\nif __name__ == \'__main__\':\n main()', 'def main():\n N, M = [int(x) for x in input().split()]\n expected_num_ary = [1] + [0] * (N - 1)\n\n if N == 1 and M == 0:\n print("0")\n return\n\n inputted_digit = []\n for _ in range(M):\n d, v = [int(x) for x in input().split()]\n if d > N:\n print("-1")\n return\n if d in inputted_digit and expected_num_ary[d - 1] != v:\n print("-1")\n return\n if d == 1 and v == 0 and N > 1:\n print("-1")\n return\n expected_num_ary[d - 1] = v\n inputted_digit.append(d)\n\n num_str = ""\n for num in expected_num_ary:\n num_str += str(num)\n print(num_str)\n\n\n\nif __name__ == \'__main__\':\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s449277002', 's672321524'] | [3064.0, 3064.0] | [17.0, 17.0] | [563, 718] |
p02761 | u979126665 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import sys\nn,m = map(int,input().split(" "))\nnums = [-1] * n\nfor _ in range(m):\n s,c = map(int,input().split(" "))\n if n > 1 and s == 1 and c == 0:\n print(-1)\n sys.exit(0)\n if nums[s-1] != -1 and c != nums[s-1]:\n print(-1)\n sys.exit(0)\n nums[s-1] = c\nnums = [0 for num in nums if num == -1 else num]\nif n == 1:\n print(nums[0])\n sys.exit(0)\nif nums[0] == 0:\n nums[0] = 1\nprint("".join(map(str,nums)))', 'import sys\nn,m = map(int,input().split(" "))\nnums = [0] * m\nfor _ in range(m):\n s,c = map(int,input().split(" "))\n if c >= 10 or c < 0:\n print(-1)\n sys.exit(0)\n if s >= n:\n print(-1)\n sys.exit(0)\n if s == 1 and c == 0:\n print(-1)\n sys.exit(0)\n if nums[s-1] != 0 and c != nums[s-1]:\n print(-1)\n sys.exit(0)\n nums[s-1] = c\nif nums[0] == 0:\n nums[0] = 1\nprint("".join(map(str,nums)))', 'import sys\nn,m = map(int,input().split(" "))\nnums = [-1] * n\nfor _ in range(m):\n s,c = map(int,input().split(" "))\n if n > 1 and s == 1 and c == 0:\n print(-1)\n sys.exit(0)\n if nums[s-1] != -1 and c != nums[s-1]:\n print(-1)\n sys.exit(0)\n nums[s-1] = c\nnums = [0 if num == -1 else num for num in nums]\nif n == 1:\n print(nums[0])\n sys.exit(0)\nif nums[0] == 0:\n nums[0] = 1\nprint("".join(map(str,nums)))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s570879969', 's676537701', 's007300668'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 17.0] | [448, 457, 448] |
p02761 | u981040490 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["# -*- coding: utf-8 -*-\ndef main():\n N,M = map(int,input().split())\n SC = [list(map(int,input().split())) for i in range(M)]\n #print(N,M,SC)\n ans = []\n for _ in range(N):\n ans.append(-1)\n #print(ans)\n for j in range(M):\n if ans[SC[j][0]-1] == -1 or ans[SC[j][0]-1] == SC[j][1]:\n ans[SC[j][0]-1] = SC[j][1]\n else:\n print('-1')\n return\n for k in range(N):\n if ans[k]==-1:\n ans[k]=0\n print(ans[k],end = '')\n #print(''.join(str(ans)))\nif __name__ == '__main__':\n main()", "# -*- coding: utf-8 -*-\ndef main():\n N,M = map(int,input().split())\n SC = [list(map(int,input().split())) for i in range(M)]\n ans = []\n anst = ''\n for _ in range(N):\n ans.append(-1)\n for j in range(M):\n if ans[SC[j][0]-1] == -1 or ans[SC[j][0]-1] == SC[j][1]:\n ans[SC[j][0]-1] = SC[j][1]\n else:\n print('-1')\n return\n for k in range(N):\n if ans[k] == -1:\n if k == 0 and N>=2:\n ans[k] = 1\n else:\n ans[k] = 0\n anst += str(ans[k])\n if len(str(int(anst))) != N:\n print('-1')\n return\n print(int(anst))\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s940228912', 's090158927'] | [3064.0, 3064.0] | [17.0, 17.0] | [575, 695] |
p02761 | u981332890 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import math\ndef main():\n N, M = map(int, input().split())\n\n ans = {i:0 for i in range(N)}\n for _ in range(M):\n s, c = map(int, input().split())\n\n ans[s-1] = c\n if ans[0] == 0:\n print(-1)\n return 0\n\n for v in ans.values():\n print(v, end="")\n\n\n\n\n return 0\nif __name__ == \'__main__\':\n main()', 'import math\ndef main():\n N, M = map(int, input().split())\n\n ans = {i:0 for i in range(N)}\n\n for _ in range(M):\n s, c = map(int, input().split())\n if s-1 not in ans:\n print(-1)\n return 0\n if (ans[s-1] != 0) and (ans[s-1] > c):\n ans[s-1] = c\n else:\n ans[s - 1] = c\n if (ans[0] == 0) and (len(ans) != 1):\n print(-1)\n return 0\n\n for v in ans.values():\n print(v, end="")\n\n\n\n\n return 0\nif __name__ == \'__main__\':\n main()', 'import math\ndef main():\n N, M = map(int, input().split())\n\n ans = {i:0 for i in range(N)}\n for _ in range(M):\n s, c = map(int, input().split())\n if s-1 not in ans:\n print(-1)\n return 0\n\n ans[s-1] = c\n if (ans[0] == 0) and (len(ans) != 1):\n print(-1)\n return 0\n\n for v in ans.values():\n print(v, end="")\n\n\n\n\n return 0\nif __name__ == \'__main__\':\n main()', "def main():\n N, M = map(int, input().split())\n S = []\n for _ in range(M):\n S.append(tuple(map(int, input().split())))\n\n for i in range(0, 10**N):\n k = str(i)\n count = 0\n if len(k) < N:\n continue\n for s, c in S:\n if k[s-1] == str(c):\n count += 1\n if count == M:\n print(i)\n return 0\n print(-1)\n\n return 0\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s098623374', 's108343527', 's117347379', 's277544703'] | [3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 17.0, 17.0, 18.0] | [344, 528, 436, 461] |
p02761 | u985125584 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["import sys\n\nN, M = map(int, input().split())\n\nans = ['*'] * N\n\nif M == 0:\n if N == 1:\n print(0)\n else:\n print(10**(N-1))\nelse:\n for i in range(M):\n a, b = map(int, input().split())\n\n if ans[a-1] == '*':\n ans[a-1] = str(b)\n else:\n print(-1)\n sys.exit()\n\n for i in range(M):\n if ans[i] == '*' or ans[i] == '0':\n print(-1)\n sys.exit()\n else:\n print(''.join(ans).replace('*', '0'))\n sys.exit()\n", "import sys\n\nN, M = map(int, input().split())\n\nans = ['*'] * N\nflag = 0\n\nif M == 0:\n if N == 1:\n print(0)\n else:\n print(10**(N-1))\nelse:\n for i in range(M):\n a, b = map(int, input().split())\n\n if ans[a-1] == '*':\n ans[a-1] = str(b)\n else:\n flag += 1\n\n if flag != 0:\n print(-1)\n sys.exit()\n\n for i in range(M):\n if ans[i] == '*' or ans[i] == '0':\n print(-1)\n sys.exit()\n else:\n print(''.join(ans).replace('*', '0'))\n\n sys.exit()\n", "N, M = map(int, input().split())\na = [list(map(int, input().split())) for _ in range(M)]\n\nans = [None] * N\n\nfor i in a:\n if ans[i[0]-1] is None:\n ans[i[0]-1] = i[1]\n elif ans[i[0]-1] != i[1]:\n print(-1)\n exit()\n \nif N == 1:\n if ans[0] is None:\n print(0)\n else:\n print(ans[0])\n exit()\n\nif ans[0] == 0:\n print(-1)\n exit()\n\nfor i, v in enumerate(ans):\n if v is None:\n ans[i] = 0\n\nif ans[0] == 0:\n ans[0] = 1\n\nprint(''.join(list(map(str,ans))))\n\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s339301717', 's735002757', 's469580911'] | [3064.0, 3064.0, 3064.0] | [18.0, 17.0, 18.0] | [528, 571, 518] |
p02761 | u987170100 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N, M = map(int, input().split())\nlst = [0] * N\nif M == 0 and N != 1:\n lst[0] = 1\nelse:\n dic = {}\n for _ in range(M):\n s, c = map(int, input().split())\n n = dic.get(s)\n if n is not None and n != c:\n print(-1)\n exit()\n dic[s] = c\n\nif N != 1 and lst[0] == 0:\n print(-1)\n exit()\n\nfor k, v in dic.items():\n lst[k - 1] = v\n\nif len(lst) != 0 and lst[0] == 0:\n lst[0] = 1\n\nprint("".join(map(str, lst)))\n', 'N, M = map(int, input().split())\nif M == 0:\n if N == 1:\n print(0)\n else:\n print("1" + "0" * (N - 1))\n exit()\n\ndic = {}\nfor _ in range(M):\n s, c = map(int, input().split())\n if s == 1 and c == 0 and N != 1:\n print(-1)\n exit()\n n = dic.get(s)\n if n is not None and n != c:\n print(-1)\n exit()\n dic[s] = c\n\nlst = [0] * N\nfor k, v in dic.items():\n lst[k - 1] = v\n\nif len(lst) != 1 and lst[0] == 0:\n lst[0] = 1\n\nprint("".join(map(str, lst)))\n'] | ['Runtime Error', 'Accepted'] | ['s883906383', 's549983239'] | [3064.0, 3064.0] | [20.0, 17.0] | [466, 508] |
p02761 | u987326700 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m = map(int,input().split())\ns = []\nc = []\nwhile True:\n try:\n tmp = list(map(int,input().split()))\n s.append(tmp[0])\n c.append(tmp[1])\n except EOFError:\n break\n \nfor i in range(10**(n-1)-1,10**n):\n cnt =0\n tmp = str(i)\n for _ in range(len(c)):\n if tmp[s[_]-1]==str(c[_]):\n cnt +=1\n if cnt == len(c):\n print(i)\n exit()\nprint("-1")', 'n,m = map(int,input().split())\ns = []\nc = []\nwhile True:\n try:\n tmp = list(map(int,input().split()))\n s.append(tmp[0])\n c.append(tmp[1])\n except EOFError:\n break\nif n == 1 and all(i == 0 for i in c):\n print(0)\n exit()\nfor i in range(10**(n-1),10**n):\n cnt =0\n tmp = str(i)\n for _ in range(len(c)):\n if tmp[s[_]-1]==str(c[_]):\n cnt +=1\n if cnt == len(c):\n print(i)\n exit()\nprint("-1")'] | ['Runtime Error', 'Accepted'] | ['s467126993', 's367113900'] | [3064.0, 3064.0] | [19.0, 19.0] | [364, 417] |
p02761 | u989348352 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['N , M = [int(i) for i in input().split()]\ns = [[int(j) for j in input().split()] for i in range(M)]\n#print(s)\n#print(c)\nx = 0\n\ns = list(map(list, set(map(tuple, s))))\nf = [0] * N\n\n#print(f)\nfor ss in s:\n if f[ss[0]-1] == 1:\n x = -1\n break\n if ss[0] == 1 and ss[1]==0:\n if N == 1:\n x = 0\n break\n else:\n x = -1\n break\n \n f[ss[0]-1] = 1\n x += ss[1] * 10 ** (N-ss[0])\n #for cc in c:\n\nif x < 10 ** N:\n print(-1)\nelse:\n print(x)\n\n', '\nN , M = [int(i) for i in input().split()]\ns = [[int(j) for j in input().split()] for i in range(M)]\n#print(s)\n#print(c)\nx = 0\n\ns = list(map(list, set(map(tuple, s))))\nf = [0] * N\n\n#print(f)\nfor ss in s:\n if f[ss[0]-1] == 1:\n f = [1] * N\n x = -1\n break\n if ss[0] == 1 and ss[1]==0:\n f[0]=1\n if N == 1:\n x = 0\n break\n else:\n f = [1] * N\n x = -1\n break\n \n f[ss[0]-1] = 1\n x += ss[1] * 10 ** (N-ss[0])\n #for cc in c:\n\n\nif N == 1 and M == 0:\n print(0)\nelse:\n if f[0]==0:\n x += 10 ** (N-1)\n print(x)\n else:\n print(x)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s017748685', 's849024499'] | [3064.0, 3064.0] | [17.0, 17.0] | [544, 683] |
p02761 | u991567869 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\ns = [list(map(int, input().split())) for _ in range(m)]\ncnt = 0\n\nfor i in range(1000):\n il = len(str(i))\n if il == n:\n for j in range(m):\n if il >= j + 1:\n num = s[j][0] - 1\n k = str(i)\n if str(s[j][1]) == k[num]:\n cnt += 1\n num = 0\n if cnt == n:\n print(i)\n exit()\n\nprint(-1)', 'n, m = map(int, input().split())\ns = [list(map(int, input().split())) for _ in range(m)]\ncnt = 0\n\nif m == 0:\n if n == 1:\n print(0)\n exit()\n else:\n print(10**(n - 1))\n exit()\nfor i in range(1000):\n il = len(str(i))\n if il == n:\n for j in range(m):\n num = s[j][0] - 1\n k = str(i)\n if str(s[j][1]) == k[num]:\n cnt += 1\n num = 0\n if cnt == m:\n print(i)\n exit()\n else:\n cnt = 0\nprint(-1)'] | ['Wrong Answer', 'Accepted'] | ['s691569195', 's866985822'] | [3064.0, 3064.0] | [20.0, 20.0] | [440, 535] |
p02761 | u992910889 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['def resolve():\n N, M = map(int, input().split())\n S, C = [0] * M, [0] * M\n for i in range(M):\n S[i], C[i] = map(int, input().split())\n\n def main():\n if M==0:\n if N==1:\n return 10\n elif N==2:\n return 10\n else:\n return 100\n else:\n for j in range(10**(N-1),10**(N)):\n for i in range(M):\n if str(j)[S[i]-1]==C[i]:\n return j\n print(main() if main()!=None else -1)\n\n\nresolve()', '\ndef resolve():\n N, M = map(int, input().split())\n S, C = [0] * M, [0] * M\n for i in range(M):\n S[i], C[i] = map(int, input().split())\n\n def main():\n if M == 0:\n if N == 1:\n return 10\n elif N == 2:\n return 10\n else:\n return 100\n else:\n for j in range(10 ** (N - 1), 10 ** (N)):\n for i in range(M):\n if str(j)[S[i] - 1] != C[i]:\n break\n elif i == M - 1:\n return j\n\n\n val=main()\n print(val if val != None else -1)\n\nresolve()', 'def resolve():\n N, M = map(int, input().split())\n S, C = [0] * M, [0] * M\n for i in range(M):\n S[i], C[i] = map(int, input().split())\n\n def main():\n if M == 0:\n if N == 1:\n return 0\n elif N == 2:\n return 10\n else:\n return 100\n elif M==1 and N==1 and S[0]==1 and C[i]==0:\n return 0\n else:\n for j in range(10 ** (N - 1), 10 ** (N)):\n for k in range(M):\n temp=str(j)[S[k] - 1]\n if temp!=str(C[k]):\n break\n elif k == M - 1:\n return j\n\n\n val=main()\n print(val if val != None else -1)\n\nresolve()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s197127267', 's996456911', 's229579520'] | [3064.0, 3064.0, 3188.0] | [18.0, 18.0, 19.0] | [632, 649, 753] |
p02761 | u993090205 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['import sys\nfrom io import StringIO\nimport unittest\n\n\ndef exists(value, n, ms, cs):\n if len(value) != n:\n return False\n if all([value[i - 1] == c for i, c in zip(ms, cs)]):\n return True\n return False\n\n\ndef unzip(li):\n return list(map(list, zip(*li)))\n\n\ndef resolve():\n result = -1\n inputs = sys.stdin\n n, m = [int(e) for e in inputs.readline().split()]\n if m == 0:\n print(0)\n return\n m = [input().split() for e in range(m)]\n ms, cs = unzip(m)\n ms = [int(e) for e in ms]\n\n for i in range(1000):\n if exists(str(i), n, ms, cs):\n result = i\n break\n print(result)\n', 'def exists(value,n,ms,cs):\n if (len(value) != n):\n return False\n if (len(value) <= len(m)):\n return False\n if not all([value[i-1] == c for i,c in zip(ms,cs)]):\n return False\n return True\ndef unzip(li):\n return list(map(list, zip(*li)))\nn,m = [int(e) for e in input().split()]\nm = [input().split() for e in range(m)]\nms,cs = unzip(m)\nms = [int(e) for e in ms]\nresult = -1\nfor i in range(1000):\n if exists(str(i),n,ms,cs):\n result = i\n break\nprint(result)', 'def exists(value,n,ms,cs):\n if (len(value) != n):\n return False\n if not all([value[i-1] == c for i,c in zip(ms,cs)]:\n return False\n return True\ndef unzip(li):\n return list(map(list, zip(*li)))\nn,m = [int(e) for e in input().split()]\nm = [input().split() for e in range(m)]\nms,cs = unzip(m)\nms = [int(e) for e in ms]\nresult = -1\nfor i in range(1000):\n if exists(str(i),n,ms,cs):\n result = i\n break\nprint(result)', 'def exists(value,n,ms,cs):\n if (len(value) != n):\n return False\n if all([value[i-1] == c for i,c in zip(ms,cs)]):\n return True\n return True\ndef unzip(li):\n return list(map(list, zip(*li)))\nn,m = [int(e) for e in input().split()]\nm = [input().split() for e in range(m)]\nms,cs = unzip(m)\nms = [int(e) for e in ms]\nresult = -1\nfor i in range(1000):\n if exists(str(i),n,ms,cs):\n result = i\n break\nprint(result)', 'def exists(value,n,ms,cs):\n if (len(value) != n):\n return False\n if len(value) < max(ms):\n return False\n if not all([value[i-1] == c for i,c in zip(ms,cs)]:\n return False\n return True\ndef unzip(li):\n return list(map(list, zip(*li)))\nn,m = [int(e) for e in input().split()]\nm = [input().split() for e in range(m)]\nms,cs = unzip(m)\nms = [int(e) for e in ms]\nresult = -1\nfor i in range(1000):\n if exists(str(i),n,ms,cs):\n result = i\n break\nprint(result)', 'def exists(value,n,ms,cs):\n if (len(value) != n):\n return False\n if not all([value[i-1] == c for i,c in zip(ms,cs)]):\n return False\n return True\ndef unzip(li):\n return list(map(list, zip(*li)))\nn,m = [int(e) for e in input().split()]\nm = [input().split() for e in range(m)]\nms,cs = unzip(m)\nms = [int(e) for e in ms]\nfor i in range(1000):\n if exists(str(i),n,ms,cs):\n print(i)\n break\nprint(-1)', 'n,m = map(int,input().split())\nsc = [[i for i in map(int,input().split())] for j in range(m)]\nstart = 0\ngoal = 0\nif n==1:\n start = 0\n goal = 9\nelif n==2:\n start = 10\n goal = 99\nelif n==3:\n start = 100\n goal = 999\n\nflag = 1\nans = -1\nfor num in range(start,goal+1):\n flag = 1\n for i in range(m):\n if str(num)[sc[i][0]-1] != str(sc[i][1]): \n flag = 0\n if flag == 1:\n ans = num\n break\n\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s065205427', 's176914127', 's552308239', 's642113645', 's663315075', 's858067970', 's539168154'] | [6464.0, 3064.0, 2940.0, 3064.0, 2940.0, 3064.0, 3064.0] | [69.0, 19.0, 17.0, 18.0, 19.0, 18.0, 18.0] | [654, 506, 453, 449, 503, 436, 452] |
p02761 | u993310962 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m=map(int,input().split())\nans=[0]*n\nbuf=0\nfor i in range(m):\n s,c=map(int,input().split())\n if ans[s-1]==0:\n ans[s-1]+=c\n elif ans[s-1]!=0 and c!=ans[s-1]:\n buf+=1\nif buf==0 and ans[0]!=0:\n anstr=[str(num) for num in ans]\n print(''.join(ans))\nelif buf==0 and ans[0]==0:\n print(-1)\nelse:\n print(-1)", "n,m=map(int, input().split())\nl=[]\ncnt=0\nif m==1:\n s,c=map(int, input().split())\n if s==1 and c==0:\n print('-1')\n elif s!=n:\n print(10**(n-1)+c*(10**(n-s)))\n else:\n print(c*(10**(n-s))\nelse:\n for i in range(m):\n s,c=map(int, input().split())\n l.append([s,c])\n if s==1 and c==0: \n cnt+=1\n buf=0\n for i in range(m-1):\n for j in range(i+1,m):\n if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:\n buf+=1\n if buf!=0 or cnt!=0:\n print('-1')\n else:\n l.sort()\n ans=l[0][1]*(10**(n-l[0][0]))\n for i in range(1,m):\n if l[i-1][0]==l[i][0]:\n continue\n else:\n ans+=l[i][1]*(10**(n-l[i][0]))\n print(ans)", "import sys\nn,m=map(int,input().split())\nans=[0]*n\nscash=[]\nbuf=0\nfor i in range(m):\n s,c=map(int,input().split())\n if s not in scash:\n ans[s-1]+=c\n scash.append(s)\n elif (s in scash) and c!=ans[s-1]:\n buf+=1\n scash.append(s)\nif n==1 and ans[0]==0:\n print(0)\n sys.exit()\nif buf==0 and ans[0]!=0:\n anstr=[str(num) for num in ans]\n print(''.join(anstr))\nelif buf==0 and (1 not in scash):\n ans[0]+=1\n anstr=[str(num) for num in ans]\n print(''.join(anstr))\nelse:\n print(-1)"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s166266962', 's359400514', 's035639774'] | [3064.0, 2940.0, 3064.0] | [18.0, 17.0, 18.0] | [335, 824, 529] |
p02761 | u993622994 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["N, M = map(int, input().split())\nans = ['-1'] * N\n\nfor i in range(M):\n s, c = map(int, input().split())\n if ans[s-1] == str(c):\n continue\n elif ans[s-1] == '-1':\n ans[s-1] = str(c)\n else:\n ans = -1\n print(ans)\n exit()\n\nfor i in range(N):\n if ans[i] == '-1':\n ans[i] = str(0)\n\nif N == 3 and ans[0] == '0' or ans[1] == '0':\n ans = -1\n print(ans)\n exit()\nelif N == 2 and ans[0] == '0':\n ans = -1\n print(ans)\n exit()\nelse:\n print(''.join(ans))", "N, M = map(int, input().split())\nans = ['-1'] * N\n\nif N == 1 and M == 0:\n print(0)\n exit()\n\nfor i in range(M):\n s, c = map(int, input().split())\n if ans[s-1] == str(c):\n continue\n elif ans[s-1] == '-1':\n ans[s-1] = str(c)\n else:\n print(-1)\n exit()\n\nif N >= 2 and ans[0] == '0':\n print(-1)\n exit()\nelif ans[0] == '-1':\n ans[0] = '1'\n\nans = ''.join(ans).replace('-1', '0')\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s216393015', 's914396613'] | [3064.0, 3188.0] | [17.0, 20.0] | [517, 436] |
p02761 | u995419623 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['a,b=map(int,input().split())\nans=-1\narr = [list(map(int,input().split)) for i in range(b)]\n\nfor i in range(1001):\n j=str(i)\n if len(j)==a and all(j[s-1]==str(t) for s,t in arr):\n ans = i\n break\nprint(ans)', 'a,b=map(int,input().split())\nans=-1\narr = [list(map(int,input().split())) for i in range(b)]\n\nfor i in range(1001):\n j=str(i)\n if len(j)==a and all(j[s-1]==str(t) for s,t in arr):\n ans = i\n break\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s364177851', 's804086516'] | [3060.0, 3064.0] | [17.0, 19.0] | [212, 214] |
p02761 | u995861601 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\nl = [-1]*n\n\nr = True\nfor i in range(m):\n s, c = map(int, input().split())\n if l[s-1] == -1:\n l[s-1] = c\n else:\n if l[s-1] != c:\n r = False\n\nif l[0] == -1:\n if n == 1:\n l[0] = 0\n else:\n l[0] = 1\n\nfor i in range(1, n+1):\n if l[i] == -1:\n l[i] = 0\nif r == True:\n print("".join(map(str, l)))\nelse:\n print(-1)', 'n, m = map(int, input().split())\nl = [-1]*n\n\nr = True\nfor i in range(m):\n s, c = map(int, input().split())\n if l[s-1] == -1:\n l[s-1] = c\n else:\n if l[s-1] != c:\n r = False\n\nif l[0] == -1:\n if n == 1:\n l[0] = 0\n else:\n l[0] = 1\nif l[0] == 0:\n if n != 1:\n r = False\n \nfor i in range(1, n):\n if l[i] == -1:\n l[i] = 0\n \nif r == True:\n print("".join(map(str, l)))\nelse:\n print(-1)'] | ['Runtime Error', 'Accepted'] | ['s105620350', 's949435518'] | [3064.0, 3064.0] | [17.0, 17.0] | [407, 469] |
p02761 | u996434204 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m = map(int,input().split())\nans = []\n\nfor i in range(m):\n s,c = map(int,input().split())\n li.append([s,c])\n\nfor i in range(10**(n-1),10**n):\n buf = str(i)\n flag = True\n for j in range(len(li)):\n if buf[li[j][0]-1] != str(li[j][1]):\n flag = False\n if flag:\n ans.append(buf)\n flag = True\n\nans.sort()\nif ans:\n print(ans[0])\nelse:\n print(-1)\n', 'n,m = map(int,input().split())\nans = []\nli = []\n\nfor i in range(m):\n s,c = map(int,input().split())\n li.append([s,c])\n\nif n == 1:\n for i in range(10):\n buf = str(i)\n flag = True\n for j in range(len(li)):\n if buf[li[j][0]-1] != str(li[j][1]):\n flag = False\n if flag:\n ans.append(buf)\n flag = True\nelse:\n for i in range(10**(n-1),10**n):\n buf = str(i)\n flag = True\n for j in range(len(li)):\n if buf[li[j][0]-1] != str(li[j][1]):\n flag = False\n if flag:\n ans.append(buf)\n flag = True\n\nans.sort()\nif ans:\n print(ans[0])\nelse:\n print(-1)\n'] | ['Runtime Error', 'Accepted'] | ['s060335629', 's657560852'] | [3064.0, 3064.0] | [17.0, 19.0] | [397, 703] |
p02761 | u996506712 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n,m=map(int,input().split())\nif m=0:\n print(0)\nelse:\n sc= [list(map(int,input().split())) for i in range(m)]\n ans = -1\n s=[[0 for i in range(2)] for i in range(n)]\n for j in range(10**n):\n k=str(j)\n for l in range(len(k)):\n s[l][0]=l+1\n s[l][1]=int(k[l])\n if all(elm in s for elm in sc) == 1:\n ans=j\n break\n print(ans)', 'n,m=map(int,input().split())\nif m=0:\n print(0)\nelse:\n sc= [list(map(int,input().split())) for i in range(m)]\n ans = -1\n s=[[0 for i in range(2)] for i in range(n)]\n for j in range(10**n):\n k=str(j)\n for l in range(len(k)):\n s[l][0]=l+1\n s[l][1]=int(k[l])\n if all(elm in s for elm in sc) == 1:\n ans=j\n break\n print(ans)', 'n,m=map(int,input().split())\nif m==0:\n if n ==1:\n print(0)\n else:\n print(10**(n-1))\nelse:\n sc= [list(map(int,input().split())) for i in range(m)]\n ans = -1\n for j in range(10**(n-1)-1,10**n):\n k=str(j)\n s=[[0 for i in range(2)] for i in range(len(k))]\n for l in range(len(k)):\n s[l][0]=l+1\n s[l][1]=int(k[l])\n if all(elm in s for elm in sc) == 1:\n ans=j\n break\n if ans==j:\n break\n print(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s194392659', 's211838657', 's150738008'] | [9008.0, 8840.0, 9240.0] | [23.0, 25.0, 30.0] | [353, 351, 449] |
p02761 | u998082063 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['n, m = map(int, input().split())\ntmp = []\none = 1000\ntwo = 11000\nthree = 10000\nfor i in range(m):\n s, c = map(int, input().split())\n tup = (s, c)\n tmp.append(tup)\n\ns = set(tmp)\nfor a, b in s:\n if a == 1:\n if one > b:\n one = b*100\n elif a == 2:\n if two > b:\n two = b*10\n elif a ==3:\n if three > b:\n three = b\n\nif one == 0 and n != m:\n print(-1)\nelse:\n print(one + two + three)', "from collections import defaultdict, deque\nimport sys\nimport heapq\nimport bisect\nimport itertools\nimport queue\nimport copy\nimport time\nsys.setrecursionlimit(10**8)\nINF = float('inf')\nmod = 10**9+7\neps = 10**-7\n\ndef inp(): return int(sys.stdin.readline())\n\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\ndef inpl_str(): return list(sys.stdin.readline().split())\n\ndef inpl_strl(): return list(sys.stdin.readline())\n\nn,m = inpl()\na = [list(map(int, input().split())) for i in range(m)]\nans = -1\nfor i in range(1000):\n s = str(i)\n if len(s) == n:\n flg = 0\n for (x, y) in a:\n if int(s[x-1]) != y:\n flg = 1\n if flg == 0:\n ans = i\n break\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s642305083', 's778582542'] | [3064.0, 4072.0] | [18.0, 29.0] | [453, 734] |
p02761 | u998741086 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ['#!/usr/bin/env python3\nn, m = map(int, input().split())\ns = [-1 for _ in range(m)]\nc = [-1 for _ in range(m)]\nfor i in range(m):\n s[i], c[i] = map(int, input().split())\n\nfor x in range(1000):\n keta = 1 \n nx = x/10\n d = []\n while nx: \n keta += 1\n d.append(nx%10)\n nx /= 10\n if keta != n:\n continue\n ok = True\n d = d[::-1]\n for i in range(m):\n if d[s[i]-1] != c[i]:\n ok = False\n if ok: \n print(x)\n exit(0)\n\nprint(-1)\n', "#!/usr/bin/env python3\nn, m = map(int, input().split())\ns = [-1 for _ in range(m)]\nc = [-1 for _ in range(m)]\nfor i in range(m):\n s[i], c[i] = map(int, input().split())\n\nfor i in range(1000):\n flg = True\n numstr = str(i)\n\n if len(numstr) != n:\n continue\n\n for j in range(m):\n\n# print('j =', j)\n\n# print('c[j] =', c[j])\n# print()\n if numstr[s[j]-1] != str(c[j]):\n flg = False\n if flg == True:\n print(i)\n exit(0)\nprint(-1)"] | ['Runtime Error', 'Accepted'] | ['s177222289', 's698798105'] | [3064.0, 3064.0] | [152.0, 20.0] | [505, 582] |
p02761 | u999503965 | 2,000 | 1,048,576 | If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) | ["n,m=map(int,input().split())\nl=[list(map(int,input().split())) for i in range(m)]\n\nnum=[-1]*n\n\nfor i in l:\n if num[i[0]-1]==-1 or num[i[0]-1]==i[1]:\n num[i[0]-1]=i[1]\n elif i[0]==1 and i[1]==0 and n==1:\n print(0)\n exit()\n else:\n print(-1)\n exit()\n \nif num[0]==0:\n print(-1)\nelif n=1 and num[0]==-1:\n print(0)\nelse:\n for i in range(len(num)):\n if num[i]==-1 and i==0:\n num[i]=1\n elif num[i]==-1:\n num[i]=0\n \n print(*num,sep='')", 'N,M = map(int,input().split())\na = [-1]*N\nans = 0\nfor i in range(M):\n s,c = map(int,input().split())\n if a[s-1] == -1:\n a[s-1] = c\n elif a[s-1] != c:\n ans = -1\n break\nif a[0] == 0 and N>1:\n ans = -1\nif ans != -1:\n if a[0] == -1 and N>1:\n a[0] = 1\n if a[0] == -1 and N == 1:\n a[0] = 0\n for i in range(N):\n if a[i] == -1:\n a[i] = 0\n a[i] = str(a[i])\n ans = "".join(a)\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s543418808', 's359515818'] | [8956.0, 9204.0] | [29.0, 29.0] | [470, 461] |
p02762 | u002539468 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int, input().split())\n\ncandidates = [0] * n\nfriends = [set() for _ in range(n)]\nblocks = [set() for _ in range(n)]\nparent = [i for i in range(n)]\nsizes = [1 for _ in range(n)]\n\ndef root(x):\n global parent\n if parent[x] == x:\n return x\n else:\n parent[x] = root(parent[x])\n return parent[x]\n\ndef unite(x, y):\n global parent\n global sizes\n x = root(x)\n y = root(y)\n if x == y:\n return\n parent[x] = y\n \n \n\ndef same(x, y):\n return root(x) == root(y)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a - 1].add(b - 1)\n friends[b - 1].add(a - 1)\n unite(a - 1, b - 1)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if same(c - 1, d - 1):\n blocks[c - 1].add(d - 1)\n blocks[d - 1].add(c - 1)\n\nfor i in range(n):\n x = root(i)\n s = sizes[x]\n candidates[i] = s - len(friends[i]) - len(blocks[i]) - 1\n\nprint(*candidates)\n', 'n, m, k = map(int, input().split())\n\ncandidates = [0] * n\nfriends = [set() for _ in range(n)]\nblocks = [set() for _ in range(n)]\nparent = [i for i in range(n)]\nsizes = [1 for _ in range(n)]\n\ndef root(x):\n global parent\n if parent[x] == x:\n return x\n else:\n parent[x] = root(parent[x])\n return parent[x]\n\ndef unite(x, y):\n global parent\n global sizes\n x = root(x)\n y = root(y)\n # print(x, y)\n if x == y:\n return\n parent[x] = y \n sizes[x] += sizes[y]\n sizes[y] = sizes[x]\n\ndef same(x, y):\n return root(x) == root(y)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a - 1].add(b - 1)\n friends[b - 1].add(a - 1)\n unite(a - 1, b - 1)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if same(c - 1, d - 1):\n blocks[c - 1].add(d - 1)\n blocks[d - 1].add(c - 1)\n\nfor i in range(n):\n x = root(i)\n \n s = 0\n candidates[i] = s - len(friends[i]) - len(blocks[i]) - 1\n\nprint(*candidates)\n', 'n, m, k = map(int, input().split())\n\ncandidates = [0] * n\nfriends = [set() for _ in range(n)]\nblocks = [set() for _ in range(n)]\nparent = [i for i in range(n)]\nsizes = [1 for _ in range(n)]\n\ndef root(x):\n global parent\n if parent[x] == x:\n return x\n else:\n parent[x] = root(parent[x])\n return parent[x]\n\ndef unite(x, y):\n global parent\n global sizes\n x = root(x)\n y = root(y)\n if x == y:\n return\n parent[x] = y\n sizes[x] = sizes[x] + sizes[y]\n sizes[y] = sizes[x]\n\ndef same(x, y):\n return root(x) == root(y)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a - 1].add(b - 1)\n friends[b - 1].add(a - 1)\n # unite(a - 1, b - 1)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if same(c - 1, d - 1):\n blocks[c - 1].add(d - 1)\n blocks[d - 1].add(c - 1)\n\nfor i in range(n):\n x = root(i)\n s = sizes[x]\n candidates[i] = s - len(friends[i]) - len(blocks[i]) - 1\n\nprint(*candidates)\n', 'n, m, k = map(int, input().split())\n\ncandidates = [0] * n\nfriends = [set() for _ in range(n)]\nblocks = [set() for _ in range(n)]\nparent = [i for i in range(n)]\nsizes = [1 for _ in range(n)]\n\ndef root(x):\n global parent\n if parent[x] == x:\n return x\n else:\n parent[x] = root(parent[x])\n return parent[x]\n\ndef unite(x, y):\n global parent\n global sizes\n x = root(x)\n y = root(y)\n if x == y:\n return\n # parent[x] = y\n \n \n\ndef same(x, y):\n return root(x) == root(y)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a - 1].add(b - 1)\n friends[b - 1].add(a - 1)\n unite(a - 1, b - 1)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if same(c - 1, d - 1):\n blocks[c - 1].add(d - 1)\n blocks[d - 1].add(c - 1)\n\nfor i in range(n):\n x = root(i)\n s = sizes[x]\n candidates[i] = s - len(friends[i]) - len(blocks[i]) - 1\n\nprint(*candidates)\n', 'import sys\n\nsys.setrecursionlimit(10 ** 9)\n\nclass UnionFind:\n def __init__(self, n):\n self.parents = [i for i in range(n)]\n self.sizes = [1] * n\n\n def find(self, x):\n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n self.parents[y] = x\n self.sizes[x] += self.sizes[y]\n self.sizes[y] = self.sizes[x]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return self.sizes[self.find(x)]\n\n\nn, m, k = map(int, input().split())\nuf = UnionFind(n)\nfriends = [0] * n\nblocks = [0] * n\nfor i in range(m):\n a, b = map(int, input().split())\n friends[a - 1] += 1\n friends[b - 1] += 1\n uf.unite(a - 1, b - 1)\nfor i in range(k):\n c, d = map(int, input().split())\n if uf.same(c - 1, d - 1):\n blocks[c - 1] += 1\n blocks[d - 1] += 1\nans = [0] * n\nfor i in range(n):\n ans[i] = uf.size(i) - friends[i] - blocks[i] - 1\nprint(*ans)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s486679360', 's660307691', 's768618086', 's862416220', 's833277703'] | [80732.0, 80760.0, 68920.0, 68952.0, 41420.0] | [1545.0, 1426.0, 989.0, 1047.0, 1229.0] | [1001, 1054, 999, 1003, 1162] |
p02762 | u004423772 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(2147483647)\ndef dfs(v, seen, overall, connected_components):\n seen[v] = True\n connected_components.add(v)\n for nv in overall[v]:\n if seen[nv] == True:continue\n dfs(nv, seen, overall, connected_components)\ndef main():\n N, M, K = map(int, input().split())\n overall = {}\n friends = {}\n blocks = {}\n for i in range(N):\n overall[i] = set()\n friends[i] = set()\n blocks[i] = set()\n for _ in range(M):\n a, b = map(int, input().split())\n overall[a-1].add(b-1)\n overall[b-1].add(a-1)\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n for _ in range(K):\n c, d = map(int, input().split())\n blocks[c-1].add(d-1)\n blocks[d-1].add(c-1)\n ans = {}\n seen = [False] * N\n for i in range(N):\n if seen[i] == True:continue\n connected_components = set()\n dfs(i, seen, overall, connected_components)\n for v in list(connected_components):\n ans[v] = connected_components - {v}\n for i in range(N):\n print(len(ans[i]-friends[i]-blocks[i]), end=" ")\nif __name__ == "__main__":\n main()', 'import sys\nsys.setrecursionlimit(2147483647)\nN, M, K = map(int, input().split())\ngraph = [[] for _ in range(N)]\nblock = [[] for _ in range(N)]\nconnected_components = []\ncount = 0\ncounts = [0 for _ in range(N)]\nseen = [False for _ in range(N)]\ndef dfs(v, c, seen, origin):\n global count\n seen[v] = True\n for node in graph[v]:\n if seen[node] == True:\n continue\n if node not in block[origin]:\n count += 1\n dfs(node, c+1, seen, origin)\ndef dfs_connected(v, order):\n seen[v] = True', "import sys\nsys.setrecursionlimit(2147483647)\ninput = sys.stdin.readline\n\nN, M, K = map(int, input().split())\nfriends = {i: set() for i in range(N)}\nblocks = {i: set() for i in range(N)}\n\nfor _ in range(M):\n a, b = map(int, input().split())\n friends[a-1].add(b-1)\n friends[b-1].add(a-1)\n\nfor _ in range(K):\n a, b = map(int, input().split())\n blocks[a-1].add(b-1)\n blocks[b-1].add(a-1)\n\ncounts = [0] * N\nseen = [False] * N\ndef dfs(v):\n if seen[v] == True:\n return\n seen[v] = True\n for node in friends[v]:\n c.add(node)\n dfs(node)\n \nfor v in range(N):\n if seen[v] == True:\n continue\n c = set()\n dfs(v)\n l = len(c)\n for i in c:\n counts[i] = l - 1\n counts[i] -= len(c & friends[i])\n counts[i] -= len(c & blocks[i])\nprint(' '.join(map(str, counts)))"] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s157585530', 's387317417', 's167986664'] | [1805052.0, 19156.0, 106984.0] | [2214.0, 77.0, 937.0] | [1193, 531, 833] |
p02762 | u046187684 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["class UnionFind:\n\n def __init__(self, n):\n self.t = [-1] * (n + 1)\n\n def flatten(self):\n for i, _ in enumerate(self.t):\n self.find_root(i)\n\n def union(self, a, b):\n ra = self.find_root(a)\n rb = self.find_root(b)\n if ra != rb:\n self.t[max(ra, rb)] = min(ra, rb)\n\n def find_root(self, x):\n t = []\n while self.t[x] > 0:\n t.append(x)\n x = self.t[x]\n for _t in t:\n self.t[_t] = x\n return x\n\n\ndef solve(string):\n n, m, k, *abcd = map(int, string.split())\n ab, cd = abcd[:2 * m], abcd[2 * m:]\n fr, br = [[] for _ in range(n + 1)], [[] for _ in range(n + 1)]\n uf = UnionFind(n)\n for a, b in zip(*[iter(ab)] * 2):\n fr[a].append(b)\n fr[b].append(a)\n uf.union(a, b)\n uf.flatten()\n for i, v in enumerate(uf.t):\n if v < 0:\n uf.t[i] = i\n mp = {k: i for i, k in enumerate(set(uf.t[1:]))}\n g = [[] for _ in enumerate(mp.keys())]\n for i in range(n + 1):\n if uf.t[i] > 0:\n g[mp[uf.t[i]]].append(i)\n for c, d in zip(*[iter(cd)] * 2):\n br[c].append(d)\n br[d].append(c)\n\n\n\nif __name__ == '__main__':\n import sys\n print(solve(sys.stdin.read().strip()))\n", "class UnionFind:\n\n def __init__(self, n):\n self.t = [-1] * (n + 1)\n\n def flatten(self):\n for i, _ in enumerate(self.t):\n self.find_root(i)\n\n def union(self, a, b):\n ra = self.find_root(a)\n rb = self.find_root(b)\n if ra != rb:\n self.t[max(ra, rb)] = min(ra, rb)\n\n def find_root(self, x):\n t = []\n while self.t[x] > 0:\n t.append(x)\n x = self.t[x]\n for _t in t:\n self.t[_t] = x\n return x\n\n\ndef solve(string):\n n, m, k, *abcd = map(int, string.split())\n ab, cd = abcd[:2 * m], abcd[2 * m:]\n fr, br = [[] for _ in range(n + 1)], [[] for _ in range(n + 1)]\n uf = UnionFind(n)\n for a, b in zip(*[iter(ab)] * 2):\n fr[a].append(b)\n fr[b].append(a)\n uf.union(a, b)\n uf.flatten()\n\nif __name__ == '__main__':\n import sys\n print(solve(sys.stdin.read().strip()))\n", 'class UnionFind:\n\n def __init__(self, n):\n self.t = [-1] * (n + 1)\n\n def flatten(self):\n for i, _ in enumerate(self.t):\n self.find_root(i)\n\n def union(self, a, b):\n ra = self.find_root(a)\n rb = self.find_root(b)\n if ra != rb:\n self.t[max(ra, rb)] = min(ra, rb)\n\n def find_root(self, x):\n t = []\n while self.t[x] > 0:\n t.append(x)\n x = self.t[x]\n for _t in t:\n self.t[_t] = x\n return x\n\n\ndef solve(string):\n n, m, k, *abcd = map(int, string.split())\n r = [1] * (n + 1)\n uf = UnionFind(n)\n for a, b in zip(*[iter(abcd[:2 * m])] * 2):\n r[a] += 1\n r[b] += 1\n uf.union(a, b)\n uf.flatten()\n for i, v in enumerate(uf.t):\n uf.t[i] = i if v < 0 else v\n mp = {k: set([]) for k in set(uf.t[1:])}\n for i, v in enumerate(uf.t[1:], start=1):\n mp[v].add(i)\n for c, d in zip(*[iter(abcd[2 * m:])] * 2):\n r[c] += 1 if d in mp[uf.t[c]] else 0\n r[d] += 1 if c in mp[uf.t[d]] else 0\n mp = {k: len(v) for k, v in mp.items()}\n return " ".join([str(mp[uf.t[i]] - r[i]) for i in range(1, n + 1)])\n\n\nif __name__ == \'__main__\':\n import sys\n print(solve(sys.stdin.read().strip()))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s621818920', 's737533757', 's077330132'] | [70452.0, 49012.0, 70376.0] | [546.0, 449.0, 491.0] | [1271, 924, 1272] |
p02762 | u054556734 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import numpy as np\nimport scipy.sparse as sps\nimport scipy.misc as spm\nimport collections as col\nimport functools as func\nimport itertools as ite\nimport fractions as frac\nimport math as ma\nfrom math import cos,sin,tan,sqrt\nimport cmath as cma\nimport copy as cp\nimport sys\nimport re\nimport bisect as bs\nsys.setrecursionlimit(10**7)\nEPS = sys.float_info.epsilon\nPI = np.pi; EXP = np.e; INF = np.inf\nMOD = 10**9 + 7\n\ndef sinput(): return sys.stdin.readline().strip()\ndef iinput(): return int(sinput())\ndef imap(): return map(int, sinput().split())\ndef fmap(): return map(float, sinput().split())\ndef iarr(n=0):\n if n: return [0 for _ in range(n)]\n else: return list(imap())\ndef farr(): return list(fmap())\ndef sarr(n=0):\n if n: return ["" for _ in range(n)]\n else: return sinput().split()\ndef adj(n): return [[] for _ in range(n)]\n\nclass unionfind:\n def __init__(self, n):\n self.parent = [i for i in range(n)]\n self.size = [1 for i in range(n)]\n def find(self,a):\n if a == self.parent[a]: return a\n else: self.parent[a] = find(self,self.parent[a]); return self.parent[a]\n def unite(self,a,b):\n pa,pb = self.find(self,a), self.find(self,b)\n if pa == pb: return\n else: self.parent[pb] = pa; self.size[pa] += self.size[pb]\n def same(self,a,b): return find(self,a) == find(self,b)\n\n\nn,m,k = imap()\nab = np.array([iarr() for i in range(n)]) -1\n\nuf = unionfind(n)\n\nf = iarr(n)\nfor a,b in ab:\n uf.unite(a,b)\n f[a] += 1; f[b] += 1\n\nng = iarr(n)\nfor i in range(k):\n c,d = imap()\n if uf.same(c,d): ng[c] += 1; ng[d] += 1\n\nanss = []\nfor i in range(n):\n ans = uf.size(i) - f[i] - ng[i] - 1\n anss.append(ans)\nprint(*anss)\n', 'import numpy as np\nimport scipy.sparse as sps\nimport scipy.misc as spm\nimport collections as col\nimport functools as func\nimport itertools as ite\nimport fractions as frac\nimport math as ma\nfrom math import cos,sin,tan,sqrt\nimport cmath as cma\nimport copy as cp\nimport sys\nimport re\nsys.setrecursionlimit(10**7)\nEPS = sys.float_info.epsilon\nPI = np.pi; EXP = np.e; INF = np.inf\nMOD = 10**9 + 7\n\ndef sinput(): return sys.stdin.readline().strip()\ndef iinput(): return int(sinput())\ndef imap(): return map(int, sinput().split())\ndef fmap(): return map(float, sinput().split())\ndef iarr(n=0):\n if n: return [0 for _ in range(n)]\n else: return list(imap())\ndef farr(): return list(fmap())\ndef sarr(n=0):\n if n: return ["" for _ in range(n)]\n else: return sinput().split()\ndef adj(n): return [[] for _ in range(n)]\n\nclass unionfind():\n def __init__(self, n):\n self.n = n\n \n self.parents = [-1] * n\n def find(self, x):\n if self.parents[x] < 0: return x\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n def union(self, x, y):\n x,y = self.find(x), self.find(y)\n if x == y: return\n if self.parents[x] > self.parents[y]: x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n def size(self, x): return -self.parents[self.find(x)]\n def same(self, x, y): return self.find(x) == self.find(y)\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n def roots(self): return [i for i, x in enumerate(self.parents) if x < 0]\n def group_count(self): return len(self.roots())\n\nn,m,k = imap()\nuf = unionfind(n)\nf,ng,anss = iarr(n),iarr(n),iarr(n)\n\nfor i in range(m):\n a,b = imap()\n a,b = a-1,b-1\n f[a] += 1\n f[b] += 1\n uf.union(a,b)\n\nfor i in range(n):\n anss[i] = uf.size(i) - f[i] - 1\n\nfor i in range(k):\n c,d = imap()\n c,d = c-1,d-1\n if uf.same(c,d):\n anss[c] -= 1\n anss[d] -= 1\n\nprint(*anss)\n'] | ['Runtime Error', 'Accepted'] | ['s994115197', 's105570667'] | [57512.0, 47456.0] | [340.0, 722.0] | [1720, 2103] |
p02762 | u070201429 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int, input().split())\n\nfriend = [[] for _ in range(n)]\nblock = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c-1].append(d-1)\n block[d-1].append(c-1)\n\nsize = [0] * n\nseen = [0] * n \ntodo = [] \n\n#DFS\nfor i in range(n):\n if seen[i] == 0:\n element = [] \n seen[i] = 1\n todo.append(i)\n element.append(i)\n while todo != []:\n for j in friend[todo[-1]]:\n if seen[j] == 0:\n seen[j] = 1\n todo.append(j)\n element.append(j)\n break\n else:\n del todo[-1]\n length = len(element)\n for j in element:\n block[j] = [k for k in block[j] if k in element]\n size[j] = length - len(friend[j]) - len(block[j]) - 1\n \n print(size[i])', 'n, m, k = map(int, input().split())\n\nfriend = [[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor _ in range(m):\n a, b = map(int, input().split())\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c-1].append(d-1)\n block[d-1].append(c-1)\n\nans = [0] * n #answer\nseen = [0] * n \ntodo = [] \n\n#DFS\nfor i in range(n):\n if seen[i] == 0:\n element = [] \n seen[i] = 1\n todo.append(i)\n element.append(i)\n size = 0\n\n while todo != []:\n for j in friend[todo[-1]]:\n if seen[j] == 0:\n seen[j] = 1\n todo.append(j)\n element.append(j)\n size += 1\n break\n else:\n del todo[-1]\n\n for j in element:\n bl = 0\n for k in block[j]:\n if k in element:\n bl += 1\n\n #size = len(element) - 1\n ans[j] = size - len(friend[j]) - bl\n \n print(ans[i])', 'n, m, k = map(int, input().split())\n\nfriend = [[] for _ in range(n)]\nblock = [[] for _ in range(n)]\nfor _ in range(m):\n a, b = map(int, input().split())\n friend[a-1].append(b-1)\n friend[b-1].append(a-1)\nfor _ in range(k):\n c, d = map(int, input().split())\n block[c-1].append(d-1)\n block[d-1].append(c-1)\n\nans = [0] * n #answer\nseen = [0] * n \ntodo = [] \n\n#DFS\nfor i in range(n):\n if seen[i] == 0:\n element = [] \n seen[i] = 1\n todo.append(i)\n element.append(i)\n size = 0\n\n while todo != []:\n for j in friend[todo[-1]]:\n if seen[j] == 0:\n seen[j] = 1\n todo.append(j)\n element.append(j)\n size += 1\n break\n else:\n del todo[-1]\n\n for j in element:\n bl = 0\n for k in block[j]:\n if k in element:\n bl += 1\n\n #size = len(element) - 1\n ans[j] = size - len(friend[j]) - bl\n \n print(ans[i])', "\nclass UnionFind():\n # parents\n \n \n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n # find(x)\n \n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n # union(x, y)\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n # same(x, y)\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n # size(x)\n \n def size(self, x):\n return -self.parents[self.find(x)]\n\nimport sys\ndef input():\n return sys.stdin.readline().strip()\n\nn, m, k = map(int, input().split())\nans = [-1 for _ in range(n)]\nuf = UnionFind(n)\n\nfor _ in range(m):\n a, b = map(int, input().split())\n uf.union(a-1, b-1)\n ans[a-1] -= 1\n ans[b-1] -= 1\n\nfor _ in range(k):\n c, d = map(int, input().split())\n if uf.same(c-1, d-1):\n ans[c-1] -= 1\n ans[d-1] -= 1\n\nfor i in range(n):\n ans[i] += uf.size(i)\n\nprint(' '.join(map(str, ans)))"] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s049120545', 's205113483', 's547203336', 's462231920'] | [43312.0, 41368.0, 41456.0, 18004.0] | [2107.0, 2110.0, 2106.0, 821.0] | [1051, 1145, 1145, 1718] |
p02762 | u074372598 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from collections import defaultdict\nclass UnionFind:\n def __init__(self, n=0):\n self.d = [-1 for _ in range(n)]\n \n def find(self, x): # find root\n if self.d[x] < 0: return x\n self.d[x] = self.find(self.d[x])\n return self.d[x]\n\n def unite(self, x, y):\n x, y = self.find(x), self.find(y)\n if x == y: return False\n if -self.d[x] < -self.d[y]: # swap\n t = x\n x = y\n y = t\n self.d[x] += self.d[y]\n self.d[y] = x\n return True\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.d[self.find(x)]\n \n\ndef main():\n N, M, K = map(int, input().split())\n uf = UnionFind(N)\n\n deg = [0 for _ in range(N)]\n for _ in range(M): # friends\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n deg[a] += 1\n deg[b] += 1\n uf.unite(a, b)\n print('----')\n print(uf.d)\n\n\n to = [[] for _ in range(N)]\n for _ in range(K): # block\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n to[c].append(c)\n to[d].append(d)\n\n ret = []\n for i in range(N):\n ans = uf.size(i) - 1 - deg[i]\n for u in to[i]:\n if uf.same(i, u): ans -= 1\n ret.append(str(ans))\n\n print(' '.join(ret))\n\n\nmain()", "from collections import defaultdict\nclass UnionFind:\n def __init__(self, n=0):\n self.d = [-1 for _ in range(n)]\n \n def find(self, x): # find root\n if self.d[x] < 0: return x\n self.d[x] = self.find(self.d[x])\n return self.d[x]\n\n def unite(self, x, y):\n x, y = self.find(x), self.find(y)\n if x == y: return False\n if -self.d[x] < -self.d[y]: # swap\n t = x\n x = y\n y = t\n self.d[x] += self.d[y]\n self.d[y] = x\n return True\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.d[self.find(x)]\n \n\ndef main():\n N, M, K = map(int, input().split())\n uf = UnionFind(N)\n\n deg = [0 for _ in range(N)]\n for _ in range(M): # friends\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n deg[a] += 1\n deg[b] += 1\n uf.unite(a, b)\n \n\n to = [[] for _ in range(N)]\n for _ in range(K): # block\n c, d = map(int, input().split())\n c -= 1\n d -= 1\n to[c].append(d)\n to[d].append(c)\n\n ret = []\n for i in range(N):\n ans = uf.size(i) - 1 - deg[i]\n for u in to[i]:\n if uf.same(i, u): ans -= 1\n ret.append(str(ans))\n\n print(' '.join(ret))\n\n\nmain()"] | ['Wrong Answer', 'Accepted'] | ['s010149327', 's474674221'] | [34492.0, 34016.0] | [1264.0, 1242.0] | [1370, 1353] |
p02762 | u089142196 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['def BFS(x):\n cnt=1\n v=deque([x])\n k=0\n zu[x]=k\n lis=[x]\n \n while len(v)>0:\n a=v.popleft()\n for i in fr[a]:\n if zu[i]==-1:\n zu[i]=zu[a]+1\n v.append(i)\n cnt += 1\n lis.append(i)\n \n return lis\n\n##############################\n\nfrom collections import deque\nN,M,K=map(int,input().split())\nA=[0]*M\nB=[0]*M\nC=[0]*K\nD=[0]*K\nfr=[ [] for _ in range(N)]\nbl=[ set() for _ in range(N)]\nzu=[ -1 for _ in range(N)] \n\nfor i in range(M):\n A[i],B[i]= map(int,input().split())\n fr[A[i]-1].append(B[i]-1)\n fr[B[i]-1].append(A[i]-1)\nfor k in range(K):\n C[k],D[k]= map(int,input().split())\n bl[C[k]-1].add(D[k]-1)\n bl[D[k]-1].add(C[k]-1)\n \nsize=[0]*N\npena=[0]*N\nfor i in range(N):\n if zu[i]==-1:\n kumi=BFS(i) \n \n# for k in range(len(kumi)):\n# size[kumi[k]]=len(kumi)\n# for l in range(len(kumi)):\n# if l==k:\n\n# else:\n# if (kumi[l] in bl[kumi[k]]) or (kumi[l] in fr[kumi[k]]):\n# #print(kumi[k],kumi[l],bl[kumi[k]],fr[kumi[k]])\n\n#print(size)\n#print(pena)\n#ans=[]\n\n# ans.append(size[i]-pena[i]-1)\n#print(*ans)', 'def BFS(x):\n cnt=0\n v=deque([x])\n zu=[ -1 for _ in range(N)] \n k=0\n zu[x]=k\n \n while len(v)>0:\n a=v.popleft()\n for i in fr[a]:\n if zu[i]==-1:\n zu[i]=zu[a]+1\n v.append(i)\n #if zu[i]>1 and (i not in bl[x]):\n cnt +=1 \n return cnt\n\n##############################\n\nfrom collections import deque\nN,M,K=map(int,input().split())\nA=[0]*M\nB=[0]*M\nC=[0]*K\nD=[0]*K\nfr=[ [] for _ in range(N)]\nbl=[ set() for _ in range(N)]\n\nfor i in range(M):\n A[i],B[i]= map(int,input().split())\n fr[A[i]-1].append(B[i]-1)\n fr[B[i]-1].append(A[i]-1)\nfor k in range(K):\n C[k],D[k]= map(int,input().split())\n bl[C[k]-1].add(D[k]-1)\n bl[D[k]-1].add(C[k]-1)\n\nans=[] \nfor i in range(N):\n ans.append(BFS(i))\nprint(*ans)', 'N,M,K=map(int,input().split())\nA=[0]*M\nB=[0]*M\nC=[0]*K\nD=[0]*K\n\nc= [[float("inf") for _ in range(N)] for _ in range(N)]\n\nfor i in range(M):\n A[i],B[i]= map(int,input().split())\n c[A[i]-1][B[i]-1]=0\n c[B[i]-1][A[i]-1]=0\nfor k in range(N):\n c[k][k]=0\n \n#print(c)\n\n\nfor k in range(N):\n for i in range(N):\n for j in range(N):\n c[i][j]=min(c[i][j],c[i][k]+c[k][j])\n \nfor i in range(M):\n c[A[i]-1][B[i]-1]=float("inf")\n c[B[i]-1][A[i]-1]=float("inf")\n \nfor j in range(K):\n C[j],D[j]= map(int,input().split())\n c[C[j]-1][D[j]-1]=float("inf")\n c[D[j]-1][C[j]-1]=float("inf")\n\nimport collections \nfor p in range(N):\n d=collections.Counter(c[p])\n print(d[0]-1)', 'def BFS(x):\n cnt=1\n v=deque([x])\n k=0\n zu[x]=k\n lis=[x]\n \n while len(v)>0:\n a=v.popleft()\n for i in fr[a]:\n if zu[i]==-1:\n zu[i]=zu[a]+1\n v.append(i)\n cnt += 1\n lis.append(i)\n \n return lis\n\n##############################\n\nfrom collections import deque\nN,M,K=map(int,input().split())\nA=[0]*M\nB=[0]*M\nC=[0]*K\nD=[0]*K\nfr=[ [] for _ in range(N)]\nbl=[ set() for _ in range(N)]\nzu=[ -1 for _ in range(N)] \n\nfor i in range(M):\n A[i],B[i]= map(int,input().split())\n fr[A[i]-1].append(B[i]-1)\n fr[B[i]-1].append(A[i]-1)\nfor k in range(K):\n C[k],D[k]= map(int,input().split())\n bl[C[k]-1].add(D[k]-1)\n bl[D[k]-1].add(C[k]-1)\n \nsize=[0]*N\npena=[0]*N\n\nkumi=BFS(0)', 'def BFS(x):\n cnt=1\n v=deque([x])\n k=0\n zu[x]=k\n lis=[x]\n roots[x]=x\n \n while len(v)>0:\n a=v.popleft()\n roots[a]=x\n for i in fr[a]:\n if zu[i]==-1:\n zu[i]=zu[a]+1\n v.append(i)\n cnt += 1\n lis.append(i)\n\n \n return lis\n\n##############################\n\nfrom collections import deque\nN,M,K=map(int,input().split())\nA=[0]*M\nB=[0]*M\nC=[0]*K\nD=[0]*K\nfr=[ [] for _ in range(N)]\nbl=[ set() for _ in range(N)]\nzu=[ -1 for _ in range(N)] \nroots= [ -1 for _ in range(N)]\n\nfor i in range(M):\n A[i],B[i]= map(int,input().split())\n fr[A[i]-1].append(B[i]-1)\n fr[B[i]-1].append(A[i]-1)\nfor k in range(K):\n C[k],D[k]= map(int,input().split())\n bl[C[k]-1].add(D[k]-1)\n bl[D[k]-1].add(C[k]-1)\nfr_set= [set(fr[i]) for i in range(N)]\n \nsize=[0]*N\npena=[0]*N\nfor i in range(N):\n if zu[i]==-1:\n kumi=BFS(i) \n for k in range(len(kumi)):\n size[kumi[k]]=len(kumi)\n \n \nans=[0 for _ in range(N)] \nfor i in range(N):\n ans[i]= size[i]-1 - len(fr[i])\n for j in bl[i]:\n if roots[j]==roots[i]:\n ans[i] -= 1 \n \nprint(*ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s104962091', 's194765257', 's320840086', 's512261748', 's416845631'] | [74004.0, 70568.0, 374688.0, 72276.0, 108104.0] | [1087.0, 2108.0, 2127.0, 1173.0, 1769.0] | [1199, 772, 737, 738, 1134] |
p02762 | u094191970 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from sys import stdin\nnii=lambda: map(int, stdin.readline().split())\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nn,m,k=map(int,input().split())\n\ntree_f=[[] for i in range(n+1)]\ntree_g=[[] for i in range(n+1)]\n\nuf=UnionFind(n+1)\n\nfor i in range(m):\n a,b=nii()\n tree_f[a].append(b)\n tree_f[b].append(a)\n uf.union(a,b)\n\n\n\nfor i in range(k):\n a,b=nii()\n tree_g[a].append(b)\n tree_g[b].append(a)\n\nfor i in range(n):\n i+=1\n sst=list(set(tree_f[i]+tree_g[i]) & set(uf.members(i)))\n cnt=len(sst)\n print(len(uf.members(i))-1-cnt)", 'from sys import stdin\nnii=lambda: map(int, stdin.readline().split())\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\nn,m,k=map(int,input().split())\n\ntree_f=[[] for i in range(n+1)]\ntree_g=[[] for i in range(n+1)]\n\nuf=UnionFind(n+1)\n\nfor i in range(m):\n a,b=nii()\n tree_f[a].append(b)\n tree_f[b].append(a)\n uf.union(a,b)\n\nfor i in range(k):\n a,b=nii()\n if uf.find(a)==uf.find(b):\n tree_g[a].append(b)\n tree_g[b].append(a)\n\nans=[uf.size(i)-len(tree_f[i])-len(tree_g[i])-1 for i in range(1,n+1)]\nprint(*ans)'] | ['Time Limit Exceeded', 'Accepted'] | ['s076681971', 's652618749'] | [51244.0, 46844.0] | [2106.0, 979.0] | [1662, 1077] |
p02762 | u111473084 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['# import numpy as np\nclass UnionFind:\n def __init__(self, n):\n # self.parent = np.array([-1] * n)\n # self.size = np.array([1] * n)\n self.parent = [-1] * n\n self.size = [0] * n\n def find(self, x):\n if self.parent[x] == -1:\n return x\n else:\n a = self.find(self.parent[x])\n self.parent[x] = a\n return a\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.parent[x] = y\n self.size[y] += self.size[x]\n def get_size(self, x):\n return self.size[self.find(x)]\n def printout(self):\n print(self.parent)\n print(self.size)\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nab = [[int(i)-1 for i in input().split()] for j in range(M)]\ncd = [[int(i)-1 for i in input().split()] for j in range(K)]\n\nfor a, b in ab:\n uf.union(a, b)\n\nans =[uf.get_size(i) for i in range(N)]\n\nfor a, b in ab:\n ans[a] -= 1\n ans[b] -= 1\n\nfor c, d in cd:\n if uf.find(c) == uf.find(d):\n ans[c] -= 1\n ans[d] -= 1\n\nprint(*ans)', '# import numpy as np\nclass UnionFind:\n def __init__(self, n):\n # self.parent = np.array([-1] * n)\n # self.size = np.array([1] * n)\n self.parent = [-1] * n\n self.size = [1] * n\n def find(self, x):\n if self.parent[x] == -1:\n return x\n else:\n a = self.find(self.parent[x])\n self.parent[x] = a\n return a\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.parent[x] = y\n self.size[y] += self.size[x]\n def get_size(self, x):\n return self.size[self.find(x)]\n def printout(self):\n print(self.parent)\n print(self.size)\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nab = [[int(i)-1 for i in input().split()] for j in range(M)]\ncd = [[int(i)-1 for i in input().split()] for j in range(K)]\n\nfor a, b in ab:\n uf.union(a, b)\n\nans =[uf.get_size(i)-1 for i in range(N)]\n\n# for a, b in ab:\n# ans[a] -= 1\n# ans[b] -= 1\n\n# for c, d in cd:\n\n# ans[c] -= 1\n# ans[d] -= 1\n\n# print(*ans)', '# import numpy as np\nclass UnionFind:\n def __init__(self, n):\n # self.parent = np.array([-1] * n)\n # self.size = np.array([1] * n)\n self.parent = [-1] * n\n self.size = [1] * n\n def find(self, x):\n if self.parent[x] == -1:\n return x\n else:\n a = self.find(self.parent[x])\n self.parent[x] = a\n return a\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.parent[x] = y\n self.size[y] += self.size[x]\n def get_size(self, x):\n return self.size[self.find(x)]\n def printout(self):\n print(self.parent)\n print(self.size)\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nab = [[int(i)-1 for i in input().split()] for j in range(M)]\ncd = [[int(i)-1 for i in input().split()] for j in range(K)]\n\n# for a, b in ab:\n\n\n\n\n# for a, b in ab:\n# ans[a] -= 1\n# ans[b] -= 1\n\n# for c, d in cd:\n\n# ans[c] -= 1\n# ans[d] -= 1\n\n# print(*ans)', '# import numpy as np\nclass UnionFind:\n def __init__(self, n):\n # self.parent = np.array([-1] * n)\n # self.size = np.array([1] * n)\n self.parent = [-1] * n\n self.size = [1] * n\n def find(self, x):\n if self.parent[x] == -1:\n return x\n else:\n a = self.find(self.parent[x])\n self.parent[x] = a\n return a\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.parent[x] = y\n self.size[y] += self.size[x]\n def get_size(self, x):\n return self.size[self.find(x)]\n def printout(self):\n print(self.parent)\n print(self.size)\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nab = [[int(i)-1 for i in input().split()] for j in range(M)]\ncd = [[int(i)-1 for i in input().split()] for j in range(K)]\n\nfor a, b in ab:\n uf.union(a, b)\n\n\n\n# for a, b in ab:\n# ans[a] -= 1\n# ans[b] -= 1\n\n# for c, d in cd:\n\n# ans[c] -= 1\n# ans[d] -= 1\n\n# print(*ans)', 'import sys \nsys.setrecursionlimit(500*500) \n\nclass UnionFind:\n def __init__(self, n):\n self.parent = [-1] * n\n self.size = [1] * n\n def find(self, x):\n if self.parent[x] == -1:\n return x\n else:\n a = self.find(self.parent[x])\n self.parent[x] = a\n return a\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.parent[x] = y\n self.size[y] += self.size[x]\n def get_size(self, x):\n return self.size[self.find(x)]\n def printout(self):\n print(self.parent)\n print(self.size)\n\nN, M, K = map(int, input().split())\nuf = UnionFind(N)\n\nab = [[int(i)-1 for i in input().split()] for j in range(M)]\ncd = [[int(i)-1 for i in input().split()] for j in range(K)]\n\nfor a, b in ab:\n uf.union(a, b) #RE\n\nans =[uf.get_size(i)-1 for i in range(N)]\n\nfor a, b in ab:\n ans[a] -= 1\n ans[b] -= 1\n\nfor c, d in cd:\n if uf.find(c) == uf.find(d):\n ans[c] -= 1\n ans[d] -= 1\n\nprint(*ans)'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s421845934', 's608193932', 's774894750', 's830424160', 's105793548'] | [44708.0, 45540.0, 40924.0, 43404.0, 75248.0] | [1130.0, 968.0, 649.0, 857.0, 1177.0] | [1108, 1126, 1132, 1128, 1069] |
p02762 | u113971909 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\nclass UnionFind():\n def __init__(self, n): \n self.n = n\n \n self.parents = [i for i in range(n)]\n \n self.ranks = [0] * n\n \n self.sizes = [1] * n\n\n def find(self, x): \n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.ranks[x] < self.ranks[y]:\n self.parents[x] = y\n self.sizes[y] += self.sizes[x]\n else:\n self.parents[y] = x\n self.sizes[x] += self.sizes[y]\n if self.ranks[x]==self.ranks[y]:\n self.ranks[x] += 1\n\n def same(self, x, y): \n return self.find(x) == self.find(y)\n\n def members(self, x): \n root = self.find(x)\n return {i for i in range(self.n) if self.find(i) == root}\n\n def size(self, x): \n root = self.find(x)\n return self.sizes[root]\n\n def roots(self): \n return {i for i, x in enumerate(self.parents) if i == x}\n\n def group_count(self): \n return len(self.roots())\n\n def all_group_members(self): \n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\n\n################\n\ndef main():\n N, M, K = map(int, input().split())\n uf = UnionFind(N)\n dic = {i:set([i]) for i in range(N)}\n\n for i in range(M):\n a,b = map(int,input().split())\n uf.unite(a-1, b-1)\n dic[a-1].add(b-1)\n dic[b-1].add(a-1)\n\n for j in range(K):\n a,b = map(int,input().split())\n dic[a-1].add(b-1)\n dic[b-1].add(a-1)\n\n ret = [None]*N\n for i in range(N):\n cnt = 0\n print(uf.members(i))\n for x in uf.members(i):\n cnt += not x in dic[i]\n ret[i]=cnt\n print(" ".join(map(str,ret)))\n\nif __name__ == \'__main__\':\n main()', '#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\nclass UnionFind():\n def __init__(self, n): \n self.n = n\n \n self.parents = [i for i in range(n)]\n \n self.ranks = [0] * n\n \n self.sizes = [1] * n\n\n def find(self, x): \n if self.parents[x] == x:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.ranks[x] < self.ranks[y]:\n self.parents[x] = y\n self.sizes[y] += self.sizes[x]\n else:\n self.parents[y] = x\n self.sizes[x] += self.sizes[y]\n if self.ranks[x]==self.ranks[y]:\n self.ranks[x] += 1\n\n def same(self, x, y): \n return self.find(x) == self.find(y)\n\n def members(self, x): \n root = self.find(x)\n return {i for i in range(self.n) if self.find(i) == root}\n\n def size(self, x): \n root = self.find(x)\n return self.sizes[root]\n\n def roots(self): \n return {i for i, x in enumerate(self.parents) if i == x}\n\n def group_count(self): \n return len(self.roots())\n\n def all_group_members(self): \n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\n\n################\n\ndef main():\n N, M, K = map(int, input().split())\n uf = UnionFind(N)\n dic = {i:set([i]) for i in range(N)}\n fcnt = {i:0 for i in range(N)}\n\n for i in range(M):\n a,b = map(int,input().split())\n uf.unite(a-1, b-1)\n fcnt[a-1] += 1\n fcnt[b-1] += 1\n\n for j in range(K):\n a,b = map(int,input().split())\n dic[a-1].add(b-1)\n dic[b-1].add(a-1)\n\n ret = [None]*N\n for i in range(N):\n ret[i] = uf.size(i)-fcnt[i]\n for x in dic[i]:\n if uf.same(x,i):\n ret[i] -= 1\n\n print(" ".join(map(str,ret)))\n\nif __name__ == \'__main__\':\n main()'] | ['Wrong Answer', 'Accepted'] | ['s389268013', 's541743654'] | [84020.0, 69360.0] | [2108.0, 1496.0] | [2391, 2466] |
p02762 | u149752754 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind():\n def __init__(self,size): \n self.table = [-1 for _ in range(size)]\n self.cou = [1 for _ in range(size)]\n def find(self,x): \n if self.table[x] < 0:\n return x\n else:\n self.table[x] = self.find(self.table[x])\n return self.table[x]\n def union(self,x,y): \n s1 = self.find(x)\n s2 = self.find(y)\n if s1 != s2:\n if self.table[s1] > self.table[s2]:\n self.table[s1] = s2\n self.cou[s2] += self.cou[s1]\n self.cou[s1] = 0\n elif self.table[s2] > self.table[s1]:\n self.table[s2] = s1\n self.cou[s1] += self.cou[s2]\n self.cou[s2] = 0\n else:\n self.table[s2] = s1\n self.table[s1] -= 1\n self.cou[s1] += self.cou[s2]\n self.cou[s2] = 0\n return\n \nn, m, k = map(int, input().split())\nBList = [[] for _ in range(n)]\nfriendU = UnionFind(n)\nfor i in range(m):\n a, b = map(int, input().split())\n BList[a-1].append(b-1)\n BList[b-1].append(a-1)\n friendU.union(a-1, b-1)\n\nfor i in range(k):\n c, d = map(int, input().split())\n if friendU.find(c-1) != friendU.find(d-1):\n BList[c-1].append(d-1)\n BList[d-1].append(c-1)\n \nansl = []\nfor i in range(n):\n j = friendU.find(i)\n ans = friendU.cou[j] - len(BList[i]) - 1\n ansl.append(ans)\n\nprint(*ansl)', 'class UnionFind():\n \n def __init__(self,size): \n self.table = [-1 for _ in range(size)]\n self.cou = [1 for _ in range(size)]\n \n def find(self,x): \n if self.table[x] < 0:\n return x\n else:\n self.table[x] = self.find(self.table[x])\n return self.table[x]\n \n def union(self,x,y): \n s1 = self.find(x)\n s2 = self.find(y)\n if s1 != s2:\n if self.table[s1] > self.table[s2]:\n self.table[s1] = s2\n self.cou[s2] += self.cou[s1]\n self.cou[s1] = 0\n elif self.table[s2] > self.table[s1]:\n self.table[s2] = s1\n self.cou[s1] += self.cou[s2]\n self.cou[s2] = 0\n else:\n self.table[s2] = s1\n self.table[s1] -= 1\n self.cou[s1] += self.cou[s2]\n self.cou[s2] = 0\n return\n \nn, m, k = map(int, input().split())\nBList = [[] for _ in range(n)]\nfriendU = UnionFind(n)\n\nfor i in range(m):\n a, b = map(int, input().split())\n BList[a-1].append(b-1)\n BList[b-1].append(a-1)\n friendU.union(a-1, b-1)\n\nfor i in range(k):\n c, d = map(int, input().split())\n if friendU.find(c-1) == friendU.find(d-1):\n BList[c-1].append(d-1)\n BList[d-1].append(c-1)\n \nansl = []\nfor i in range(n):\n j = friendU.find(i)\n ans = friendU.cou[j] - len(BList[i]) - 1\n ansl.append(ans)\n\nprint(*ansl)'] | ['Wrong Answer', 'Accepted'] | ['s027823983', 's043489704'] | [33104.0, 40376.0] | [1256.0, 1321.0] | [1458, 1482] |
p02762 | u169501420 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["# -*- coding: utf-8 -*-\n\n#def find_friend(tree_node, target):\n# for friend in tree_node.friends:\n# if target in friend.friend_numbers:\n# return True\n#\n# flags = []\n# for friend in tree_node.friends:\n# flags.append(find_friend(friend, target))\n# if True in flags:\n# return True\n# return False\n\ndef display(node):\n print('----')\n print('val: {}'.format(node.val))\n print('friend_numbers: {}'.format(node.friend_numbers))\n print('block_numbers: {}'.format(node.block_numbers))\n\ndef find_friend(root, target):\n queue = [root]\n already_list = [root.val]\n while len(queue) > 0:\n node = queue.pop(0)\n if target in node.friend_numbers:\n return True\n \n for friend in node.friends:\n if friend.val not in already_list:\n queue.append(friend)\n already_list.append(friend.val)\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.friends = []\n self.friend_numbers = []\n self.blocks = []\n self.block_numbers = []\n self.candidate = []\n\n[N, M, K] = [int(i) for i in input().split()]\n\nAB = []\nfor m in range(M):\n [a, b] = [int(i) for i in input().split()]\n AB.append((a, b))\n\nCD = []\nfor k in range(K):\n [c, d] = [int(i) for i in input().split()]\n CD.append((c, d))\n\ntree_nodes = {}\nfor i in range(1, N + 1):\n tree_node = TreeNode(i)\n tree_nodes[i] = tree_node\n\nfor (a, b) in AB:\n tree_nodes[a].friends.append(tree_nodes[b])\n tree_nodes[a].friend_numbers.append(b)\n tree_nodes[b].friends.append(tree_nodes[a])\n tree_nodes[b].friend_numbers.append(a)\n\nfor (c, d) in CD:\n tree_nodes[c].blocks.append(tree_nodes[d])\n tree_nodes[c].block_numbers.append(d)\n tree_nodes[d].blocks.append(tree_nodes[c])\n tree_nodes[d].block_numbers.append(c)\n\nfor k, v in tree_nodes.items():\n display(v)\n\ncandidates = []\nfor k, v in tree_nodes.items():\n \n candidate = 0\n for n in range(1, N + 1):\n if n == k:\n continue\n if n in v.friend_numbers:\n continue\n if n in v.block_numbers:\n continue\n\n \n flag = find_friend(v, n)\n if flag:\n candidate += 1\n print('{}の友達候補{}: {}'.format(k, n, flag))\n \n candidates.append(candidate)\n\nans = ''\nfor candidate in candidates:\n ans += str(candidate)\n ans += ' '\n\nprint(ans[:len(ans)-1])", "# -*- coding: utf-8 -*-\n\nclass UnionFindTree():\n def __init__(self, n):\n self.parent = [] \n self.rank = [] \n self.number = [] \n for i in range(n):\n self.parent.append(i)\n self.rank.append(0)\n self.number.append(1)\n\n \n def find(self, x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n\n \n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n \n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n self.number[y] += self.number[x]\n else:\n self.parent[y] = x\n self.number[x] += self.number[y]\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n \n def union_number(self, x):\n x = self.find(x)\n return self.number[x]\n\n[N, M, K] = [int(i) for i in input().split()]\n\nAB = []\nfor m in range(M):\n [a, b] = [int(i) for i in input().split()]\n AB.append((a, b))\n\nCD = []\nfor k in range(K):\n [c, d] = [int(i) for i in input().split()]\n CD.append((c, d))\n\nuf_tree = UnionFindTree(N)\nfor (a, b) in AB:\n a -= 1\n b -= 1\n uf_tree.unite(a, b)\n\n\ncandidates = []\nfor n in range(N):\n candidates.append(uf_tree.union_number(n) - 1)\n\n\nfor (a, b) in AB:\n a -= 1\n b -= 1\n candidates[a] -= 1\n candidates[b] -= 1\n\n\nfor (c, d) in CD:\n c -= 1\n d -= 1\n if uf_tree.same(c, d):\n candidates[c] -= 1\n candidates[d] -= 1\n\nans = ''\nfor candidate in candidates:\n ans += str(candidate) + ' '\n\nprint(ans[:len(ans) - 1])"] | ['Wrong Answer', 'Accepted'] | ['s183297516', 's099756017'] | [125932.0, 41904.0] | [2111.0, 1207.0] | [2532, 1999] |
p02762 | u185325486 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["from collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n\ndef check():\n N,M,K = map(int, input().split())\n uf = UnionFind(N)\n friend = defaultdict(int)\n block = defaultdict(int)\n \n for _ in range(M):\n a,b = map(int, input().split())\n friend[a-1] += 1\n friend[b-1] += 1\n uf.union(a-1,b-1)\n \n for _ in range(K):\n a,b = map(int, input().split())\n if uf.same(a-1,b-1):\n block[a-1] += 1\n block[b-1] += 1\n \n result = [uf.size(i) - friend[i] - block[i] - 1 for i in range(N)]\n print(' '.join(map(str, result)))", "from collections import defaultdict\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n \n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n\n\nN,M,K = map(int, input().split())\nuf = UnionFind(N)\nfriend = defaultdict(int)\nblock = defaultdict(int)\n\nfor _ in range(M):\n a,b = map(int, input().split())\n friend[a-1] += 1\n friend[b-1] += 1\n uf.union(a-1,b-1)\n\nfor _ in range(K):\n a,b = map(int, input().split())\n if uf.same(a-1,b-1):\n block[a-1] += 1\n block[b-1] += 1\n\nresult = [uf.size(i) - friend[i] - block[i] - 1 for i in range(N)]\nprint(' '.join(map(str, result)))"] | ['Wrong Answer', 'Accepted'] | ['s525195819', 's634182435'] | [3316.0, 36792.0] | [21.0, 1307.0] | [1271, 1183] |
p02762 | u187516587 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\nN,M,K=map(int,input().split())\ns=[[]for i in range(N)]\ntn=[0]*N\nsys.setrecursionlimit(200000)\nfor i in range(M):\n a,b=map(int,input().split())\n s[a-1].append(b)\n s[b-1].append(a)\n tn[a-1]+=1\n tn[b-1]+=1\nl=[None]*N\ndef hu(n,t):\n for i in s[n]:\n if l[i-1]==None:\n l[i-1]=t\n hu(i-1,t)\nt=0\nfor i in range(N):\n if l[i]==None:\n hu(i,t)\n t+=1\nc=[0]*t\nfor i in l:\n c[i]+=1\nfor i in range(K):\n a,b=map(int,input().split())\n if l[a-1]==l[b-1]:\n tn[a-1]+=1\n tn[b-1]+=1\nfor i in range(N):\n print(c[l[i]]-tn[i]-1,end=" ")', 'import sys\nN,M,K=map(int,input().split())\ns=[[]for i in range(N)]\ntn=[0]*N\nsys.setrecursionlimit(2000000)\nfor i in range(M):\n a,b=map(int,input().split())\n s[a-1].append(b)\n s[b-1].append(a)\n tn[a-1]+=1\n tn[b-1]+=1\nl=[None]*N\ndef hu(n,t):\n for i in s[n]:\n if l[i-1]==None:\n l[i-1]=t\n hu(i-1,t)\nt=0\nfor i in range(N):\n if l[i]==None:\n hu(i,t)\n t+=1\nc=[0]*t\nfor i in l:\n c[i]+=1\nfor i in range(K):\n a,b=map(int,input().split())\n if l[a-1]==l[b-1]:\n tn[a-1]+=1\n tn[b-1]+=1\nfor i in range(N):\n print(c[l[i]]-tn[i]-1,end=" ")', 'import sys\nN,M,K=map(int,input().split())\ntn=[0]*N\nl=[i for i in range(N)]\nfor i in range(M):\n A,B=map(lambda x:int(x)-1,input().split())\n t=B\n tn[A]+=1\n tn[B]+=1\n while 1:\n if l[t]==t:\n l[t]=l[A]\n break\n l[t],t=l[A],l[t]\nln=[0]*N\nfor i in range(N):\n if l[i]!=i:\n c=[i]\n t=l[i]\n while 1:\n if l[t]==t:\n for j in c:\n l[j]=t\n break\n t=l[t]\n ln[t]+=1\n else:\n ln[i]+=1\nfor i in range(K):\n C,D=map(lambda x: int(x)-1,input().split())\n if l[C]==l[D]:\n tn[C]+=1\n tn[D]+=1\nfor i in range(N):\n print(ln[l[i]]-tn[i]-1,end=" ")\n', 'import sys\ndef input():\n return sys.stdin.readline()[:-1]\nsys.setrecursionlimit(200000)\nclass uf:\n def __init__(self,n):\n self.n=n\n self.l=[-1]*n\n def ro(self,n):\n if self.l[n]<0:\n return n\n r=self.ro(self.l[n])\n self.l[n]=r\n return r\n def me(self,a,b):\n ra=self.ro(a)\n rb=self.ro(b)\n if self.l[ra]>self.l[rb]:\n ra,rb=rb,ra\n if ra!=rb:\n self.l[ra]+=self.l[rb]\n self.l[rb]=ra\n def size(self,n):\n return -self.l[self.ro(n)]\n def sa(self,a,b):\n return self.ro(a)==self.ro(b)\nN,M,K=map(int,input().split())\nu=uf(N)\nl=[-1]*N\nfor i in range(M):\n A,B=map(lambda x: int(x)-1,input().split())\n u.me(A,B)\n l[A]-=1\n l[B]-=1\nfor i in range(N):\n l[i]+=u.size(i)\nfor i in range(K):\n C,D=map(lambda x: int(x)-1,input().split())\n if u.sa(C,D):\n l[C]-=1\n l[D]-=1\nprint(*l)'] | ['Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s190604772', 's351181635', 's976840811', 's937856328'] | [46528.0, 46528.0, 9392.0, 13340.0] | [1064.0, 1055.0, 2104.0, 853.0] | [609, 610, 702, 936] |
p02762 | u196746947 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import queue\nimport numpy\ndef main():\n n,m,k=map(int,input().split())\n root=numpy.array([numpy.zeros(n) for i in range(n)])\n for i in range(n):\n root[i][i]=2\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1][b-1]=1\n root[b-1][a-1]=1\n for i in range(k):\n a,b=map(int,input().split())\n root[a-1][b-1]=-100\n root[b-1][a-1]=-100\n toVis=queue.Queue()\n Visted=[]\n checkOK=numpy.zeros(n)\n OK={}\n checkVis=numpy.zeros(n)\n checkVinit=numpy.zeros(n)\n for i in range(n):\n if checkOK[i]==5:\n continue\n print(i)\n checkVis=checkVinit\n Visted=[i]\n checkVis[i]=5\n toVis=queue.Queue()\n \n for j in range(len(root[i])):\n nex=root[i][j] \n if checkVis[j]!=5 and nex==1:\n toVis.put(j)\n\n while toVis.empty()==False:\n \n now=toVis.get()\n\n if checkVis[now]==5:\n continue\n\n Visted.append(now)\n checkVis[now]=5\n for j in range(n):#len(root[now]\n nex=root[now][j]\n if nex==1 and checkVis[j]!=5:\n toVis.put(j)\n \n for j in Visted:\n OK[j]=Visted\n checkOK[j]=5\n print(1," ",1," ",1)\n \nif __name__=="__main__":\n main()\n', "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\n\nn,m,k=map(int,input().split())\nuf=UnionFind(n)\nblock={}\nfor i in range(n):\n block[i]=[i]\nfor i in range(m):\n a,b=map(int,input().split())\n uf.union(a-1,b-1)\n block[a-1].append(b-1)\n block[b-1].append(a-1)\n \nfor i in range(k):\n a,b=map(int,input().split())\n block[a-1].append(b-1)\n block[b-1].append(a-1)\nans=[]\nprint(block)\nfor i in range(n):\n res=uf.size(i)\n print(res)\n for value in block[i]:\n if uf.same(value,i):\n res-=1\n ans.append(res)\nprint(*ans)", 'import queue\nimport sys\nimport numpy\ninput = sys.stdin.readline\n\ndef main():\n n,m,k=map(int,input().split())\n root=numpy.array([numpy.zeros(n) for i in range(n)])\n for i in range(n):\n root[i][i]=2\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1][b-1]=1\n root[b-1][a-1]=1\n for i in range(k):\n a,b=map(int,input().split())\n root[a-1][b-1]=-100\n root[b-1][a-1]=-100\n toVis=queue.Queue()\n Visted=[]\n checkOK=numpy.zeros(n)\n OK={}\n checkVis=numpy.zeros(n)\n checkVinit=numpy.zeros(n)\n for i in range(n):\n if checkOK[i]==5:\n continue\n print(i)\n checkVis=checkVinit\n Visted=[i]\n checkVis[i]=5\n toVis=queue.Queue()\n \n for j in range(len(root[i])):\n nex=root[i][j] \n if checkVis[j]!=5 and nex==1:\n toVis.put(j)\n\n while toVis.empty()==False:\n \n now=toVis.get()\n\n if checkVis[now]==5:\n continue\n\n Visted.append(now)\n checkVis[now]=5\n for j in range(n):#len(root[now]\n nex=root[now][j]\n if nex==1 and checkVis[j]!=5:\n toVis.put(j)\n \n for j in Visted:\n OK[j]=Visted\n checkOK[j]=5\n \n ans=[]\n for i in range(n):\n num=0\n for value in OK[i]:\n if root[i][value]==0:\n num+=1\n ans.append(num)\n print(" ".join(map(str,ans)))\nif __name__=="__main__":\n main()\n\n \n ', 'import queue\ndef main():\n n,m,k=map(int,input().split())\n root={}\n ng={}\n for i in range(n):\n root[i]=[]\n ng[i]=[i]\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1].append(b-1)\n root[b-1].append(a-1)\n for i in range(k):\n a,b=map(int,input().split())\n ng[a-1].append(b-1)\n ng[b-1].append(a-1)\n \n Vstd=[]\n checkVst=[0]*n\n num=[0]*n\n ToVst=queue.Queue()\n for i in range(n):\n Vstd=[]\n if checkVst[i]==1:\n continue\n now=i\n Vstd.append(now)\n checkVst[now]=1\n for kouho in root[now]:\n if checkVst[kouho]!=1:\n ToVst.put(kouho)\n checkVst[kouho]=1\n while ToVst.empty()==False:\n now=ToVst.get()\n Vstd.append(now)\n checkVst[now]=1\n for kouho in root[now]:\n if checkVst[kouho]==1:\n continue\n ToVst.put(kouho)\n checkVst[kouho]=1\n # print("a")\n\n # print(Vstd)\n for x in Vstd:\n num[x]=len(Vstd)\n for y in Vstd:\n if y in ng[x] or y in root[x]:\n num[x]-=1\n print(" ".join(map(str,num)))\n ', 'import queue\nimport numpy\ndef main():\n n,m,k=map(int,input().split())\n root=numpy.array([[0]*n for i in range(n)])\n for i in range(n):\n root[i][i]=2\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1][b-1]=1\n root[b-1][a-1]=1\n for i in range(k):\n a,b=map(int,input().split())\n root[a-1][b-1]=-100\n root[b-1][a-1]=-100\n toVis=queue.Queue()\n Visted=[]\n checkOK=numpy.zeros(n)\n OK={}\n checkVis=numpy.zeros(n)\n checkVinit=numpy.zeros(n)\n for i in range(n):\n if checkOK[i]==5:\n continue\n checkVis=checkVinit\n Visted=[i]\n checkVis[i]=5\n toVis=queue.Queue()\n \n for j in range(len(root[i])):\n nex=root[i][j]\n if checkVis[j]!=5 and nex==1:\n toVis.put(j)\n\n while toVis.empty()==False:\n \n now=toVis.get()\n\n if checkVis[now]==5:\n continue\n\n Visted.append(now)\n checkVis[now]=5\n for j in range(n):#len(rooot[now]\n nex=root[now][j]\n if nex==1 and checkVis[j]!=5:\n toVis.put(j)\n \n for j in Visted:\n OK[j]=Visted\n checkOK[j]=5\n ans=[]\n for i in range(n):\n num=0\n """ for value in OK[i]:\n if root[i][value]==0:\n num+=1"""\n ans.append(num)\n print(" ".join(map(str,ans)))\nif __name__=="__main__":\n main()\n', 'import queue\nimport numpy\ndef main():\n n,m,k=map(int,input().split())\n root=numpy.array([numpy.zeros(n) for i in range(n)])\n for i in range(n):\n root[i][i]=2\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1][b-1]=1\n root[b-1][a-1]=1\n for i in range(k):\n a,b=map(int,input().split())\n root[a-1][b-1]=-100\n root[b-1][a-1]=-100\n toVis=queue.Queue()\n Visted=[]\n checkOK=numpy.zeros(n)\n OK={}\n checkVis=numpy.zeros(n)\n checkVinit=numpy.zeros(n)\n for i in range(n):\n if checkOK[i]==5:\n continue\n print(i)\n checkVis=checkVinit\n Visted=[i]\n checkVis[i]=5\n toVis=queue.Queue()\n \n for j in range(len(root[i])):\n nex=root[i][j] \n if checkVis[j]!=5 and nex==1:\n toVis.put(j)\n\n while toVis.empty()==False:\n \n now=toVis.get()\n\n if checkVis[now]==5:\n continue\n\n Visted.append(now)\n checkVis[now]=5\n for j in range(n):#len(root[now]\n nex=root[now][j]\n if nex==1 and checkVis[j]!=5:\n toVis.put(j)\n \n for j in Visted:\n OK[j]=Visted\n checkOK[j]=5\n print(1 1 1 1 1)\n \nif __name__=="__main__":\n main()\n', 'import queue\nimport numpy\ndef main():\n n,m,k=map(int,input().split())\n root=numpy.array([[0]*n for i in range(n)])\n for i in range(n):\n root[i][i]=2\n for i in range(m):\n a,b=map(int,input().split())\n root[a-1][b-1]=1\n root[b-1][a-1]=1\n for i in range(k):\n a,b=map(int,input().split())\n root[a-1][b-1]=-100\n root[b-1][a-1]=-100\n toVis=queue.Queue()\n Visted=[]\n checkOK=numpy.zeros(n)\n OK={}\n checkVis=numpy.zeros(n)\n checkVinit=numpy.zeros(n)\n for i in range(n):\n if checkOK[i]==5:\n continue\n checkVis=checkVinit\n Visted=[i]\n checkVis[i]=5\n toVis=queue.Queue()\n \n for j in range(len(root[i])):\n nex=root[i][j]\n if checkVis[j]!=5 and nex==1:\n toVis.put(j)\n\n while toVis.empty()==False:\n \n now=toVis.get()\n\n if checkVis[now]==5:\n continue\n\n Visted.append(now)\n checkVis[now]=5\n for j in range(n):#len(rooot[now]\n nex=root[now][j]\n if nex==1 and checkVis[j]!=5:\n toVis.put(j)\n \n for j in Visted:\n OK[j]=Visted\n checkOK[j]=5\n ans=[]\n for i in range(n):\n num=0\n """ for value in OK[i]:\n if root[i][value]==0:\n num+=1\n ans.append(num)"""\n print(" ".join(map(str,ans)))\nif __name__=="__main__":\n main()\n', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return \'\\n\'.join(\'{}: {}\'.format(r, self.members(r)) for r in self.roots())\ndef main():\n\n n,m,k=map(int,input().split())\n uf=UnionFind(n)\n block={}\n for i in range(n):\n block[i]=[i]\n for i in range(m):\n a,b=map(int,input().split())\n uf.union(a-1,b-1)\n block[a-1].append(b-1)\n block[b-1].append(a-1)\n \n for i in range(k):\n a,b=map(int,input().split())\n block[a-1].append(b-1)\n block[b-1].append(a-1)\n ans=[]\n #print(block)\n for i in range(n):\n res=uf.size(i)\n # print(res)\n for value in block[i]:\n if uf.same(value,i):\n res-=1\n ans.append(res)\n print(*ans)\n \n \nif __name__=="__main__":\n main()\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s118618533', 's311490367', 's406292489', 's542812479', 's585887121', 's838833356', 's995759534', 's285237366'] | [1901824.0, 58824.0, 1901840.0, 4080.0, 3064.0, 3064.0, 3188.0, 49072.0] | [2456.0, 2106.0, 2358.0, 29.0, 20.0, 17.0, 19.0, 1693.0] | [2515, 1658, 2537, 1272, 1660, 2511, 1660, 1825] |
p02762 | u210827208 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['def find(x):\n if par[x]<0:\n return x\n else:\n par[x]=find(par[x])\n return par[x]\n\ndef unite(x,y):\n x,y=find(x),find(y)\n if x!=y:\n if x>y:\n x,y=y,x\n par[x]+=par[y]\n par[y]=x\n \ndef same(x,y):\n return find(x)==find(y)\n\ndef size(x):\n return-par[find(x)]\n \nn,m,k=map(int,input().split())\n\npar=[-1]*n\n\nF=[]\nB=[]\n\nf=[set() for _ in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n F.append([a,b])\n \nfor i in range(k):\n c,d=map(int,input().split())\n B.append([c,d])\n\nfor a,b in F:\n a-=1\n b-=1\n unite(a,b)\n f[a].add(b)\n f[b].add[a]\n\na=[size(i)-len(f[i])-1 for i in range(n)]\n\nfor c,d in B:\n c-=1\n d-=1\n if same(c,d):\n a[c]-=1\n a[d]-=1\nprint(*a)', 'def find(x):\n if par[x]<0:\n return x\n else:\n par[x]=find(par[x])\n return par[x]\n\ndef unite(x,y):\n x,y=find(x),find(y)\n if x!=y:\n if x>y:\n x,y=y,x\n par[x]+=par[y]\n par[y]=x\n \ndef same(x,y):\n return find(x)==find(y)\n\ndef size(x):\n return-par[find(x)]\n \nn,m,k=map(int,input().split())\n\npar=[-1]*n\n\nF=[]\nB=[]\n\nf=[set() for _ in range(n)]\n\nfor i in range(m):\n a,b=map(int,input().split())\n F.append([a,b])\n \nfor i in range(k):\n c,d=map(int,input().split())\n B.append([c,d])\n\nfor a,b in F:\n a-=1\n b-=1\n unite(a,b)\n f[a].add(b)\n f[b].add(a)\n\na=[size(i)-len(f[i])-1 for i in range(n)]\n\nfor c,d in B:\n c-=1\n d-=1\n if same(c,d):\n a[c]-=1\n a[d]-=1\nprint(*a)\n'] | ['Runtime Error', 'Accepted'] | ['s957046051', 's603240280'] | [60008.0, 76756.0] | [789.0, 1262.0] | [750, 751] |
p02762 | u212786022 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind(object):\n def __init__(self, n=0):\n self.par = [i for i in range(n)]\n self.rank = [-1 for _ in range(n)]\n \n def find(self, x):\n if self.rank[x] < 0:\n return x\n else:\n self.rank[x] = self.find(self.rank[x])\n return self.rank[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if abs(x) < abs(y):\n x, y = y, x\n self.rank[x] += self.rank[y]\n self.rank[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\nn,m,k=map(int, input().split())\nuf=UnionFind(n)\nfriend = [0]*n\nfor i in range(m):\n a,b=map(int, input().split())\n friend[a-1] +=1\n friend[b-1] +=1\n uf.union(a-1,b-1)\n\nblock = [[] for _ in range(n)]\nfor i in range(k):\n x,y=map(int, input().split())\n block[x-1].append(y-1)\n block[y-1].append(x-1)\n\nans = [0]*n\nfor i in range(n):\n ans[i] = uf.size(i)-1-friend[i]\n for j in block[i]:\n if uf.same(i,j):\n ans[i] -= 1\n ans[i] = str(ans[i])\n \nprint(" ".join(ans))', 'class UnionFind(object):\n def __init__(self, n=0):\n self.par = [i for i in range(n)]\n self.rank = [-1 for _ in range(n)] \n\n def find(self, x):\n if self.rank[x] < 0:\n return x\n else:\n self.rank[x] = self.find(self.rank[x])\n return self.rank[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return 0\n\n if abs(x) < abs(y): \n x, y = y, x \n self.rank[x] += self.rank[y]\n self.rank[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.rank[self.find(x)]\n\nn,m,k=map(int, input().split())\nuf=UnionFind(n)\nfriend = [0]*n\nfor i in range(m):\n a,b=map(int, input().split())\n friend[a-1] +=1\n friend[b-1] +=1\n uf.union(a-1,b-1)\n\nblock = [[] for _ in range(n)]\nfor i in range(k):\n x,y=map(int, input().split())\n block[x-1].append(y-1)\n block[y-1].append(x-1)\n\nans = [0]*n\nfor i in range(n):\n ans[i] = uf.size(i)-1-friend[i]\n for j in block[i]:\n if uf.same(i,j):\n ans[i] -= 1\n ans[i] = str(ans[i])\n \nprint(" ".join(ans))'] | ['Runtime Error', 'Accepted'] | ['s745710014', 's524812235'] | [27824.0, 35052.0] | [898.0, 1376.0] | [1089, 1192] |
p02762 | u250583425 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import sys\nfrom collections import defaultdict\ndef input(): return sys.stdin.readline().rstrip()\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n + 1\n self.parents = [-1] * (n + 1)\n self.mem = [[] for _ in range(n+1)]\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.parents[self.find(x)]\n \n def members(self, x):\n root = self.find(x)\n if not self.mem[root]:\n self.mem[root] = [i for i in range(1, self.n) if self.find(i) == root]\n return self.mem[root]\n\ndef main():\n N, M, K = map(int, input().split())\n friend_or_block = [set() for _ in range(N+1)]\n friendsGroup = UnionFind(N)\n for _ in range(M):\n a, b = map(int, input().split())\n friendsGroup.union(a, b)\n friend_or_block[a].add(b)\n friend_or_block[b].add(a)\n\n for _ in range(K):\n c, d = map(int, input().split())\n friend_or_block[c].add(d)\n friend_or_block[d].add(c)\n\n memo = defaultdict(int)\n ans = [0] * (N + 1)\n for i in range(1, N+1):\n root = friendsGroup.find(i)\n if memo[root] == 0:\n memo[root] = len([v for v in friendsGroup.members(i) if v not in friend_or_block[i]]) - 1\n ans[i] = memo[root]\n print(*ans[1:])\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom collections import defaultdict\ndef input(): return sys.stdin.readline().rstrip()\n\nclass UnionFind:\n def __init__(self, n):\n self.parents = [-1] * (n + 1)\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.parents[self.find(x)]\n\ndef main():\n N, M, K = map(int, input().split())\n\n friends = defaultdict(lambda : 1)\n friendsGroup = UnionFind(N)\n for _ in range(M):\n a, b = map(int, input().split())\n friendsGroup.union(a, b)\n friends[a] += 1\n friends[b] += 1\n\n blocks = defaultdict(int)\n for _ in range(K):\n c, d = map(int, input().split())\n if friendsGroup.same(c, d):\n blocks[c] += 1\n blocks[d] += 1\n\n ans = [friendsGroup.size(i) - friends[i] - blocks[i] for i in range(1, N+1)]\n print(*ans)\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s080239171', 's829580962'] | [69492.0, 32372.0] | [2108.0, 859.0] | [1805, 1359] |
p02762 | u255382385 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['n, m, k = map(int, input().split())\nfriends = [[] * n for i in range(n)]\nfor _ in range(m):\n num_from, num_to = map(int, input().split())\n friends[num_from - 1].append(num_to - 1)\n friends[num_to - 1].append(num_from - 1)\n\nblocks = [[] * n for i in range(n)]\nfor _ in range(k):\n num_from, num_to = map(int, input().split())\n blocks[num_from - 1].append(num_to - 1)\n blocks[num_to - 1].append(num_from - 1)\n\nseen = [False] * n\nglobal count\n\ndef dfs(me, now, prev):\n global count\n \n seen[now] = True\n \n for next in friends[now]:\n if next != prev:\n if seen[next]:\n \n continue\n \n if next not in friends[me] and next not in blocks[me]:\n count += 1\n dfs(me, next, now)\n\nans = [0] * n\nfor i in range(n):\n seen = [False] * n\n count = 0\n dfs(i, i, -1)\n ans[i] = count\n\nprint(count)', "n, m, k = map(int, input().split())\npar = [-1 for _ in range(n)]\n\ndef find(x):\n if par[x] < 0:\n return x\n else:\n par[x] = find(par[x]) \n return par[x]\n\ndef same(x, y):\n return find(x) == find(y)\n\ndef unite(x, y):\n x = find(x)\n y = find(y)\n if x == y:\n return False\n \n \n if par[x] < par[y]:\n par[x] += par[y]\n par[y] = x\n else:\n par[y] += par[x]\n par[x] = y\n return True\n\nfriends_num = [0] * 100005\nfor _ in range(m):\n num_from, num_to = map(int, input().split())\n num_from -= 1\n num_to -= 1\n friends_num[num_from] += 1\n friends_num[num_to] += 1\n unite(num_from, num_to)\n\nblocks = [[] * n for i in range(n)]\nfor _ in range(k):\n num_from, num_to = map(int, input().split())\n num_from -= 1\n num_to -= 1\n blocks[num_from].append(num_to)\n blocks[num_to].append(num_from)\n\nans_list = []\nfor i in range(n):\n ans = -par[find(i)] - friends_num[i] - 1\n for b in blocks[i]:\n if same(i, b):\n ans -= 1\n ans_list.append(ans)\n\nprint(' '.join(map(str, ans_list)))"] | ['Runtime Error', 'Accepted'] | ['s722113167', 's104796213'] | [41960.0, 33300.0] | [2106.0, 1203.0] | [1046, 1295] |
p02762 | u257162238 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import bisect\n\n\nclass UnionFind():\n \n def __init__(self, n):\n self.n = next\n self.parent = [-1 for i in range(n)]\n \n def find(self, x):\n if self.parent[x] < 0:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n \n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n else:\n if self.parent[x] > self.parent[y]:\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x\n return True\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.parent[self.find(x)]\n \n def __str__(self):\n return str(self.parent)\n\n\n\ndef read():\n N, M, K = list(map(int, input().strip().split()))\n uf = UnionFind(N)\n friends = [list() for i in range(N+1)]\n blocked = [list() for i in range(N+1)]\n for i in range(M):\n a, b = list(map(int, input().strip().split()))\n friends[a].append(b)\n friends[b].append(a)\n uf.unite(a-1, b-1)\n for i in range(K):\n c, d = list(map(int, input().strip().split()))\n blocked[c].append(d)\n blocked[d].append(c)\n for i in range(N+1):\n friends[i] = sorted(friends[i])\n blocked[i] = sorted(blocked[i])\n return N, M, K, friends, blocked, uf\n\n\ndef solve(N, M, K, friends, blocked, uf):\n n_friendships = [0 for i in range(N)]\n for i in range(N):\n for j in friends[i]:\n bi = bisect.bisect_left(blocked[i+1], j+1)\n is_blocked = bi < len(blocked[i+1]) and blocked[i+1][bi] == j+1\n if not is_blocked:\n n_friendships[i] += 1\n return \' \'.join(map(str, n_friendships))\n\n\nif __name__ == \'__main__\':\n inputs = read()\n print("{}".format(solve(*inputs)))\n', 'import bisect\n\n\nclass UnionFind():\n \n def __init__(self, n):\n self.n = next\n self.parent = [-1 for i in range(n)]\n \n def find(self, x):\n if self.parent[x] < 0:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n \n def unite(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return False\n else:\n if self.parent[x] > self.parent[y]:\n x, y = y, x\n self.parent[x] += self.parent[y]\n self.parent[y] = x\n return True\n \n def same(self, x, y):\n return self.find(x) == self.find(y)\n \n def size(self, x):\n return -self.parent[self.find(x)]\n \n def __str__(self):\n return str(self.parent)\n\n\n\ndef read():\n N, M, K = list(map(int, input().strip().split()))\n uf = UnionFind(N)\n friends = [list() for i in range(N+1)]\n blocked = [list() for i in range(N+1)]\n for i in range(M):\n a, b = list(map(int, input().strip().split()))\n friends[a].append(b)\n friends[b].append(a)\n uf.unite(a-1, b-1)\n for i in range(K):\n c, d = list(map(int, input().strip().split()))\n blocked[c].append(d)\n blocked[d].append(c)\n return N, M, K, friends, blocked, uf\n\n\ndef solve(N, M, K, friends, blocked, uf):\n n_friendships = [0 for i in range(N)]\n for i in range(1, N+1):\n n = uf.size(i-1)\n m = len(friends[i])\n k = 0\n for b in blocked[i]:\n if uf.same(i-1, b-1):\n k += 1\n n_friendships[i-1] = n-1-m-k\n return \' \'.join(map(str, n_friendships))\n\n\nif __name__ == \'__main__\':\n inputs = read()\n print("{}".format(solve(*inputs)))\n'] | ['Wrong Answer', 'Accepted'] | ['s522290848', 's627305154'] | [60396.0, 63932.0] | [1367.0, 1525.0] | [1931, 1792] |
p02762 | u268181283 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n def get(self):\n return [self.members(r) for r in self.roots()][1:]\n\nN,M,K = map(int,input().split())\nf_arr = [[] for _ in range(N+1)]\nuf = UnionFind(N+1)\nfor i in range(M):\n a,b = map(int,input().split())\n uf.union(a,b)\n f_arr[a].append(b)\n f_arr[b].append(a)\nfor j in range(K):\n a,b = map(int,input().split())\n f_arr[a].append(b)\n f_arr[b].append(a)\n\nfor k in range(1,N+1):\n print(len(uf.members(k))-len(f_arr[k]) -1)', 'class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n def get(self):\n return [self.members(r) for r in self.roots()][1:]\n\nN,M,K = map(int,input().split())\nf_arr = [0 for _ in range(N+1)]\nuf = UnionFind(N+1)\nfor i in range(M):\n a,b = map(int,input().split())\n uf.union(a,b)\n f_arr[a] += 1\n f_arr[b] += 1\nfor j in range(K):\n a,b = map(int,input().split())\n if uf.same(a,b):\n f_arr[a] += 1\n f_arr[b] += 1\n\narr = []\nfor k in range(1,N+1):\n ans = uf.size(k)-f_arr[k] -1\n arr.append(ans)\nprint(*arr)\n'] | ['Wrong Answer', 'Accepted'] | ['s641281374', 's173109795'] | [34452.0, 14116.0] | [2105.0, 1078.0] | [1472, 1500] |
p02762 | u268318377 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['N, M, K = map(int, input().split())\nans = [0] * (N + 1)\nchild = {i:[] for i in range(1, N+1)}\ngroup_id = {i:[] for i in range(1, N+1)}\ngroup = {}\nisChecked = [0] * (N + 1)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n child[a].append(b)\n child[b].append(a)\n \nX = []\ng = 0\ni = 1\nwhile len(X) != N:\n if isChecked[i]:\n i += 1\n continue\n isChecked[i] = 1\n group_id[i] = g\n x = [i]\n ch = child[i].copy()\n while ch:\n print(ch)\n c = ch.pop(0)\n group_id[c] = g\n isChecked[c] = 1\n for j in child[c]:\n if not isChecked[j] and j not in ch:\n ch.append(j)\n x.append(c)\n group[g] = len(x)\n X += x\n if g % 1000 == 0:\n print(g)\n g += 1\n i += 1\n\nfor i in range(1, N+1):\n ans[i] = group[group_id[i]] - len(child[i]) - 1\n\nfor _ in range(K):\n c, d = map(int, input().split())\n if group_id[c] == group_id[d]:\n ans[c] -= 1\n ans[d] -= 1\n \nprint(*ans[1:])', 'N, M, K = map(int, input().split())\nans = [0] * (N + 1)\nchild = {i:[] for i in range(1, N+1)}\nisChecked = [0] * (N + 1)\nisBlocked = [set() for _ in range(N+1)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n child[a].append(b)\n child[b].append(a)\n \nfor _ in range(K):\n c, d = map(int, input().split())\n isBlocked[c].add(d)\n isBlocked[d].add(c)\n \nfor i in range(1, N+1):\n if isChecked[i]:\n continue\n isChecked[i] = 1\n x = set([i])\n ch = child[i].copy()\n while ch:\n c = ch.pop()\n if isChecked[c]:\n continue\n isChecked[c] = 1\n x.add(c)\n ch.extend(child[c])\n print(x)\n for j in x:\n ans[j] = len(x) - 1 - len(child[j]) - len(x & isBlocked[j])\n \nprint(*ans[1:])', 'N, M, K = map(int, input().split())\nans = [0] * (N + 1)\nchild = {i:[] for i in range(1, N+1)}\nisChecked = [0] * (N + 1)\nisBlocked = [set() for _ in range(N+1)]\n\nfor _ in range(M):\n a, b = map(int, input().split())\n child[a].append(b)\n child[b].append(a)\n \nfor _ in range(K):\n c, d = map(int, input().split())\n isBlocked[c].add(d)\n isBlocked[d].add(c)\n \nfor i in range(1, N+1):\n if isChecked[i]:\n continue\n isChecked[i] = 1\n x = set([i])\n ch = child[i].copy()\n while ch:\n c = ch.pop()\n if isChecked[c]:\n continue\n isChecked[c] = 1\n x.add(c)\n ch.extend(child[c])\n for j in x:\n ans[j] = len(x) - 1 - len(child[j]) - len(x & isBlocked[j])\n \nprint(*ans[1:])'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s834293813', 's948440075', 's206523007'] | [140276.0, 73784.0, 73012.0] | [2106.0, 1170.0, 1043.0] | [1004, 774, 761] |
p02762 | u278356323 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["# ABC157d\n\n\ndef main():\n import sys\n input = sys.stdin.readline\n sys.setrecursionlimit(10**6)\n \n\n class UnionFind:\n def __init__(self, n):\n self.tree = [i for i in range(n)]\n self.member = [1]*n\n\n def root(self, x):\n if(self.tree[x] == x):\n return x\n self.tree[x] = self.root(self.tree[x])\n return self.tree[x] \n\n def same(self, x, y): \n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if(x == y):\n return\n new = self.member[x]+self.member[y]\n self.member[x] = new\n self.member[y] = new\n self.tree[x] = y\n\n n, m, k = map(int, input().split())\n tree = UnionFind(n)\n\n friend = [set() for i in range(n)]\n for _ in range(m):\n a, b = map(int, input().split())\n friend[a - 1].add(b - 1)\n friend[b - 1].add(a - 1)\n tree.unite(a-1, b-1)\n block = [set() for i in range(n)]\n for _ in range(k):\n c, e = map(int, input().split())\n if tree.same(c - 1, e - 1):\n block[c - 1].add(e - 1)\n block[e - 1].add(c - 1)\n ans = []\n for i in range(n):\n print(i, tree.member[tree.root(i)], len(friend[i]), len(block[i]))\n ans.append(tree.member[tree.root(i)]-len(friend[i])-len(block[i])-1)\n print(*ans)\n\n\nif __name__ == '__main__':\n main()\n", "# ABC157d\n\n\ndef main():\n import sys\n input = sys.stdin.readline\n sys.setrecursionlimit(10**6)\n \n\n class UnionFind:\n def __init__(self, n):\n self.tree = [i for i in range(n)]\n self.member = [1]*n\n\n def root(self, x):\n if(self.tree[x] == x):\n return x\n self.tree[x] = self.root(self.tree[x])\n return self.tree[x] \n\n def same(self, x, y): \n return self.root(x) == self.root(y)\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if(x == y):\n return\n new = self.member[x]+self.member[y]\n self.member[x] = new\n self.member[y] = new\n self.tree[x] = y\n\n n, m, k = map(int, input().split())\n tree = UnionFind(n)\n\n friend = [set() for i in range(n)]\n for _ in range(m):\n a, b = map(int, input().split())\n friend[a - 1].add(b - 1)\n friend[b - 1].add(a - 1)\n tree.unite(a-1, b-1)\n block = [set() for i in range(n)]\n for _ in range(k):\n c, e = map(int, input().split())\n if tree.same(c - 1, e - 1):\n block[c - 1].add(e - 1)\n block[e - 1].add(c - 1)\n ans = []\n for i in range(n):\n \n ans.append(tree.member[tree.root(i)]-len(friend[i])-len(block[i])-1)\n print(*ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s164304545', 's384488502'] | [99984.0, 98292.0] | [1381.0, 1142.0] | [1593, 1594] |
p02762 | u298633786 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["import numpy as np\n\nN, M, K = map(int, input().split(' '))\n\nfriend_graph = np.zeros((N, N), dtype=np.uint8)\nfor _ in range(M):\n a, b = map(int, input().split(' '))\n friend_graph[a-1, b-1] = 1\n friend_graph[b-1, a-1] = 1\n\nblock_graph = np.zeros((N, N), dtype=np.uint8)\nfor _ in range(K):\n c, d = map(int, input().split(' '))\n block_graph[c-1, d-1] = 1\n block_graph[d-1, c-1] = 1\n\n\ndef dfs(s, adj_mat):\n cand_list = [s]\n vis_list = []\n\n while len(cand_list) > 0:\n vis = cand_list.pop(-1)\n vis_list.append(vis)\n pre_cand_list = np.where(adj_mat[vis] == 1)[0]\n for cand in pre_cand_list:\n if cand in vis_list:\n continue\n if cand in cand_list:\n continue\n cand_list.append(cand)\n\n return vis_list\n\n\nnum_friend_candidate_array = np.zeros(N, dtype=np.uint8)\nvisited_user_list = []\n\nfor i in range(N):\n if i in visited_user_list:\n continue\n\n connected_components = dfs(i, friend_graph)\n print(i, connected_components)\n num_connected_components = len(connected_components)\n visited_user_list += connected_components\n\n for j in connected_components:\n block_user = np.where(block_graph[j] == 1)[0]\n exclude_block_user = [\n cc for cc in connected_components if cc not in block_user]\n\n ans = len(exclude_block_user) - friend_graph[j].sum() - 1\n num_friend_candidate_array[j] = max(ans, 0)\n\nprint(' '.join(num_friend_candidate_array.astype(str)))\n", "from collections import defaultdict\n\n\nclass UnionFind:\n def __init__(self, n=0):\n self.d = {i: -1 for i in range(n)}\n\n def find(self, x):\n if self.d[x] < 0:\n return x\n else:\n self.d[x] = self.find(self.d[x])\n return self.d[x]\n\n def unite(self, x, y):\n x, y = self.find(x), self.find(y)\n if (x == y):\n return False\n if (self.d[x] > self.d[y]):\n x, y = y, x\n self.d[x] += self.d[y]\n self.d[y] = x\n return True\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def size(self, x):\n return -self.d[self.find(x)]\n\n\nN, M, K = map(int, input().split(' '))\ndeg = defaultdict(int)\nto = defaultdict(list)\nuf = UnionFind(N)\n\nfor _ in range(M):\n a, b = map(int, input().split(' '))\n a -= 1\n b -= 1\n deg[a] += 1\n deg[b] += 1\n uf.unite(a, b)\n\nfor _ in range(K):\n c, d = map(int, input().split(' '))\n c -= 1\n d -= 1\n to[c].append(d)\n to[d].append(c)\n\nfor i in range(N):\n ans = uf.size(i) - 1 - deg[i]\n for u in to[i]:\n if uf.same(i, u):\n ans -= 1\n print(ans, end=' ' if i != (N - 1) else '\\n')\n"] | ['Runtime Error', 'Accepted'] | ['s833437682', 's597633060'] | [1575300.0, 52612.0] | [1432.0, 1792.0] | [1517, 1198] |
p02762 | u303039933 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['# -*- coding: utf-8 -*-\nimport sys\nimport math\nimport os\nimport itertools\nimport string\nimport heapq\nimport _collections\nfrom collections import Counter\nfrom collections import defaultdict\nfrom collections import deque\nfrom functools import lru_cache\nimport bisect\nimport re\nimport queue\nimport decimal\n\n\nclass Scanner():\n @staticmethod\n def int():\n return int(sys.stdin.readline().rstrip())\n\n @staticmethod\n def string():\n return sys.stdin.readline().rstrip()\n\n @staticmethod\n def map_int():\n return [int(x) for x in Scanner.string().split()]\n\n @staticmethod\n def string_list(n):\n return [Scanner.string() for i in range(n)]\n\n @staticmethod\n def int_list_list(n):\n return [Scanner.map_int() for i in range(n)]\n\n @staticmethod\n def int_cols_list(n):\n return [Scanner.int() for i in range(n)]\n\n\nclass Math():\n @staticmethod\n def gcd(a, b):\n if b == 0:\n return a\n return Math.gcd(b, a % b)\n\n @staticmethod\n def lcm(a, b):\n return (a * b) // Math.gcd(a, b)\n\n @staticmethod\n def divisor(n):\n res = []\n i = 1\n for i in range(1, int(n ** 0.5) + 1):\n if n % i == 0:\n res.append(i)\n if i != n // i:\n res.append(n // i)\n return res\n\n @staticmethod\n def round_up(a, b):\n return -(-a // b)\n\n @staticmethod\n def is_prime(n):\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n d = int(n ** 0.5) + 1\n for i in range(3, d + 1, 2):\n if n % i == 0:\n return False\n return True\n\n @staticmethod\n def fact(N):\n res = {}\n tmp = N\n for i in range(2, int(N ** 0.5 + 1) + 1):\n cnt = 0\n while tmp % i == 0:\n cnt += 1\n tmp //= i\n if cnt > 0:\n res[i] = cnt\n if tmp != 1:\n res[tmp] = 1\n if res == {}:\n res[N] = 1\n return res\n\n\ndef pop_count(x):\n x = x - ((x >> 1) & 0x5555555555555555)\n x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)\n x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f\n x = x + (x >> 8)\n x = x + (x >> 16)\n x = x + (x >> 32)\n return x & 0x0000007f\n\n\nMOD = int(1e09) + 7\nINF = int(1e15)\n\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def root(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.root(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.root(x)]\n\n def is_same(self, x, y):\n return self.root(x) == self.root(y)\n\n\ndef solve():\n N, M, K = Scanner.map_int()\n uni = UnionFind(N)\n friends = [set() for _ in range(N)]\n for _ in range(M):\n a, b = Scanner.map_int()\n a -= 1\n b -= 1\n uni.unite(a, b)\n friends[a].add(b)\n friends[b].add(a)\n block = [set() for _ in range(N)]\n for _ in range(K):\n a, b = Scanner.map_int()\n a -= 1\n b -= 1\n block[a].add(b)\n block[b].add(a)\n ans = [0 for _ in range(N)]\n for i in range(N):\n size = uni.size(i)\n f = len(friends[i])\n bn = 0\n for b in block[i]:\n if uni.is_same(i, b):\n bn += 1\n ans[i] = size - 1 - f - bn\n print(*ans)\n\n\ndef main():\n sys.stdin = open("sample.txt")\n # T = Scanner.int()\n # for _ in range(T):\n # solve()\n # print(\'YNeos\'[not solve()::2])\n solve()\n\n\nif __name__ == "__main__":\n main()\n', '# -*- coding: utf-8 -*-\nimport sys\nimport math\nimport os\nimport itertools\nimport string\nimport heapq\nimport _collections\nfrom collections import Counter\nfrom collections import defaultdict\nfrom collections import deque\nfrom functools import lru_cache\nimport bisect\nimport re\nimport queue\nimport decimal\n\n\nclass Scanner():\n @staticmethod\n def int():\n return int(sys.stdin.readline().rstrip())\n\n @staticmethod\n def string():\n return sys.stdin.readline().rstrip()\n\n @staticmethod\n def map_int():\n return [int(x) for x in Scanner.string().split()]\n\n @staticmethod\n def string_list(n):\n return [Scanner.string() for i in range(n)]\n\n @staticmethod\n def int_list_list(n):\n return [Scanner.map_int() for i in range(n)]\n\n @staticmethod\n def int_cols_list(n):\n return [Scanner.int() for i in range(n)]\n\n\nclass Math():\n @staticmethod\n def gcd(a, b):\n if b == 0:\n return a\n return Math.gcd(b, a % b)\n\n @staticmethod\n def lcm(a, b):\n return (a * b) // Math.gcd(a, b)\n\n @staticmethod\n def divisor(n):\n res = []\n i = 1\n for i in range(1, int(n ** 0.5) + 1):\n if n % i == 0:\n res.append(i)\n if i != n // i:\n res.append(n // i)\n return res\n\n @staticmethod\n def round_up(a, b):\n return -(-a // b)\n\n @staticmethod\n def is_prime(n):\n if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n d = int(n ** 0.5) + 1\n for i in range(3, d + 1, 2):\n if n % i == 0:\n return False\n return True\n\n @staticmethod\n def fact(N):\n res = {}\n tmp = N\n for i in range(2, int(N ** 0.5 + 1) + 1):\n cnt = 0\n while tmp % i == 0:\n cnt += 1\n tmp //= i\n if cnt > 0:\n res[i] = cnt\n if tmp != 1:\n res[tmp] = 1\n if res == {}:\n res[N] = 1\n return res\n\n\ndef pop_count(x):\n x = x - ((x >> 1) & 0x5555555555555555)\n x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)\n x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f\n x = x + (x >> 8)\n x = x + (x >> 16)\n x = x + (x >> 32)\n return x & 0x0000007f\n\n\nMOD = int(1e09) + 7\nINF = int(1e15)\n\n\nclass UnionFind:\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def root(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.root(self.parents[x])\n return self.parents[x]\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.root(x)]\n\n def is_same(self, x, y):\n return self.root(x) == self.root(y)\n\n\ndef solve():\n N, M, K = Scanner.map_int()\n uni = UnionFind(N)\n friends = [set() for _ in range(N)]\n for _ in range(M):\n a, b = Scanner.map_int()\n a -= 1\n b -= 1\n uni.unite(a, b)\n friends[a].add(b)\n friends[b].add(a)\n block = [set() for _ in range(N)]\n for _ in range(K):\n a, b = Scanner.map_int()\n a -= 1\n b -= 1\n block[a].add(b)\n block[b].add(a)\n ans = [0 for _ in range(N)]\n for i in range(N):\n size = uni.size(i)\n f = len(friends[i])\n bn = 0\n for b in block[i]:\n if uni.is_same(i, b):\n bn += 1\n ans[i] = size - 1 - f - bn\n print(*ans)\n\n\ndef main():\n \n # T = Scanner.int()\n # for _ in range(T):\n # solve()\n # print(\'YNeos\'[not solve()::2])\n solve()\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s470685626', 's981579336'] | [5656.0, 78868.0] | [51.0, 1206.0] | [4002, 4004] |
p02762 | u312907447 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ['import sys\n\nsys.setrecursionlimit(10 ** 7)\n\ndef dfs(x, seen):\n seen.add(x)\n for i in G[x]:\n if i in seen:\n continue\n dfs(i, seen)\n\nN, M, K = map(int, input().split())\n\n\nS = set()\n\nG = [[] for i in range(N)]\n\nfor _ in range(M):\n A, B = map(int, input().split())\n G[A-1].append(B-1)\n G[B-1].append(A-1)\n S |= set([A-1, B-1])\n\n#print(len(S))\n\n#n_iter = 0\n\nR = []\nwhile len(S) != 0:\n seen = set()\n dfs(S.pop(), seen)\n \n R.append(seen)\n S = S - seen\n #n_iter += 1\n\n#print(R[0])\n\n\nBlock = [set() for i in range(N)]\nfor _ in range(K):\n C, D = map(int, input().split())\n Block[C-1].add([D-1])\n Block[D-1].add([C-1])\n\nseq = [0]*N\n\nfor r in R:\n for j in r:\n seq[j] = len(r) - len(G[j]) - len(r&Block[j]) - 1\n\n\nprint(*seq)', 'import sys\nsys.setrecursionlimit(10 ** 9)\n\nN, M, K = map(int, input().split())\n\nFriend = [[] for i in range(N)]\nfor _ in range(M):\n A, B = map(int, input().split())\n Friend[A-1].append(B-1)\n Friend[B-1].append(A-1)\n\nBlock = [set() for i in range(N)]\nfor _ in range(K):\n C, D = map(int, input().split())\n Block[C-1].add(D-1)\n Block[D-1].add(C-1)\n\n\ndef dfs(x):\n if seen[x] == 0:\n R[cnt].add(x)\n seen[x]=1\n for i in Friend[x]:\n dfs(i)\n\nseen = [0]*N\ncnt = 0\nR = []\nfor i in range(N):\n if seen[i] == 0:\n R.append(set())\n dfs(i)\n cnt += 1\n\nseq = [0]*N\n\nfor r in R:\n lr = len(r)\n for j in r:\n seq[j] = lr - len(Friend[j]) - len(r&Block[j]) - 1\n\nprint(*seq)'] | ['Runtime Error', 'Accepted'] | ['s053388093', 's757757900'] | [57940.0, 83704.0] | [2022.0, 1188.0] | [1050, 731] |
p02762 | u318127926 | 2,000 | 1,048,576 | An SNS has N users - User 1, User 2, \cdots, User N. Between these N users, there are some relationships - M _friendships_ and K _blockships_. For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i. For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i. We define User a to be a _friend candidate_ for User b when all of the following four conditions are satisfied: * a \neq b. * There is not a friendship between User a and User b. * There is not a blockship between User a and User b. * There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1. For each user i = 1, 2, ... N, how many friend candidates does it have? | ["n, m, k = map(int, input().split())\n\nfriends = [[] for _ in range(n+1)]\nblocks = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].append(b)\n friends[b].append(a)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n blocks[c].append(d)\n blocks[d].append(c)\n\ngroups = []\nnseen = {i for i in range(1, n+1)}\nwhile len(nseen)>0:\n stack = [nseen.pop()]\n tmp = set()\n while len(stack)>0:\n node = stack.pop()\n tmp.add(node)\n for c_node in friends[node]:\n if c_node not in nseen:\n continue\n stack.append(c_node)\n nseen.remove(c_node)\n groups.append(tmp)\n\nfor i in range(1, n+1):\n for j in groups:\n if i in j:\n print(len(j - set(friends[i]) - set(blocks[i]))-1, end=' ')\n break", "n, m, k = map(int, input().split())\n\nfriends = []\nblocks = []\ngroups = []\nfs = [[] for _ in range(n+1)]\nbs = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n friends.append(tuple(map(int, input().split())))\nfor _ in range(k):\n blocks.append(tuple(map(int, input().split())))\n\nfor i, j in friends:\n fs[i].append(j)\n fs[j].append(i)\n\nfor i, j in blocks:\n bs[i].append(j)\n bs[j].append(i)\n\ndef search_groups(x, y):\n xx = -1\n yy = -1\n for ind, i in enumerate(groups):\n if x in i:\n xx = ind\n if yy >= 0:\n break\n if y in i:\n yy = ind\n if xx >= 0:\n break\n return xx, yy\n\nfor i, j in friends:\n ii, jj = search_groups(i, j)\n if ii==jj==-1:\n groups.append({i, j})\n elif ii==-1:\n groups[jj].add(i)\n elif jj==-1:\n groups[ii].add(j)\n elif ii!=jj:\n rm1 = groups[ii]\n rm2 = groups[jj]\n groups.append(rm1|rm2)\n groups.remove(rm1)\n groups.remove(rm2)\n\nfor i in range(1, n+1):\n for j in groups:\n if i in j:\n print(len(j - set(fs[i]) - set(bs[i]))-1, end=' ')\n break", "n, m, k = map(int, input().split())\n\nfriends = [[] for _ in range(n+1)]\nblocks = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].append(b)\n friends[b].append(a)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n blocks[c].append(d)\n blocks[d].append(c)\n\ngroups = []\nnseen = {i for i in range(1, n+1)}\nwhile len(nseen)>0:\n stack = [nseen.pop()]\n tmp = set()\n while len(stack)>0:\n node = stack.pop()\n tmp.add(node)\n nseen.remove(node)\n for c_node in friends[node]:\n if c_node not in nseen:\n continue\n stack.append(c_node)\n groups.append(tmp)\n\nfor i in range(1, n+1):\n for j in groups:\n if i in j:\n print(len(j - set(friends[i]) - set(blocks[i]))-1, end=' ')\n break", "n, m, k = map(int, input().split())\n\nfriends = []\nblocks = []\ngroups = []\nfs = [[] for _ in range(n+1)]\nbs = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n friends.append(tuple(map(int, input().split())))\nfor _ in range(k):\n blocks.append(tuple(map(int, input().split())))\n\nfor i, j in friends:\n fs[i].append(j)\n fs[j].append(i)\n\nfor i, j in blocks:\n bs[i].append(j)\n bs[j].append(i)\n\nseen = [False]*(n+1)\nwhile True:\n for i in range(1, n+1):\n if not seen[i]:\n stack = [i]\n break\n else:\n break\n tmp = set()\n while len(stack)>0:\n node = stack.pop()\n tmp.add(node)\n seen[node] = True\n for c_node in fs[node]:\n if seen[c_node]:\n continue\n stack.append(c_node)\n groups.append(tmp)\n\n\nfor i in range(1, n+1):\n for j in groups:\n if i in j:\n print(len(j - set(fs[i]) - set(bs[i]))-1, end=' ')\n break", "n, m, k = map(int, input().split())\n\nfriends = [[] for _ in range(n+1)]\nblocks = [[] for _ in range(n+1)]\n\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a].append(b)\n friends[b].append(a)\n\nfor _ in range(k):\n c, d = map(int, input().split())\n blocks[c].append(d)\n blocks[d].append(c)\n\ngroups = []\nseen = [False]*(n+1)\nwhile True:\n for i in range(1, n+1):\n if not seen[i]:\n stack = [i]\n break\n else:\n break\n tmp = set()\n while len(stack)>0:\n node = stack.pop()\n tmp.add(node)\n seen[node] = True\n for c_node in friends[node]:\n if seen[c_node]:\n continue\n stack.append(c_node)\n groups.append(tmp)\n\n\nfor i in range(1, n+1):\n for j in groups:\n if i in j:\n print(len(j - set(friends[i]) - set(blocks[i]))-1, end=' ')\n break", 'from collections import deque\nn, m, k = map(int, input().split())\nfriends = [[] for _ in range(n)]\nblocks = [[] for _ in range(n)]\nfor _ in range(m):\n a, b = map(int, input().split())\n friends[a-1].append(b-1)\n friends[b-1].append(a-1)\nfor _ in range(k):\n c, d = map(int, input().split())\n blocks[c-1].append(d-1)\n blocks[d-1].append(c-1)\n\n\ngrp_idx = [-1]*n\ngrp_szs = []\ngrp = 0\nfor i in range(n):\n if grp_idx[i]>=0:\n continue\n queue = deque([i])\n grp_idx[i] = grp\n tmp = 0\n while len(queue)>0:\n node = queue.popleft()\n for c_node in friends[node]:\n if grp_idx[c_node]>=0:\n continue\n grp_idx[c_node] = grp\n tmp += 1\n queue.append(c_node)\n grp_szs.append(tmp)\n grp += 1\nans = []\nfor i in range(n):\n tmp = grp_szs[grp_idx[i]]\n for j in friends[i]:\n if grp_idx[j]==grp_idx[i]:\n tmp -= 1\n for j in blocks[i]:\n if grp_idx[j]==grp_idx[i]:\n tmp -= 1\n ans.append(tmp)\nprint(*ans)'] | ['Time Limit Exceeded', 'Wrong Answer', 'Runtime Error', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s080460017', 's099710095', 's101562981', 's561358180', 's730153620', 's812356075'] | [64996.0, 68240.0, 48616.0, 67060.0, 52812.0, 47188.0] | [2111.0, 2107.0, 806.0, 2108.0, 2110.0, 1112.0] | [842, 1165, 836, 956, 899, 1038] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.