QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724950 | #9580. 插排串联 | snow_mikumiku# | WA | 0ms | 3652kb | C++14 | 981b | 2024-11-08 15:41:04 | 2024-11-08 15:41:05 |
Judging History
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;
}
else if(cnt == 0) {
cout << "YES";
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: 3592kb
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: 3592kb
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: 3652kb
input:
3 0 1000000000 0 1000000000 0 147483647
output:
YES
result:
wrong answer 1st lines differ - expected: 'NO', found: 'YES'