# sisendi korrektsuse kontrollija import sys fi = open(sys.argv[1], 'rt') fo = open(sys.argv[2], 'wt') (n, k) = map(int, fi.readline().strip().split()) if 1 > n or n > 500000: sys.exit('N out of range') if 1 > k or k > n: sys.exit('K out of range') fo.write('{0} {1}\n'.format(n, k)) g = [[] for i in range(n)] for i in range(n - 1): (u, v) = map(int, fi.readline().strip().split()) if 1 > u or u > n: sys.exit('U[{0}] out of range'.format(i + 1)) if 1 > v or v > n: sys.exit('V[{0}] out of range'.format(i + 1)) g[u - 1].append(v - 1) g[v - 1].append(u - 1) fo.write('{0} {1}\n'.format(u, v)) cc = map(int, fi.readline().strip().split()) if len(cc) <> k: sys.exit('Wrong number of C values') for i, c in enumerate(cc): if 1 > c or c > n: sys.exit('C[{0}] out of range'.format(i + 1)) fo.write('{0}\n'.format(' '.join(map(str, cc)))) fi.close() fo.close() # teedegraaf peab olema sidus h = [0 for i in range(n)] q = [0] while len(q) > 0: i = q.pop() h[i] = 1 for j in g[i]: if h[j] == 0: q.append(j) if sum(h) <> n: sys.exit('Road network not connected') # turniiril osalevad linnad peavad olema paarikaupa erinevad cc.sort() d = 0 for c in cc: if c == d: sys.exit('Duplicate tournament participant {0}\n'.format(c)) d = c