QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414479#8544. Colorful Graph 2berarchegas#RE 155ms9680kbC++202.7kb2024-05-19 03:02:112024-05-19 03:02:12

Judging History

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

  • [2024-05-19 03:02:12]
  • 评测
  • 测评结果:RE
  • 用时:155ms
  • 内存:9680kb
  • [2024-05-19 03:02:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
typedef pair<int, int> pii;
const int inf=INT_MAX;
const int maxn=1e6+10;

int n, m;
vector<int> g[maxn];
int deg[maxn];

int l[maxn];
int r[maxn];

int cor[maxn];

int32_t main()
{
    ios::sync_with_stdio(0);cin.tie(0);

    int T; cin>> T;
    while(T--)
    {
        cin>> n>> m;
        int sdg = 0;
        for(int i=1; i<=n; i++)
        {
            g[i].clear();
            cor[i] = deg[i] = l[i] = r[i] = 0;
        }
        set<int> all;
        set<pii> alldg;
        for(int i=0; i<m; i++)
        {
            int u, v; cin>> u>> v;
            u++, v++;
            g[u].pb(v);
            g[v].pb(u);
            deg[u]++;
            deg[v]++;
            sdg += 2;
        }
        for(int i=1; i<=n; i++)
        {
            all.insert(i);
            alldg.emplace(deg[i], i);
        }
        deque<int> ordem;
        while(sdg)
        {
            auto it1 = alldg.begin();
            int v = (*it1).ss;
            // alldg.erase(it1);
            // all.erase(v);
            assert(deg[v] == 0);
            // u primeiro maior que v, w primeiro menor que v, indices mod n
            vector<int> caras;
            auto it = all.find(v);
            while(!deg[*it])
            {
                caras.pb(*it);
                if(it == all.begin()) it = all.end();
                it--;
            }
            int u = *it;
            it = all.find(v);
            it++; if(it == all.end()) it = all.begin();
            while(!deg[*it])
            {
                caras.pb(*it);
                it++; if(it == all.end()) it = all.begin();
            }
            int w = *it;
            for(int x: caras)
            {
                ordem.pb(x);
                l[x] = u;
                all.erase(x);
                alldg.erase(pii(deg[x], x));
            }
            assert(u != v);
            alldg.erase(pii(deg[w], w));
            deg[w]--;
            alldg.insert(pii(deg[w], w));
            alldg.erase(pii(deg[u], u));
            deg[u]--;
            alldg.insert(pii(deg[u], u));
            sdg -= 2;
        }
        int curcor = 1;
        for(int x: all)
        {
            cor[x] = curcor;
            curcor = 3 - curcor;
        }
        reverse(ordem.begin(), ordem.end());
        for(int v: ordem)
        {
            assert(l[v]);
            cor[v] = 3 - cor[l[v]];
        }
        for(int i=1; i<=n; i++)
        {
            if(cor[i] == 1) cout<< 'B';
            else cout<< 'R';
        }
        cout<< "\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9676kb

input:

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

output:

BRB
RBRB
BRRBRB

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 155ms
memory: 9680kb

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:

BRRBRBRRB
BRB
RBBRB
RBRBRB
RRBBRBBRB
BRB
RBRBBRB
BRBBBRB
RBRB
BRRBRB
RBRBRB
BRBRBRB
RBRRRBRB
BRB
BRRRRBRB
RBRRRBRB
BRB
RBRRBRBRRB
RBRRBRRB
RRRBRBRRRB
RBRBRBRBRB
RBBRBRRBRB
BRB
RRBRBRB
RBRRRB
RBBRRRRB
RBRB
RBRBRRB
RRBRBRRRRB
RRBRBRB
RBRBRBRB
RBRRRB
BRRBRB
BRB
BRB
RBRRRBBRB
RBRBBRB
BRBRB
RRBRBRBRRB
BR...

result:

ok ok (100000 test cases)

Test #3:

score: -100
Runtime Error

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:


result: