QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728681#9580. 插排串联bruteforce_WA 1ms3852kbC++20913b2024-11-09 15:39:362024-11-09 15:39:46

Judging History

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

  • [2024-11-09 15:39:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3852kb
  • [2024-11-09 15:39:36]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+7,inf=1e18,mod=998244353;
vector<int> a,siz;
vector<vector<int>> e;
//vector<int> f(1);
void dfs(int u)
{
	for(auto v:e[u])
	{
		dfs(v);
		siz[u]+=siz[v];
	}
	if(e[u].empty())
		siz[u]=a[u];
//	if(u)
//	{
//		f.push_back(siz[u]);
////		g.push_back(a[u])
//	}
}
void O_o()
{
	int n;
	cin>>n;
	a.assign(n+1,0);
	siz.assign(n+1,0);
	e.assign(n+1,vector<int>());
	for(int i=1; i<=n; i++)
	{
		int x,v;
		cin>>x>>a[i];
		e[x].push_back(i);
	}
	dfs(0);
	sort(a.begin()+1,a.end());
	sort(siz.begin()+1,siz.end());
	for(int i=1; i<=n; i++)
		if(a[i]<siz[i])
		{
			cout<<"NO\n";
			return;
		}
	cout<<"YES\n";
}
signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout<<fixed<<setprecision(12);
	int T=1;
//	cin>>T;
	while(T--)
	{
		O_o();
	}
}









Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3652kb

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

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: 1ms
memory: 3548kb

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

input:

3
0 1000000000
0 1000000000
0 147483647

output:

YES

result:

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