QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438212#8544. Colorful Graph 2ucup-team045#WA 166ms3776kbC++202.4kb2024-06-10 13:53:502024-06-10 13:53:50

Judging History

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

  • [2024-06-10 13:53:50]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:3776kb
  • [2024-06-10 13:53:50]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<set>
#include<cassert>
#include<algorithm>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n, m;
        cin >> n >> m;
        vector<vector<int> > g(n);
        vector<pair<int, int> > edge(m);
        for(int i = 0; i < m; i++){
            int a, b;
            cin >> a >> b;
            g[a].push_back(b);
            g[b].push_back(a);
            edge[i] = {a, b};
        }
        for(int i = 0; i < n; i++){
            int a = i, b = (i + 1) % n;
            g[a].push_back(b);
            g[b].push_back(a);
            edge.push_back({a, b});
        }

        vector<int> color(n);

        vector<int> d(n);
        for(auto [a, b] : edge){
            d[a] += 1;
            d[b] += 1;
        }
        vector<bool> del(n);

        vector<int> v;

        for(int i = 0; i < n; i++){
            if (d[i] <= 2){
                del[i] = true;
                v.push_back(i);
            }
        }

        vector<int> order;
        while(!v.empty()){
            sort(v.begin(), v.end());
            int pos = 0;
            for(int i = 0; i < v.size(); i++){
                if ((v[i] + 1) % n != v[(i + 1) % v.size()]){
                    pos = (i + 1) % v.size();
                    break;
                }
            }
            rotate(v.begin(), v.begin() + pos, v.end());
            order.insert(order.end(), v.begin(), v.end());
            vector<int> nv;
            for(auto x : v){
                for(auto j : g[x]){
                    if (--d[j] <= 2 and !del[j]){
                        del[j] = true;
                        nv.push_back(j);
                    }
                }
            }
            v.swap(nv);
        }

        reverse(order.begin(), order.end());
        assert(order.size() == n);
        set<int> s;
        for(auto x : order){
            if (!s.empty()){
                auto it = s.lower_bound(x);
                if (it == s.end()) it = s.begin();
                color[x] = color[*it] ^ 1;
            }
            s.insert(x);
        }
        for(auto x : color) cout << (x ? 'R' : 'B');
        cout << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

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

output:

BRB
RBBR
BRBBRR

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 166ms
memory: 3776kb

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:

RRBBBBRBB
BRB
BRBBR
RBBBRR
RBRBBBRBR
BRB
BRRBRBR
RBBRBRB
RBBR
BRBBRR
BBBRBR
BRBRRBR
RBBRBRRB
BRB
BBRBRBRR
RBBRBRRB
BRB
RRBRBRRRBR
RBRBBBRR
RBRBBBRBRR
BRBBRRBRRB
RBRBRBRBBR
BRB
RBBBRBR
RBRBRR
RRBBRBRR
RBBR
BBRBBRB
BRBRRRBRRR
BRBRRBR
RBRRBBRR
RBRBRR
BRBBRR
BRB
BRB
RBBRBRBRR
RBRRBRB
RBRBB
RBRRRBBRBR
RB...

result:

ok ok (100000 test cases)

Test #3:

score: -100
Wrong Answer
time: 135ms
memory: 3544kb

input:

100000
8 4
5 3
5 1
6 1
3 1
7 4
5 0
4 1
4 0
3 1
4 0
8 1
4 7
3 0
3 0
8 1
1 3
3 0
9 4
6 0
3 0
3 1
5 0
7 0
6 2
4 2
0 4
7 3
0 3
0 4
1 3
5 1
3 0
10 4
6 8
5 2
1 5
5 3
5 1
1 4
3 0
9 3
5 0
8 6
6 0
3 0
5 2
1 3
1 4
9 0
6 1
4 2
8 1
1 3
5 0
8 2
3 1
6 1
5 1
3 0
8 3
3 0
7 4
7 5
7 2
5 3
1 3
10 3
8 0
0 3
8 5
9 4
3 0...

output:

RBRBBRRB
RBBRBBB
RBRB
BRBRBRBR
BRB
BRB
RBBRRBRB
BRB
BRBRRBRBR
BRBRBRB
BRBBRR
BBBRRBR
BRBRR
BRBBBRRRBR
RBRBR
BRB
BBRBRBRBR
BRB
RBRBR
BRBRBRBRB
BRBBRR
RBBRRBRB
BRBRB
RBRBRBRB
BRBRR
RRBRBBBR
RBRBBRB
BRBRRBRBRR
BRBRBRBBR
RBRBRBRBB
RBRBRB
BRBRRBR
BRB
RBBRBRBRRB
RBRBRB
RBRBBRBBB
BRBRB
BRBRBBRBBR
BRBBR
BRB...

result:

wrong answer cycle detected (test case 1636)