QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528586#6396. Puzzle: KusabiOneWan#WA 18ms9716kbC++232.9kb2024-08-23 16:34:412024-08-23 16:34:41

Judging History

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

  • [2024-08-23 16:34:41]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:9716kb
  • [2024-08-23 16:34:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
vector<int>v[1000005];
int type[100005]; //1 tong 2 duan 3 chang
pair<int,int>hv[100005];
int dep[100005];
set<pair<int,int>>res;
bool cmp(int x,int y){
    return dep[x]<dep[y];
}
void dfs(int u,int fa){
    dep[u]=dep[fa]+1;
    vector<int>t;
    vector<int>d;
    vector<int>c;
     if(type[u]!=0){
        if(type[u]==1){
            t.push_back(u);
        }else if(type[u]==2){
            d.push_back(u);
        }else if(type[u]==3){
            c.push_back(u);
        }
    }
    for(auto x:v[u]){
        if(x==fa)continue;
        dfs(x,u);
        if(hv[x].first!=0){
            if(hv[x].first==1){
                t.push_back(hv[x].second);
            }else if(hv[x].first==2){
                d.push_back(hv[x].second);
            }else if(hv[x].first==3){
                c.push_back(hv[x].second);
            }
        }
    }
    sort(begin(c),end(c),cmp);
    sort(begin(d),end(d),cmp);
    sort(begin(t),end(t),cmp);
    int less=0;
    int lessid=0;
    for(int i=0;i<t.size();i++){
        if(i+1<t.size()&&dep[t[i]]==dep[t[i+1]]){
            res.insert({t[i],t[i+1]});
            i++;
        }else{
            less++;
            hv[u].first=1;
            hv[u].second=t[i];
        }
    }
    if(less>=2){;
        cout<<"NO\n";
        exit(0);
    }
    int l=0,r=0;
    for(l=0,r=0;l<c.size();l++){
        while(r<d.size()&&dep[c[l]]<=dep[d[r]]){
            if(hv[u].first!=0){
                cout<<"No\n";
                exit(0);
            }else{
                hv[u].first=2;
                hv[u].second=d[r];
            }
            r++;
        }
        if(r<d.size()){
            res.insert({c[l],d[r]});
            r++;
        }else{
            if(hv[u].first!=0){
                cout<<"No\n";
                exit(0);
            }else{
              
                hv[u].first=3;
                hv[u].second=c[l];
            }
        }
    }
    for(r;r<d.size();r++){
        if(hv[u].first!=0){
                cout<<"No\n";
                exit(0);
            }else{
                hv[u].first=2;
                hv[u].second=d[r];
            }
    }

    if(u==1&&hv[u].first!=0){
        cout<<"No\n";
        exit(0);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n-1;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        string sx;
        cin>>sx;
        if(sx=="Tong"){
            type[x]=1;
        }else if(sx=="Duan"){
            type[x]=2;
        }else if(sx=="Chang"){
            type[x]=3;
        }else{
            type[x]=0;
        }
    }

    dfs(1,0);
    cout<<"YES\n";
    for(auto [x,y]:res){
        cout<<x<<" "<<y<<'\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3864kb

input:

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

output:

YES
4 5
8 6

result:

ok Correct.

Test #2:

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

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

result:

ok Correct.

Test #3:

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

input:

2
2 1 Tong

output:

No

result:

ok Correct.

Test #4:

score: -100
Wrong Answer
time: 18ms
memory: 9716kb

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.