QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645166#8544. Colorful Graph 2CreditWA 56ms10020kbC++171.4kb2024-10-16 17:07:292024-10-16 17:07:30

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 17:07:30]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:10020kb
  • [2024-10-16 17:07:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 3e5 + 5;
const int mod = 1e9 + 5;
int n, m;

vector<ll> v[200005];
ll co[200005];
bool vis[1000005];
void bfs(ll x) {
    queue<ll> q;
    for (auto i : v[x]) {
        q.push(i);
        co[i] = 1;
        vis[i] = 1;
    }
    while (!q.empty()) {
        ll nxt = q.front();
        q.pop();
        for (auto i : v[nxt]) {
            if (vis[i])continue;
            co[i] = co[nxt] ^ 1;
            vis[i] = 1;
            q.push(nxt);
        }
    }
}
void solve()
{
    cin >> n >> m;
    for (int i = 0;i < n;i++) {
        vis[i] = 0;
        co[i] = 0;
        v[i].clear();
    }
    for (int i = 0;i < n;i++) {
        if (i < n - 1)
            
            v[i].push_back(i + 1);
        if (i > 0)
            
            v[i].push_back(i - 1);
    }
    v[0].push_back(n-1);
    v[n-1].push_back(0);
    for (int i = 0;i < m;i++) {
        ll x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    co[1] = 0;
    vis[1] = 1;
    bfs(1);
    for (int i = 0;i < n;i++) {
        if (co[i]) cout << "B";
        else cout << "R";
    }
    cout << "\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10020kb

input:

3
3 0
4 1
1 3
6 3
0 2
2 4
4 0

output:

BRB
BRBB
BRBRRR

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 56ms
memory: 9544kb

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:

BRBRRRRRR
BRB
BRBRR
BRBRBB
BRBBRRBRB
BRB
BRBBRRR
BRBBBBR
BRBB
BRBRRR
BRBBRR
BRBRRBR
BRBBBBRR
BRB
BRBRRRRR
BRBBBBRR
BRB
BRBRRRRRRR
BRBBRRBB
BRBRRRRRRB
BRBRRRRRBB
BRBRRRRRRR
BRB
BRBRBRB
BRBBBB
BRBRRRRR
BRBB
BRBRRRR
BRBRRRRRRB
BRBRRRB
BRBRBRBB
BRBBBB
BRBRRR
BRB
BRB
BRBBBRRBB
BRBRBRR
BRBBR
BRBRRBRRRB
BR...

result:

wrong answer cycle detected (test case 1)