summaryrefslogtreecommitdiffstats
path: root/Main/Python/2013/S3.py
blob: ff2c129af06255df4fef155af8069088392da930 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
games = [(1, 2),
         (1, 3),
         (1, 4),
         (2, 3),
         (2, 4),
         (3, 4)]
seen = set()

team = {1: 0, 2: 0, 3: 0, 4: 0}

T = int(input())
G = int(input())
for i in range(G):
    A, B, SA, SB = tuple(map(int, input().split()))
    seen.add((A, B))
    seen.add((B, A))
    if SA > SB:
        team[A] += 3
    elif SA == SB:
        team[A] += 1
        team[B] += 1
    else:
        team[B] += 3

unplayed = []
for i in games:
    if i not in seen:
        unplayed.append(i)

wins = [0]


def dfs(node, depth):
    if depth == len(unplayed):
        tied = False
        winning_team = 0
        most_points = 0
        for i in node:
            if node[i] > most_points:
                most_points = node[i]
                winning_team = i
                tied = False
            elif node[i] == most_points:
                tied = True

        if not tied and winning_team == T:
            wins[0] += 1

        return

    current = node.copy()
    A, B = unplayed[depth]
    current[A] += 3
    dfs(current, depth + 1)
    current[A] -= 2
    current[B] += 1
    dfs(current, depth + 1)
    current[B] += 2
    current[A] -= 1
    dfs(current, depth + 1)


dfs(team, 0)
print(wins[0])