from random import *
from sys import argv

seed('ololo')

test = 1
def out(n, m, k, edges):
	global test
	test += 1
	print('%d'%test)
	out = open('../tests/%02d'%test, 'w')
	print(n, m, k, file = out)
	#print('\n', file = out)
	for i in edges:
		print(i[0],i[1],i[2], file = out)
		#//print('\n', file = out)
	
def sun(n):
	edges = []
	for i in range(n - 2):
		edges += [(1, i + 2, i + 1)]
	return edges
	
def chainOneColor(n):
	edges = []
	for i in range(n - 1):
		edges += [(i+1, i + 2, 1)]
	return edges

def chainDifColor(n):
	edges = []
	for i in range(n - 1):
		edges += [(i+1, i + 2, i + 1)]
	return edges

def fullGraphDifColors(n):
	edges = []
	k = 1
	for i in range(n):
		for j in range(n - i - 1):
			edges += [(i + 1, j + i + 2, k)]
			k += 1
	return edges
	
def fullGraphTwoColors(n):
	edges = []
	for i in range(n):
		for j in range(n - i - 1):
			edges += [(i + 1, j + i + 2, randint(1,2))]
	return edges

def cycleTwoColor(n):
	edges = []
	for i in range(n - 1):
		edges += [(i+1, i + 2, randint(1,2))]
	edges += [(1, n , randint(1,2))]	
	return edges
	
def chainPlusSun(k):
	n = k - 1;
	edges = []
	for i in range(n//2 + 1):
		edges += [(i+1, i + 2, 1)]
	for i in range(n//2):
		edges += [(n//2 + 2, n//2 + i + 3, 1)]
	return edges

def chainPlusSunTwo(k):
	n = k - 1;
	edges = []
	for i in range(n//2 + 1):
		edges += [(i+1, i + 2, randint(1,2))]
	for i in range(n//2):
		edges += [(n//2 + 2, n//2 + i + 3, randint(1,2))]
	return edges

def chainPlusSunMany(k):
	n = k - 1;
	edges = []
	for i in range(n//2 + 1):
		edges += [(i+1, i + 2, randint(1,n - 1))]
	for i in range(n//2):
		edges += [(n//2 + 2, n//2 + i + 3, randint(1,n - 1))]
	return edges

def chainPlusSunTen(k):
	n = k - 1;
	edges = []
	for i in range(n//2 + 1):
		edges += [(i+1, i + 2, randint(1,10))]
	for i in range(n//2):
		edges += [(n//2 + 2, n//2 + i + 3, randint(1,10))]
	return edges

def rand(n, m, col):
	edges = []
	x = set()
	for i in range(m):
		k = (randint(1,n - 1))
		x.add((k,(randint(k + 1,n))))
	for i in x:
		edges += [(i[0], i[1], randint(1, col))]
	out(n, len(x), col, edges)	

#example
k = open('../tests/%02d'%test, 'w')
print(4,3,2, file = k)
print(1,2,1, file = k)
print(2,3,2, file = k)
print(3,4,1, file = k)

#suns
out(9, 8, 8, sun(10))
out(99, 98, 98, sun(100))
out(9999, 9998, 9998, sun(10000))
out(99999, 99998, 99998, sun(100000))

#chains
out(10, 9, 1, chainOneColor(10))
out(1000, 999, 1, chainOneColor(1000))
out(100000, 99999, 1, chainOneColor(100000))

out(10, 9, 9, chainDifColor(10))
out(1000, 999, 999, chainDifColor(1000))
out(100000, 99999, 99999, chainDifColor(100000))

#fullGraph
out(5, 10, 10, fullGraphDifColors(5))
out(400, 79800, 79800, fullGraphDifColors(400))

out(5, 10, 2, fullGraphTwoColors(5))
out(400, 79800, 2, fullGraphTwoColors(400))

#cycle
out(100000, 100000, 2, cycleTwoColor(100000))

out(6,5, 1, chainPlusSun(6))
out(100000,9999, 1, chainPlusSun(10000))

out(6,5, 2, chainPlusSunTwo(6))
out(100000,9999, 2, chainPlusSunTwo(10000))

out(6,5, 5, chainPlusSunMany(6))
out(100000,9999, 99999, chainPlusSunMany(10000))

out(100000,9999, 10, chainPlusSunTen(10000))

rand(10, 10, 1)
rand(10, 10, 3)
rand(100, 300, 50)
rand(100, 300, 2)
rand(100000, 100000, 100)
rand(100000, 200000, 10000)

rand(100, 300, 50)
