QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746316#9580. 插排串联BananaWolf#WA 2ms11252kbC++141.6kb2024-11-14 14:12:392024-11-14 14:12:39

Judging History

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

  • [2024-11-14 14:12:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11252kb
  • [2024-11-14 14:12:39]
  • 提交

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'