QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397832 | #8544. Colorful Graph 2 | comeintocalm# | WA | 110ms | 7724kb | C++17 | 836b | 2024-04-24 17:25:36 | 2024-04-24 17:25:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int n, m;
int tot, h[MAXN];
struct edge {
int to, nxt;
} e[MAXN << 1];
void add (int x, int y) {
e[++tot] = (edge) { y, h[x] };
h[x] = tot;
}
int col[MAXN];
void dfs (int x, int typ = 1) {
col[x] = typ;
for (int u = h[x]; u; u = e[u].nxt)
if (!col[e[u].to]) dfs (e[u].to, typ % 2 + 1);
}
int T;
int main() {
int i,j,k;
int x, y;
cin >> T;
while (T--) {
cin >> n >> m;
tot = 0;
for (i = 1; i <= n; ++i) h[i] = 0, col[i] = 0;
for (i = 1; i <= m; ++i)
cin >> x >> y, ++x, ++y, add (x, y), add (y, x);
dfs (1);
for (i = 2; i <= n; ++i) {
if (col[i]) continue ;
col[i] = col[i - 1] % 2 + 1;
}
for (i = 1; i <= n; ++i)
putchar (col[i] == 1 ? 'R' : 'B');
puts ("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7724kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
RBR RBRB RBRBBR
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 110ms
memory: 7660kb
input:
100000 9 6 2 0 4 6 3 6 0 6 0 7 2 6 3 0 5 2 2 4 2 0 6 3 1 5 4 1 2 4 9 6 3 1 6 4 8 1 3 6 1 6 8 6 3 0 7 4 3 0 4 0 6 4 3 1 7 4 5 1 5 0 3 1 1 4 4 1 1 3 6 3 2 4 4 0 2 0 6 3 3 0 1 3 5 3 7 4 0 5 2 5 5 1 3 5 8 5 4 1 5 1 5 0 1 3 5 7 3 0 8 5 0 2 4 6 0 6 0 3 4 0 8 5 5 1 1 4 5 0 3 1 5 7 3 0 10 7 0 2 9 2 5 8 3 9 ...
output:
RBRRRBBBR RBR RBBRR RBRBRB RBRBRBRBR RBR RRBBBRR RRBBBBR RBRB RBBRRB RRBBRR RRRRBBR RRBBBBRR RBR RBBBBRRB RRBBBBRR RBR RBBBBBBRRR RBRBRBRB RBRBRBRBRB RBRBRBRBRB RBBBBRRRBB RBR RBRBRBR RBRBRB RBBRRRRR RBRB RBBBRRR RBRBRBRBRB RBRBRBR RBRBRBRB RBRBRB RBRBBR RBR RBR RBRBRBRBR RRRBBRR RRBBR RBRBRBRBRB RR...
result:
wrong answer cycle detected (test case 39)