QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560074#6396. Puzzle: KusabichimeraWA 65ms10308kbC++172.1kb2024-09-12 12:01:582024-09-12 12:01:58

Judging History

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

  • [2024-09-12 12:01:58]
  • 评测
  • 测评结果:WA
  • 用时:65ms
  • 内存:10308kb
  • [2024-09-12 12:01:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>

vector<vector<ll>> adj(100000);
vector<char> type(100000, '-');


bool valid = true;
vector<array<ll,2>> out;

vector<tuple<char,ll,ll>> treecur(ll n, ll p, ll d) {
    vector<tuple<char,ll,ll>>  meeting;
    if(type[n] != '-') meeting.push_back({type[n], d, n});
    for(auto a: adj[n]) {
        if(a != p) {
            for(auto x: treecur(a,n,d+1)) meeting.push_back(x);
        }
    }


    if(meeting.size() <= 1) {
        return meeting;
    }

    vector<tuple<char,ll,ll>> tout = {};

    map<ll,ll> ts = {};

    set<pll> cs;

    vector<pll> ds;

    for(auto x: meeting) {
        char c = get<0>(x);
        ll d = get<1>(x), n = get<2>(x);
        
        if(c == 'T') {
            if(ts.find(d) == ts.end()) ts[d] = n;
            else {
                out.push_back({n, ts[d]}); ts.erase(d);
            }
        }


        if(c == 'C') {
            cs.insert({d,n});
        }

        if(c == 'D') ds.push_back({d,n});
    }

    sort(ds.rbegin(), ds.rend());

    for(auto d: ds) {
        // match to c with greater depth
        auto it = cs.upper_bound({d.first, -1});
        if(it == cs.end()) {
            tout.push_back({'D',d.first,d.second});
        } else {
            out.push_back({d.second, (*it).second});
            cs.erase(it);
        }
    }

    for(auto c: cs) tout.push_back({'C',c.first,c.second});
    for(auto t: ts) tout.push_back({'T',t.first,t.second});

    
    if(tout.size() > 1) {
        valid = false;
        tout = {};
    }
    return tout;
}

int main() {
    ll N; cin >> N;
    
    for(ll i = 0; i < N-1; i++) {
        ll a, b; cin >> a >> b; a--; b--;
        adj[a].push_back(b); adj[b].push_back(a);
        string S; cin >> S;
        type[a]=S[0];
    }

    auto reslt = treecur(0,-1,0);
    valid = valid && !reslt.size();
    if(valid) {
        cout << "YES\n";
        for(auto xy: out) {
            cout << xy[0]+1 << " " << xy[1]+1 << "\n";
        }
    } else {
        cout << "NO\n";
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
2 1 -
3 1 -
4 2 Tong
5 2 Tong
6 3 Duan
7 3 -
8 7 Chang

output:

YES
5 4
6 8

result:

ok Correct.

Test #2:

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

input:

10
2 1 Duan
3 2 Duan
4 2 -
5 4 Chang
6 2 Chang
7 1 Duan
8 6 Tong
9 6 Tong
10 3 Chang

output:

YES
3 10
9 8
2 6
7 5

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 5184kb

input:

2
2 1 Tong

output:

NO

result:

ok Correct.

Test #4:

score: -100
Wrong Answer
time: 65ms
memory: 10308kb

input:

100000
2 1 Duan
3 1 Duan
4 3 -
5 4 Duan
6 3 -
7 4 Duan
8 4 -
9 8 -
10 7 Duan
11 9 -
12 7 Duan
13 7 Duan
14 8 Duan
15 13 -
16 10 Duan
17 11 Duan
18 12 -
19 1 Duan
20 5 Duan
21 4 Duan
22 14 Duan
23 16 -
24 22 Duan
25 16 Duan
26 13 -
27 13 -
28 17 -
29 5 Duan
30 22 -
31 23 -
32 9 Duan
33 5 -
34 30 Duan...

output:

YES
56115 46666
38802 88119
10006 93143
76473 31531
15988 42604
30148 6569
2008 11412
46703 64525
70618 71289
47748 81204
46131 42353
20514 97634
82155 83516
62410 66867
9975 15712
3205 4978
5622 83026
10902 48783
30893 82167
65878 93809
66951 33377
66936 94549
64411 79128
22475 8453
36857 54702
905...

result:

wrong answer Pair 46131-42353 symbol not satisfied.