QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414476#8544. Colorful Graph 2berarchegas#RE 0ms9744kbC++202.6kb2024-05-19 02:41:152024-05-19 02:41:17

Judging History

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

  • [2024-05-19 02:41:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:9744kb
  • [2024-05-19 02:41:15]
  • 提交

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(w, deg[w]));
                deg[w]--;
                alldg.insert(pii(w, deg[w]));
            }
            if(deg[u])
            {
                alldg.erase(pii(u, deg[u]));
                deg[u]--;
                alldg.insert(pii(u, deg[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: 0ms
memory: 9744kb

input:

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

output:

RRB
RRRB
RBRBBR

result:

ok ok (3 test cases)

Test #2:

score: -100
Runtime Error

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:


result: