QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#672221#8544. Colorful Graph 2ospoasaWA 0ms8496kbC++141.7kb2024-10-24 16:03:302024-10-24 16:03:30

Judging History

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

  • [2024-10-24 16:03:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8496kb
  • [2024-10-24 16:03:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 10;
vector <int> G[N];
void solve()
{
    int n, m;
    cin >> n >> m;
    
    vector <int> ck(n + 1);// i与i + 1
    vector <char> ans(n + 1);



    int u, v;
    for(int i = 1; i <= m; i++) {
        cin >> u >> v;
        u++, v++;
        G[u].push_back(v);
        G[v].push_back(u);
    }

   

    if(n % 2 == 0) {
        for(int i = 1; i <= n; i++) {
            if(i % 2) cout << 'R';
            else cout << 'B';
        }
        cout << '\n';

        for(int i = 1; i <= n; i++) G[i].clear();
        return;
    }

    for(int i = 1; i <= n; i++) sort(G[i].begin(), G[i].end());
    

    for(int i = 1; i <= n; i++) {
        if(!G[i].size()) continue;
        for(int j = 0; j < G[i].size() - 1; j++) {
            if(G[i][j] == G[i][j + 1] - 1) ck[G[i][j]] = 1;
            if(G[i][j] == 1 && G[i][j + 1] == n) ck[n] = 1;
        }
    }

    for(int i = 1; i <= n; i++) {
        if(!ck[i]) {
            ans[i] = ans[i + 1] = 'R';
            for(int j = 2; i + j <= n; j++) {
                if(j % 2) ans[i + j] = 'R';
                else ans[i + j] = 'B';
            }
            for(int j = 1; i - j >= 1; j++) {
                if(j % 2) ans[i - j] = 'B';
                else ans[i - j] = 'R';
            }
            for(int j = 1; j <= n; j++) cout << ans[j];
            cout << '\n';

            for(int i = 1; i <= n; i++) G[i].clear();
            return;
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8496kb

input:

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

output:

RRB
RBRB
RBRBRB

result:

wrong answer cycle detected (test case 3)