QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414478#8544. Colorful Graph 2berarchegas#WA 145ms9740kbC++202.6kb2024-05-19 02:45:442024-05-19 02:45:45

Judging History

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

  • [2024-05-19 02:45:45]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:9740kb
  • [2024-05-19 02:45:44]
  • 提交

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;
        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]++;
        }
        for(int i=1; i<=n; i++)
        {
            all.insert(i);
            alldg.emplace(deg[i], i);
        }
        deque<int> ordem;
        while(all.size() > 3)
        {
            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
            auto it = all.upper_bound(v); if(it == all.end()) it = all.begin();
            int u = *it;
            it = all.lower_bound(v); if(it == all.begin()) it = all.end();
            int w = *--it;
            l[v] = w, r[v] = u;
            ordem.pb(v);
            if(deg[w])
            {
                alldg.erase(pii(deg[w], w));
                deg[w]--;
                alldg.insert(pii(deg[w], w));
            }
            if(deg[u])
            {
                alldg.erase(pii(deg[u], u));
                deg[u]--;
                alldg.insert(pii(deg[u], u));
            }
        }
        assert(all.size() == 3);
        for(int x: all)
            ordem.pb(x);
        reverse(ordem.begin(), ordem.end());
        int primeiro = ordem.front();
        // cout<< primeiro<< "\n";
        // for(int x: ordem)
        // {
        //     cout<< x<< " chama "<< (l[x] ? l[x] : primeiro)<< "\n";
        // }
        cor[primeiro] = 1;
        ordem.pop_front();
        for(int v: ordem)
        {
            int u = (l[v] ? l[v] : primeiro);
            cor[v] = 3 - cor[u];
        }
        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: 2ms
memory: 9620kb

input:

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

output:

RRB
RRRB
RBBRRB

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 145ms
memory: 9740kb

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:

RBBRBRBRB
RRB
RBRRB
RRBRRB
RRBBRBRRB
RRB
RBRBRRB
RBRRRRB
RRRB
RBBRRB
RBRRRB
RBRBRRB
RBRRRRRB
RRB
RBBBBRRB
RBRRRRRB
RRB
RBRRRBRBRB
RRBBRBRB
RRRRBRBBRB
RRBRBRBRRB
RBBRBRRRRB
RRB
RRBRRRB
RRBBRB
RBRBBBRB
RRRB
RBRRBRB
RRRBRBBBRB
RRRBRRB
RRBRBRRB
RRBBRB
RBBRRB
RRB
RRB
RRBBBRRRB
RBRBRRB
RBRRB
RRBRBRRBRB
RB...

result:

ok ok (100000 test cases)

Test #3:

score: -100
Wrong Answer
time: 117ms
memory: 9740kb

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:

RRBBRRRB
RBRRBRB
RRRB
RRRRRRRB
RRB
RRB
RRRRRRRB
RRB
RBRBBRRRB
RRRRRRB
RBRRRB
RBRBRRB
RBRRB
RRRRRRBRRB
RRRRB
RRB
RBBRRRRRB
RRB
RRBRB
RRRRRRRRB
RRRRRB
RRRRRRRB
RRRRB
RRBRRRRB
RBRRB
RBRRRRRB
RRRRBRB
RBBRRRRRRB
RBBRRBRRB
RRRBRRRRB
RRRRRB
RRRRRRB
RRB
RRRRRRRRRB
RBRRRB
RRRBRRRRB
RRRRB
RRRRRRRRRB
RBRRB
RBR...

result:

wrong answer cycle detected (test case 1)