제출 #1361566

#제출 시각아이디문제언어결과실행 시간메모리
1361566neelamneelam19September (APIO24_september)C++20
0 / 100
11 ms3168 KiB
#include "september.h"

/*#include <vector>
using namespace  std;
int solve(int n, int m, std::vector<int> F, std::vector<std::vector<int>> S) {
	vector<vector<int>> a(n);

	for(int i=n-1; i>0;i++){
		int attached_to = f[i];
		a[attached_to].push_back(i);
		for(auto j : a[i]){ a[attached_to].push_back(j);}
	}

	for(auto i: a){
		for(auto j:i) cout<<j<<' ';
		cout<<<endl;
	}
}


solve(7,1,{-1,0,1,1,3,0,5}, {{1,2,3}});
*/
#include <bits/stdc++.h>
using namespace std;

int solve(int n, int m, std::vector<int> f, std::vector<std::vector<int>> list) {
	vector<vector<int>> a(n);

	for(int i=(n-1); i>0; i--){
		int attached_to = f[i];
		a[attached_to].push_back(i);
		for(auto j : a[i]){ a[attached_to].push_back(j);}
	}

	/*for(auto i: a){
		for(auto j:i) cout<<j<<' ';
		cout<<endl;
	}*/ 
	int ans =0;
	set<int> s;
	map<int, bool> falled;
	for(int i=0; i<n-1; i++ ){
	    int node = list[0][i];
	    falled[node] = true;
	    s.erase(node);
	    for(auto j: a[node]){
	        if(falled[j]== false){
	            s.insert(j);
	        }
	    }
	    if (s.size() ==0){ans++;}
	}
	
	cout<<ans;
	return ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…