64722023-12-02 18:08:46CWMTitkos sorozatcpp17Wrong answer 0/4065ms24416 KiB
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main()
{
    int n;
    cin >> n;
	vector<int> res(n);
	vector<int> input;
	int last = -1;
	int lPN = n;
	vector<set<int>> g(n);
	queue<int> q;
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		input.push_back(a);
		a--;
		if (a == -2) {
			q.push(i);
		}
		else {
			g[a].insert(i);
		}
	}
	while (!q.empty())
	{
		int index = q.front();
		q.pop();
		res[index] = lPN--;
		for (size_t i = 0; i < g[index].size(); i++)
		{
			q.push(*(g[index].begin())+i);
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		cout << res[i] << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/03ms1820 KiB
2Wrong answer0/032ms12084 KiB
3Wrong answer0/13ms2232 KiB
4Wrong answer0/13ms2456 KiB
5Wrong answer0/23ms2648 KiB
6Wrong answer0/13ms3232 KiB
7Wrong answer0/13ms3176 KiB
8Wrong answer0/23ms3364 KiB
9Wrong answer0/265ms23556 KiB
10Wrong answer0/264ms23404 KiB
11Wrong answer0/264ms23664 KiB
12Wrong answer0/264ms23508 KiB
13Wrong answer0/264ms23524 KiB
14Wrong answer0/264ms23912 KiB
15Wrong answer0/264ms23868 KiB
16Wrong answer0/364ms24120 KiB
17Wrong answer0/364ms24076 KiB
18Wrong answer0/364ms24100 KiB
19Wrong answer0/361ms24328 KiB
20Wrong answer0/364ms24416 KiB
21Wrong answer0/161ms23144 KiB
22Wrong answer0/159ms23040 KiB
23Wrong answer0/157ms22436 KiB