QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746316 | #9580. 插排串联 | BananaWolf# | WA | 2ms | 11252kb | C++14 | 1.6kb | 2024-11-14 14:12:39 | 2024-11-14 14:12:39 |
Judging History
answer
//和爸爸一起学编程真好,不过要小学四年级分流考试了,最近没时间写代码了,呜呜呜
#include<bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << (x) << endl
#define out2(x, y) cout << #x << '=' << (x) << ',' << #y << '=' << (y) << endl
#define int long long
#define lc u<<1
#define rc u<<1|1
#define pb push_back
#define vt vector
#define fi first
#define se second
#define PII pair<int,int>
#define endl "\n"
#define il inline
typedef unsigned long long ULL;
typedef long long ll;
il int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
const int P = 13331;
const int N = 200005;
int n;
vector<int> v[N];
int sz[N];
int a[N];
vt<int> gl;
vt<int> bg;
void dfs(int u){
if(v[u].size()==0){
sz[u]+=a[u];
return;
}
gl.push_back(a[u]);
for(auto p:v[u]){
dfs(p);
sz[u]+=sz[p];
}
bg.push_back(sz[u]);
}
void solve(){
cin >> n;
for(int i = 1;i <= n;i++){
int f,v1;
cin >> f >> v1;
v[f].pb(i);
a[i] = v1;
}
dfs(1);
sort(bg.rbegin(),bg.rend());
sort(gl.rbegin(),gl.rend());
for(int i = 0;i < bg.size();i++){
//cout << bg[i] << " " << gl[i] << endl;
if(bg[i] > gl[i]){
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
signed main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int times = 1;
//cin >> times;
while(times--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10016kb
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: 2ms
memory: 11252kb
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: 2ms
memory: 10384kb
input:
4 0 1000 1 800 1 500 2 300
output:
YES
result:
ok single line: 'YES'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 11068kb
input:
3 0 1000000000 0 1000000000 0 147483647
output:
YES
result:
wrong answer 1st lines differ - expected: 'NO', found: 'YES'