QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724975 | #9580. 插排串联 | snow_mikumiku# | WA | 1ms | 5624kb | C++14 | 1.0kb | 2024-11-08 15:45:57 | 2024-11-08 15:45:57 |
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], 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;
}
LL 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
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: 5608kb
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: 1ms
memory: 5624kb
input:
3 0 1000000000 0 1000000000 0 147483647
output:
YES
result:
wrong answer 1st lines differ - expected: 'NO', found: 'YES'