-
Notifications
You must be signed in to change notification settings - Fork 0
/
liar_bfs.py
50 lines (49 loc) · 1011 Bytes
/
liar_bfs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import Queue
import sys
f=open(sys.argv[1])
dic={}
l=f.readline()
n=int(l)
while n>0:
n=n-1
l=f.readline()
name,n2=l.split()
if name not in dic:
dic[name]=[]
n2=int(n2)
while n2>0:
n2=n2-1
l=f.readline().rstrip()
if l in dic.keys():
if name in dic[l]:
pass
else:
dic[l].append(name)
else:
dic[l]=[]
dic[l].append(name)
if l not in dic[name]:
dic[name].append(l)
q=Queue.Queue()
lis,color=[],{}
for x in dic.keys():
color[x]=0
color[name]=2
q.put((name,0))
lis.append((name,0))
while q.empty()!=True:
temp=q.get()
i=(temp[1] +1 )%2
for x in dic[temp[0]]:
if color[x]==0:
q.put((x,i))
lis.append((x,i))
color[x]=1
n0,n1=0,0
for x in lis:
if x[1]==1:
n0+=1
else:
n1+=1
print max(n0,n1),min(n1,n0)