QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590383#6335. Belt Conveyornathan46901 540ms33656kbC++173.2kb2024-09-25 23:45:252024-09-25 23:45:26

Judging History

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

  • [2024-09-25 23:45:26]
  • 评测
  • 测评结果:1
  • 用时:540ms
  • 内存:33656kb
  • [2024-09-25 23:45:25]
  • 提交

answer

#include "conveyor.h"

#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int>> G[100005];
int rem[100005], par[100005];
vector<int> cnt[3], target;

void dfs(int u, int p, int depth){
    par[u] = p;
    if(rem[u] > 0) {
        cerr << "!! " << u << ' ' << depth << '\n';
        cnt[depth].push_back(u);
    }
    for(pair<int,int> e: G[u]){
        int c = e.first;
        if(c != p){
            dfs(c, u, depth+1 - 3*(depth==2));
        }
    }
}

void Solve(int N, vector<int> A, vector<int> B) {
    vector<int> ans(N-1, 2), x(N-1), y(N);
    for(int i=0;i<N;i++) {
        G[i].clear();
        rem[i] = 0;
    }
    for(int i=0;i<N-1;i++){
        cerr << A[i] << ' ' << B[i] << '\n';
        G[A[i]].push_back({B[i], i+1});
        G[B[i]].push_back({A[i], -i-1});
        rem[A[i]]++;
        rem[B[i]]++;
    }
    while(true){

//        cerr << "REM: ";
//        for(int i=0;i<N;i++) cerr << rem[i] << ' ';
//        cerr << '\n';
        cnt[0].clear(); cnt[1].clear(); cnt[2].clear();
        target.clear();
        dfs(0, -1, 0);
        int s0 = cnt[0].size(), s1 = cnt[1].size(), s2 = cnt[2].size();
        if(s0 + s1 + s2 == 0) break;
        if(s0 >= max(s1, s2)) swap(target, cnt[0]);
        else if(s1 >= max(s0, s2)) swap(target, cnt[1]);
        else swap(target, cnt[2]);
        x = vector<int>(N-1, 0);
        y = vector<int>(N, 0);
        cerr << "SZ: " << target.size() << '\n';
        for(int item: target) {
            cerr << "DEBUG: " << item << ' ' << s0 << ' ' << s1 << ' ' << s2 << '\n';
            y[item] = 1;
            for(pair<int,int> e: G[item]){
                int c = e.first, idx = abs(e.second) - 1;
                if(ans[idx] != 2){
                    x[idx] = ans[idx] ^ (e.second > 0);
                }
            }
        }
//        cerr << "??? ";
//        for(int i=0;i<N-1;i++) cerr << ans[i] << ' ';
//        cerr << '\n';
        vector<int> res = Query(x, y);
        for(int u: target){
            bool ok = true, directall = (res[u] == 1);
            int pedge=0;
            for(pair<int,int> e: G[u]){
                int c = e.first, idx = abs(e.second) - 1;
                int p = par[u];
                if(directall){
                    if(ans[idx] == 2){
                        rem[u]--;
                        rem[c]--;
//                      cerr << "abc\n";
                        ans[idx] = (e.second > 0);
                    }
                    continue;
                }
                if(c != p && ans[idx] == 2 && (ok) && rem[c] > 0){
                    rem[u]--;
                    rem[c]--;
//                    cerr << "abc\n";
                    ans[idx] = (e.second < 0);
                    ok = false;
                }
                if(c == p) pedge = e.second;
            }
            if(ok && !directall){
//                cerr << "xyz\n";
                rem[u]--; rem[par[u]]--;
                ans[abs(pedge) - 1] = (pedge < 0);
            }
        }
        cerr << "REM: ";
        for(int i=0;i<N;i++) cerr << rem[i] << ' ';
        cerr << '\n';
    }
//    for(int item: ans) cerr << item << ' '; cerr << '\n';
    Answer(ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 1ms
memory: 6176kb

input:

random1
2
0
1
1
0xC321A02965AC2640

output:

Accepted: 1

result:

ok correct

Test #2:

score: 1
Accepted
time: 0ms
memory: 6252kb

input:

random1
2
1
0
0
0x8A99AD9552B2C218

output:

Accepted: 1

result:

ok correct

Test #3:

score: 1
Accepted
time: 1ms
memory: 6200kb

input:

random1
2
1
0
1
0x024D21FA307D148D

output:

Accepted: 1

result:

ok correct

Test #4:

score: 1
Accepted
time: 0ms
memory: 6488kb

input:

random1
2
0
1
0
0x3C96AB23CEB63F75

output:

Accepted: 1

result:

ok correct

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 6808kb

input:

priority
30
10 29 10 13 17 11 2 15 15 27 9 26 18 0 14 1 22 24 29 28 6 22 4 20 15 5 28 4 21
24 3 13 1 8 13 12 8 19 16 3 1 10 24 29 12 8 4 7 2 7 28 25 12 7 2 23 27 22
89058848 6377689 24189123 31671827 205117644 254374430 56016068 6819602 212866321 246625321 274047319 230485311 202854776 280075001 203...

output:

Wrong Answer [8]

result:

wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 540ms
memory: 33656kb

input:

random1
100000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

Wrong Answer [8]

result:

wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%