QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788597#9580. 插排串联abovecloud#WA 16ms9196kbC++231.8kb2024-11-27 17:35:162024-11-27 17:35:17

Judging History

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

  • [2024-11-27 17:35:17]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:9196kb
  • [2024-11-27 17:35:16]
  • 提交

answer

/*** WORK : 省赛\2024大连省赛\c.cpp ***/
/*** TIME : 2024/11/27 16:37 ***/
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pb push_back
#define se second
#define fi first
#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MOD = (int) 1e9 + 7;
const int INF = LLONG_MAX;



void solve() {
    int n;
    cin >> n;
    vvi e(n+1,vi());
    vi w(n+1);
    vi root;
    for(int i=1;i<=n;i++){
        int fa;
        cin >> fa >> w[i];
        e[fa].push_back(i);
        if(fa == 0)root.pb(i);
    }
    // for(int x:e[1]){cout << x <<"  ";cout << endl;}
    vi lead,dp(n+1,0);
    multiset<int> use;
    int sum = 0;
    for(int i=1;i<=n;i++){
        if(e[i].size()==0){
            lead.pb(i);
            sum += w[i];
            dp[i] = w[i];
        }else{
            use.insert(w[i]);
        }
    }
    if(sum >= 2200){
        cout << "NO" << endl;
        exit(0);
    }
    use.insert(INF);
    auto dfs = [&](auto&& dfs,int u,int fa)->void{
        if(e[u].size()==0)return;
        for(int v:e[u]){
            if(v==fa)continue;
            dfs(dfs,v,u);
            dp[u] += dp[v];
        }
        auto f = *use.lower_bound(dp[u]);
        // cout << u << " " << dp[u] << " " << f << endl;
        if(f == INF){
            cout << "NO" << endl;
            exit(0);
        }
        use.erase(f);
    };
    // if(root.size() > 1){
    //     cout << "NO" << endl;
    //     return;
    // }
    // for(int rr : root){
        dfs(dfs,root[0],0);
    // }
    cout << "YES" << endl;    
}

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(12);
    int T = 1;
    T=1;
    while (T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3568kb

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: 3572kb

input:

4
0 1000
1 800
1 500
2 300

output:

YES

result:

ok single line: 'YES'

Test #4:

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

input:

3
0 1000000000
0 1000000000
0 147483647

output:

NO

result:

ok single line: 'NO'

Test #5:

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

input:

3
0 1000000000
0 1000000000
0 147483648

output:

NO

result:

ok single line: 'NO'

Test #6:

score: 0
Accepted
time: 16ms
memory: 9196kb

input:

64855
0 69748768
0 450926072
1 699448620
3 918617238
4 106189312
1 617660017
5 31691747
2 373080156
0 363984605
0 937885158
10 300431710
8 485372487
1 661592241
1 836709079
13 895424425
1 824052267
9 887752080
15 952380329
0 595041339
14 632034017
18 752444470
4 311747126
2 289503382
11 213029500
23...

output:

NO

result:

ok single line: 'NO'

Test #7:

score: -100
Wrong Answer
time: 13ms
memory: 7796kb

input:

48750
0 3785579
1 2060436
1 1095269
2 3527822
3 2748694
3 452943
5 427867
3 191538
8 2095981
1 3895276
10 3771233
3 3121067
10 416014
9 1443750
1 699351
8 933800
7 361157
16 423718
10 785063
11 2772134
16 3135666
2 1404821
15 417197
12 1560818
4 2709779
13 2489882
24 1070706
23 2364628
22 3451655
8 ...

output:

NO

result:

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