QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748857#9580. 插排串联hanmxWA 0ms3824kbC++171.1kb2024-11-14 21:42:372024-11-14 21:42:37

Judging History

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

  • [2024-11-14 21:42:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-11-14 21:42:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
using u64=unsigned long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<vector<int>> g(n+1);
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        g[x].push_back(i);
        cin>>a[i];        
    }
    multiset<int> s;
    auto dfs1=[&](auto dfs1,int x)->void{
        if(g[x].size()!=0) s.insert(a[x]);
        for(auto y:g[x]){
            dfs1(dfs1,y);
        }
    };
    dfs1(dfs1,0);
    int f=0;
    vector<int> siz(n+1);
    auto dfs=[&](auto dfs,int x)->void{
        if(!g[x].size()){
            siz[x]=a[x];
            return;
        }
        for(auto y:g[x]){
            dfs(dfs,y);
            siz[x]+=siz[y];
        }
        if(x==0) return;
        auto u=s.lower_bound(siz[x]);
        if(u==s.end()){
            f=1;
        }
        else s.erase(*u);
    };
    dfs(dfs,0);
    if(f) cout<<"NO"<<"\n";
    else cout<<"YES"<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3504kb

input:

5
0 500
1 700
1 400
2 100
2 200

output:

YES

result:

ok single line: 'YES'

Test #2:

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

input:

5
0 500
1 700
1 400
2 100
2 300

output:

NO

result:

ok single line: 'NO'

Test #3:

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

input:

4
0 1000
1 800
1 500
2 300

output:

YES

result:

ok single line: 'YES'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3824kb

input:

3
0 1000000000
0 1000000000
0 147483647

output:

YES

result:

wrong answer 1st lines differ - expected: 'NO', found: 'YES'