QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718341#9580. 插排串联PHarrWA 0ms3604kbC++20925b2024-11-06 20:17:472024-11-06 20:17:47

Judging History

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

  • [2024-11-06 20:17:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3604kb
  • [2024-11-06 20:17:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using i64 = long long;
using ui32 = unsigned int;

using vi = vector<int>;
using pii = pair<int,int>;


int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);

	int n;
	cin >> n;
	
	vi W(n + 1);
	W[0] = 2200;
	vi b, node;

	vector<vi> e(n + 1);

	for(int i = 1, f; i <= n; i ++) {
		cin >> f >> W[i];
		e[f].push_back(i);
		if(W[f] != -1) 
			b.push_back(W[f]), W[f] = -1, node.push_back(f);
	}

	auto dfs = [&](auto self, int x) -> void {
		if(W[x] != -1) return;
		W[x] = 0;
		for(auto y : e[x]) {
			self(self, y);
			W[x] += W[y];
		}
		return;
	};

	dfs(dfs, 0);

	ranges::sort(b);
	ranges::sort(node ,[&](const int &x, const int &y) -> bool {
		return W[x] < W[y];
	});

	for(int i = 0; i < b.size(); i ++) {
		if(b[i] >= W[node[i]]) continue;
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

4
0 1000
1 800
1 500
2 300

output:

YES

result:

ok single line: 'YES'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3
0 1000000000
0 1000000000
0 147483647

output:

NO

result:

ok single line: 'NO'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3528kb

input:

3
0 1000000000
0 1000000000
0 147483648

output:

YES

result:

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