QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724963#9580. 插排串联snow_mikumiku#WA 1ms5708kbC++141.0kb2024-11-08 15:43:402024-11-08 15:43:40

Judging History

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

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

answer

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

LL most[N], fa[N], val[N], ck[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];
        ck[fa[i]] = 1;
    }

    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;
    }

    else if(cnt == 0) {
        cout << "YES";
        return;
    }

    for(int i = 1; i <= n; i++) {
        if(!ck[i]) continue;
        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;
}

详细

Test #1:

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

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

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

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

input:

3
0 1000000000
0 1000000000
0 147483647

output:

YES

result:

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