Task: | 3-Coloring |
Sender: | joaquimballester |
Submission time: | 2024-11-27 16:37:45 +0200 |
Language: | C++ (C++11) |
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 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
#7 | WRONG ANSWER | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.01 s | details |
#11 | WRONG ANSWER | 0.51 s | details |
#12 | RUNTIME ERROR | 0.79 s | details |
#13 | RUNTIME ERROR | 0.39 s | details |
Code
#include <bits/stdc++.h> #define ll long long int using namespace std; int V; void printSolution(int color[]); bool isSafe(int v,vector<vector<bool>> graph, int color[], int c) { for (int i = 0; i < V; i++) if (graph[v][i] && c == color[i]) return false; return true; } bool graphColoringUtil(vector<vector<bool>> graph, int m, int color[], int v) { if (v == V) return true; for (int c = 1; c <= m; c++) { if (isSafe(v, graph, color, c)) { color[v] = c; if (graphColoringUtil(graph, m, color, v + 1) == true) return true; color[v] = 0; } } return false; } bool graphColoring(vector<vector<bool>> graph, int m) { int color[V]; for (int i = 0; i < V; i++) color[i] = 0; if (graphColoringUtil(graph, m, color, 0) == false) { cout << "Solution does not exist"; return false; } printSolution(color); return true; } void printSolution(int color[]) { for (int i = 0; i < V; i++) cout << " " << color[i] << " "; cout << "\n"; } int main(){ int n; cin >> n; V = n; vector<vector<bool>> graph (n, vector<bool>(n,false)); for(int i = 0; i < n; ++i){ int e; cin >> e; --e; graph[i][e]=true; } graphColoring(graph,3); }
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 2 1 1 |
Test 4
Verdict: ACCEPTED
input |
---|
5 5 5 1 5 4 |
correct output |
---|
1 1 2 1 2 |
user output |
---|
1 1 2 1 2 |
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 |
---|
1 2 1 1 2 2 1 1 1 2 |
Test 6
Verdict: WRONG ANSWER
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 1 1 2 1 2 2 1 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 |
---|
1 1 1 1 1 1 2 1 2 2 |
Test 8
Verdict: ACCEPTED
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 |
---|
1 2 1 2 1 1 2 1 2 2 |
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 |
---|
1 1 1 1 2 2 2 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 |
---|
1 1 2 1 1 1 1 1 1 1 ... 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 1 1 1 1 1 1 1 1 1 ... Truncated |
Test 12
Verdict: RUNTIME ERROR
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 |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
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 |
---|
(empty) |