Task: | 3-Coloring |
Sender: | arnxxau |
Submission time: | 2024-11-27 16:57:08 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | WRONG ANSWER | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | WRONG ANSWER | 0.01 s | details |
#13 | WRONG ANSWER | 0.05 s | details |
Code
#include <algorithm>#include <iostream>#include <queue>#include <stack>#include <vector>using namespace std;void colorsdfs(vector<int>& g, vector<int>& colors, int s, int color) {if (colors[s] == -1) {colors[s] = color;colorsdfs(g, colors, g[s], (color + 1) % 3);}}void topologicalSortUtil(int v, vector<int>& adj,vector<bool>& visited,stack<int>& Stack) {visited[v] = true;int i = adj[v];if (!visited[i])topologicalSortUtil(i, adj, visited, Stack);Stack.push(v);}stack<int> topologicalSort(vector<int>& adj, int V) {stack<int> Stack;vector<bool> visited(V, false);for (int i = 0; i < V; i++) {if (!visited[i])topologicalSortUtil(i, adj, visited, Stack);}return Stack;}int main() {int n;cin >> n;vector<int> g(n);for (int i = 0; i < n; i++) {int x;cin >> x;--x;g[i] = x;}stack<int> topo = topologicalSort(g, n);vector<int> colors(n, -1);int color = 0;while (!topo.empty()) {int x = topo.top();topo.pop();colors[x] = color;color = (color + 1) % 3;}/*for (int i = 0; i < n; i++) {if (colors[g[i]] == -1) {colorsdfs(g, colors, i, 0);} else {colorsdfs(g, colors, i, 0);}}*/for (int i = 0; i < n; i++) {cout << colors[i] + 1 << ' ';}cout << endl;}
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 |
---|
2 3 1 |
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 |
---|
3 2 1 2 1 |
Test 5
Verdict: ACCEPTED
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 |
---|
1 3 2 2 1 1 2 1 3 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 |
---|
3 2 1 2 3 1 2 1 1 3 |
Test 7
Verdict: ACCEPTED
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 |
---|
1 3 2 3 1 3 2 1 1 2 |
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 |
---|
3 2 2 1 1 3 2 1 1 3 |
Test 9
Verdict: WRONG ANSWER
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 |
---|
2 3 2 3 1 1 1 3 2 1 |
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 |
---|
2 3 2 2 1 1 1 1 1 3 1 2 2 3 2 ... Truncated |
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 |
---|
1 2 1 1 2 1 1 3 1 1 2 1 1 3 2 ... Truncated |
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 2 1 1 1 2 3 1 2 3 2 2 2 1 1 ... Truncated |
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 |
---|
2 1 2 1 3 1 3 2 3 3 3 3 3 1 2 ... Truncated |