QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658215#7011. Rikka with Sorting NetworksnekoyellowTL 16ms10524kbPython3660b2024-10-19 16:23:512024-10-19 16:23:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 16:23:59]
  • 评测
  • 测评结果:TL
  • 用时:16ms
  • 内存:10524kb
  • [2024-10-19 16:23:51]
  • 提交

answer

from itertools import permutations


def solve():
	n, k, m = map(int, input().split())
	p = []
	for i in range(k):
		p.append(list(map(int, input().split())))
		p[i][0] -= 1
		p[i][1] -= 1
	cnt = 0
	for a in permutations(range(1, n+1)):
		a = list(a)
		for x, y in p:
			a[x], a[y] = min(a[x], a[y]), max(a[x], a[y])
		ok = False
		for i in range(n):
			ordered = True
			prev = 0
			for j in range(n):
				if j == i: continue
				if a[j] < prev:
					ordered = False
					break
				prev = a[j]
			if ordered:
				ok = True
				break
		if ok:
			# print(a)
			cnt += 1
	print(cnt)



for _ in range(int(input())):
	solve()

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 10524kb

input:

4
4 0 998244353
4 1 998244353
1 2
4 3 998244353
1 2
2 3
1 2
4 6 998244353
1 2
2 3
1 2
3 4
2 3
1 2

output:

10
14
24
24

result:

ok 4 lines

Test #2:

score: -100
Time Limit Exceeded

input:

100
14 0 332974091
7 0 860384617
38 0 721801273
20 0 905563207
15 0 665595113
19 0 315971339
37 10 381449743
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
33 7 891399043
7 17
6 16
25 32
25 31
16 25
25 32
17 30
35 0 134186387
43 4 344440849
14 26
26 29
14 26
14 29
44 3 520502371
5 8
5 8...

output:


result: