Created
May 6, 2011 17:07
-
-
Save hiromu/959340 to your computer and use it in GitHub Desktop.
Sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def finish(res): | |
for i in res: | |
print str(len(i)) + ' ' + ' '.join(map(str, i)) | |
sys.exit(0) | |
n = int(raw_input()) | |
dic = [] | |
for i in range(0, n * (n - 1) / 2): | |
buf = raw_input().split() | |
a = [] | |
for j in buf[1:]: | |
a.append(int(j)) | |
b = [] | |
b.append(int(buf[0])) | |
b.append(a) | |
dic.append(b) | |
res = [] | |
for i in dic: | |
if i[0] == 2: | |
if [i[1][0]] not in res: | |
res.append([i[1][0]]) | |
if [i[1][1]] not in res: | |
res.append([i[1][1]]) | |
while len(res) < n: | |
for i in res: | |
for j in dic: | |
if i[0] in j[1]: | |
if list(set(j[1]) - set(i)) not in res: | |
res.append(list(set(j[1]) - set(i))) | |
if len(res) >= n: | |
finish(res) | |
finish(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment