53692023-04-26 19:05:32kohumarkKülönböző katicákcpp17Wrong answer 0/100600ms130792 KiB
#include <iostream>
#include <vector>
#include <set>
using namespace std;
vector<vector<int>> con;
set<int> act; set<int> visited;
bool van=false;

void actual(int i, int p[], int l){
	visited.insert(i);
	set<int> now;
	for(auto it=con[i].begin(); it!=con[i].end(); it++){
		if(p[*it]!=-1){
			int a=-l;
			while(a!=l){
				if(p[*it]+a>=0) now.insert(p[*it]+a);
				a+=2;
			}
		}
		if(!visited.count(*it)) actual(*it, p, l+1);
	}
	if(!van){
		for(auto it=now.begin(); it!=now.end(); it++) act.insert(*it);
		van=true;
	}
	//for(auto it=now.begin(); it!=now.end(); it++) cout << *it << '\n';
	else for(auto it=act.begin(); it!=act.end(); it++) if(!now.count(*it)){act.erase(*it); it=act.begin(); if(act.size()==0) break;}
}

int solve(int i, int p[]){
	//cout << '\n' << i << '\n';
	visited.insert(i);
	for(auto it=con[i].begin(); it!=con[i].end(); it++){
		if(p[*it]!=-1){act.insert(p[*it]+1); act.insert(abs(p[*it]-1));}
		if(act.size()>0) van=true;
		actual(*it, p, 2);
	}
	if(act.size()==0) return -1;
	int x=*(act.begin()); act.clear(); visited.clear();
	return x;
}

int main(){
	bool ok=true;
	int n; cin >> n;
	int p[n]; //f[n];
	con.assign(n, vector<int>());
	for(int i=0; i<n; i++){
		int x; cin >> x;
		if(x!=0){con[i].push_back(x-1); con[x-1].push_back(i);}
	}
	for(int i=0; i<n; i++) cin >> p[i];
	for(int i=0; i<n; i++){
		if(p[i]==-1) p[i]=solve(i, p);
		if(p[i]==-1){ok=false; break;}
	}
	if(1){
		cout << "IGEN\n";
		for(int i=0; i<n; i++){
			cout << p[i] << ' ';
		}
	}
	else cout << "NEM";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Wrong answer3ms2060 KiB
3Time limit exceeded600ms13536 KiB
subtask20/10
4Wrong answer108ms18748 KiB
5Wrong answer120ms20940 KiB
6Wrong answer134ms22428 KiB
7Wrong answer145ms24392 KiB
subtask30/15
8Runtime error236ms130792 KiB
9Runtime error237ms130548 KiB
10Runtime error240ms130316 KiB
11Runtime error230ms130152 KiB
12Runtime error245ms129916 KiB
13Runtime error232ms129872 KiB
14Wrong answer143ms51704 KiB
subtask40/35
15Wrong answer4ms4544 KiB
16Wrong answer4ms4640 KiB
17Wrong answer4ms4492 KiB
18Wrong answer4ms4748 KiB
19Wrong answer4ms4892 KiB
20Wrong answer3ms4780 KiB
21Wrong answer4ms4932 KiB
22Wrong answer4ms5040 KiB
subtask50/40
23Wrong answer134ms23968 KiB
24Time limit exceeded552ms16404 KiB
25Wrong answer317ms27692 KiB
26Wrong answer144ms24444 KiB
27Wrong answer381ms26108 KiB
28Time limit exceeded555ms16296 KiB
29Wrong answer126ms25532 KiB
30Wrong answer142ms25380 KiB
31Time limit exceeded577ms17904 KiB
32Time limit exceeded518ms16776 KiB
33Time limit exceeded569ms15564 KiB