| Task: | Building Teams |
| Sender: | kookinnam |
| Submission time: | 2025-09-08 16:39:44 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.04 s | details |
| #3 | WRONG ANSWER | 0.04 s | details |
| #4 | ACCEPTED | 0.04 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | ACCEPTED | 0.04 s | details |
| #12 | ACCEPTED | 0.04 s | details |
Code
def function(n, m, friends):
teams = [0] * n
teams[0] = 1
sorted_friends = sorted(friends)
for friend in sorted_friends:
a = friend[0] - 1
b = friend[1] - 1
if teams[a] == 0 and teams[b] == 0:
teams[a] = 1
teams[b] = 2
elif (teams[a] == 1 and teams[b] == 1) or (teams[a] == 2 and teams[b] == 2):
return []
elif (teams[a] == 0 and teams[b] == 1):
teams[a] = 2
elif (teams[a] == 0 and teams[b] == 2):
teams[a] = 1
elif (teams[b] == 0 and teams[a] == 1):
teams[b] = 2
elif (teams[b] == 0 and teams[a] == 2):
teams[b] = 1
return teams
def main():
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
friends = []
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
friends.append([a, b])
# applicants = list(map(int, input().split()))
# apartments = list(map(int, input().split()))
results = function(n, m, friends)
if results == []:
print("IMPOSSIBLE")
return
for result in results:
print(result, end=" ")
if __name__ == "__main__":
main()
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 20 3 4 8 10 3 7 1 8 ... |
| correct output |
|---|
| 1 1 1 2 2 1 2 2 2 1 |
| user output |
|---|
| 1 1 1 2 2 1 2 2 2 1 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 20 1 3 8 10 2 4 6 8 ... |
| correct output |
|---|
| 1 1 2 2 1 1 1 2 1 1 |
| user output |
|---|
| 1 1 2 2 1 1 1 2 1 1 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 7 10 3 10 9 10 2 10 ... |
| correct output |
|---|
| 1 2 2 1 1 1 2 1 2 1 |
| user output |
|---|
| IMPOSSIBLE |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 20 2 4 2 10 7 10 4 6 ... |
| correct output |
|---|
| 1 2 1 1 2 2 2 1 2 1 |
| user output |
|---|
| 1 2 1 1 2 2 2 1 2 1 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 20 3 5 8 10 9 10 1 8 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 47355 96505 90709 92058 735 80715 91802 94265 ... |
| correct output |
|---|
| 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 59991 95794 95150 96051 78453 94730 90411 95523 ... |
| correct output |
|---|
| 1 1 1 2 2 1 1 2 1 2 1 2 2 2 1 ... |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 89827 96402 65137 86792 80965 94708 19479 48078 ... |
| correct output |
|---|
| 1 2 1 1 2 1 2 2 2 1 2 1 1 2 1 ... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 72952 83723 66197 70052 2949 52160 55753 95651 ... |
| correct output |
|---|
| 1 1 2 2 2 1 1 2 2 2 2 2 1 2 1 ... |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 38942 96755 70049 82663 7746 72732 87819 99029 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 5 4 1 2 3 4 4 5 5 3 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 4 5 1 2 1 4 2 3 2 4 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
