QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117548#6396. Puzzle: Kusabiinstallb#WA 39ms29000kbC++143.0kb2023-07-01 16:57:102023-07-01 16:57:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 16:57:14]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:29000kb
  • [2023-07-01 16:57:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
const int N = 200005;

vector <int> G[N],p[3][N];
vector <pair <int,int> > ans;
pair <int,int> q[N]; // <type,id>
int n,dep[N];
int fail = 0;

void dfs(int u){
    for(int v : G[u]){
        dfs(v);
        auto [typ,w] = q[v];
        if(w) p[typ][u].push_back(w);
    }
    for(int i = 0;i < 3;i ++) sort(p[i][u].begin(),p[i][u].end(),[&](int x,int y){ return dep[x] < dep[y]; });
    // Tong
    q[u] = {-1,0};
    for(int i = 0;i < p[2][u].size();i += 2){
        if(i + 1 == p[2][u].size() || dep[p[2][u][i]] != dep[p[2][u][i + 1]]){
            if(!q[u].second){
                q[u] = {2,p[2][u][i]};
                i --;
                continue;
            }
        }
        else ans.push_back({p[2][u][i],p[2][u][i + 1]});
    }
    // Duan == Chang
    if(abs((int)(p[0][u].size()) - (int)(p[1][u].size())) >= 2 || (p[0][u].size() != p[1][u].size() && q[u].second)) fail = 1;
    if(p[0][u].size() == p[1][u].size()){
        for(int i = 0;i < p[0][u].size();i ++){
            if(dep[p[0][u][i]] < dep[p[1][u][i]]) ans.push_back({p[0][u][i],p[1][u][i]});
        }
    }
    // Duan < Chang
    if(p[0][u].size() + 1 == p[1][u].size()){
        int cur = 0;
        for(int i = 0;i < p[0][u].size();i ++){
            if(cur < p[1][u].size() && dep[p[0][u][i]] < dep[p[1][u][cur]]){
                ans.push_back({p[0][u][i],p[1][u][cur]});
                cur ++;
            }
            else{
                if(q[u].second) fail = 1;
                else{
                    q[u] = {1,cur};
                    cur ++;
                }
            }
        }
        if(!q[u].second) q[u] = {1,p[1][u].back()};
    }
    // Duan > Chang
    if(p[1][u].size() + 1 == p[0][u].size()){
        int cur = p[0][u].size() - 1;
        for(int i = (int)(p[1][u].size()) - 1;i >= 0;i --){
            if(cur >= 0 && dep[p[0][u][cur]] < dep[p[1][u][i]]){
                ans.push_back({p[0][u][cur],p[1][u][i]});
                cur --;
            }
            else{
                if(q[u].second) fail = 1;
                else{
                    q[u] = {0,cur};
                    cur --;
                }
            }
        }
        if(!q[u].second) q[u] = {0,p[0][u][0]};
    }
}

void solve(){
    int num = 0;
    cin >> n;
    dep[1] = 0;
    for(int i = 2;i <= n;i ++){
        int u,v; string str;
        cin >> u >> v >> str;
        // u == i
        G[v].push_back(u);
        dep[u] = dep[v] + 1;
        if(str == "Tong") p[2][u].push_back(u),num ++;
        if(str == "Duan") p[0][u].push_back(u),num ++;
        if(str == "Chang") p[1][u].push_back(u),num ++;
    }
    dfs(1);
    if(fail || (int)(ans.size()) * 2 < num) cout << "NO\n";
    else{
        cout << "YES\n";
        for(auto [u,v] : ans){
            cout << u << ' ' << v << '\n';
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 24544kb

input:

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

output:

YES
4 5
6 8

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 6ms
memory: 22508kb

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
8 9
2 6
7 5

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 5ms
memory: 23156kb

input:

2
2 1 Tong

output:

NO

result:

ok Correct.

Test #4:

score: -100
Wrong Answer
time: 39ms
memory: 29000kb

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:

NO

result:

wrong answer Jury has answer but participant has not.