Task: | 3-Coloring |
Sender: | ilyas.ben |
Submission time: | 2024-11-27 17:04:30 +0200 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | WRONG ANSWER | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | WRONG ANSWER | 0.02 s | details |
#6 | ACCEPTED | 0.02 s | details |
#7 | WRONG ANSWER | 0.02 s | details |
#8 | WRONG ANSWER | 0.02 s | details |
#9 | ACCEPTED | 0.02 s | details |
#10 | WRONG ANSWER | 0.02 s | details |
#11 | WRONG ANSWER | 0.02 s | details |
#12 | WRONG ANSWER | 0.03 s | details |
#13 | WRONG ANSWER | 0.12 s | details |
Code
def three_coloring(n, edges): color = [-1] * n # To store colors for nodes (1-based) visited = [False] * n # To track visited nodes in_cycle = [False] * n # To mark nodes that are part of a cycle def dfs(node): stack = [] current = node while not visited[current]: visited[current] = True stack.append(current) current = edges[current] - 1 if current in stack: cycle_start = stack.index(current) return stack[cycle_start:] return [] def color_cycle(cycle): for i, node in enumerate(cycle): color[node] = (i % 3) + 1 in_cycle[node] = True for i in range(n): if not visited[i]: cycle = dfs(i) if cycle: color_cycle(cycle) for i in range(n): if color[i] == -1: color[i] = (color[edges[i] - 1] % 3) + 1 print(" ".join(map(str, color))) n = int(input()) edges = list(map(int, input().split())) three_coloring(n, edges)
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 2 1 |
correct output |
---|
1 2 |
user output |
---|
1 2 |
Test 2
Verdict: ACCEPTED
input |
---|
3 2 1 1 |
correct output |
---|
1 2 2 |
user output |
---|
1 2 2 |
Test 3
Verdict: WRONG ANSWER
input |
---|
4 3 1 4 2 |
correct output |
---|
1 2 2 1 |
user output |
---|
1 1 2 3 |
Test 4
Verdict: ACCEPTED
input |
---|
5 5 5 1 5 4 |
correct output |
---|
1 1 2 1 2 |
user output |
---|
2 2 3 2 1 |
Test 5
Verdict: WRONG ANSWER
input |
---|
10 3 1 9 9 3 4 10 10 5 1 |
correct output |
---|
1 2 2 2 3 1 1 1 1 2 |
user output |
---|
2 3 1 3 3 1 3 3 2 3 |
Test 6
Verdict: ACCEPTED
input |
---|
10 9 10 4 3 9 1 1 4 2 6 |
correct output |
---|
1 1 1 2 1 3 2 1 2 2 |
user output |
---|
1 3 1 2 3 2 2 3 2 1 |
Test 7
Verdict: WRONG ANSWER
input |
---|
10 3 8 4 5 10 8 5 10 4 6 |
correct output |
---|
1 1 2 1 2 2 1 3 2 1 |
user output |
---|
3 1 3 3 2 2 3 3 1 1 |
Test 8
Verdict: WRONG ANSWER
input |
---|
10 9 1 10 3 9 4 6 9 3 5 |
correct output |
---|
1 2 1 2 1 1 2 1 2 2 |
user output |
---|
2 3 2 3 1 1 2 2 1 3 |
Test 9
Verdict: ACCEPTED
input |
---|
10 4 6 5 5 1 2 4 2 1 3 |
correct output |
---|
1 1 1 2 3 2 1 2 2 2 |
user output |
---|
1 1 1 2 3 2 3 2 2 2 |
Test 10
Verdict: WRONG ANSWER
input |
---|
100 19 7 2 67 47 20 73 93 43 11 49... |
correct output |
---|
1 1 2 1 1 1 3 2 1 2 1 1 2 1 1 ... |
user output |
---|
3 3 2 3 3 1 1 1 3 2 1 2 1 3 2 ... |
Test 11
Verdict: WRONG ANSWER
input |
---|
1000 155 447 741 874 264 87 534 724... |
correct output |
---|
1 1 2 1 1 1 1 1 1 1 1 2 1 2 2 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 ... |
Test 12
Verdict: WRONG ANSWER
input |
---|
10000 7778 6074 2376 8595 8243 8930 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... |
Test 13
Verdict: WRONG ANSWER
input |
---|
100000 51396 92191 77318 65910 87045 ... |
correct output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... |