QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724949#9580. 插排串联snow_mikumiku#WA 1ms5696kbC++14908b2024-11-08 15:40:102024-11-08 15:40:15

Judging History

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

  • [2024-11-08 15:40:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5696kb
  • [2024-11-08 15:40:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 10;

LL most[N], fa[N], val[N];
void solve()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> fa[i] >> most[i];
        val[fa[i]] = 0;
        val[i] = most[i];
    }

    int cnt = 0, need = 0, have = 0;
    for(int i = n; i >= 1; i--) {
        if(val[i] > most[i]) {
            cnt++;
            need = val[i], have = most[i];
        }
        val[fa[i]] += val[i];
    }
    if(cnt > 1) {
        cout << "NO";
        return;
    }

    for(int i = 1; i <= n; i++) {
        if(val[i] <= have && most[i] >= need) {
            cout << "YES";
            return;
        }
    }
    cout << "NO";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5696kb

input:

5
0 500
1 700
1 400
2 100
2 300

output:

NO

result:

ok single line: 'NO'

Test #3:

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

input:

4
0 1000
1 800
1 500
2 300

output:

NO

result:

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