답안 #377951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377951 2021-03-15T15:35:32 Z astoria Unique Cities (JOI19_ho_t5) C++14
0 / 100
98 ms 780 KB
#include "bits/stdc++.h"
using namespace std;

const int N=2000;
int n,m;
vector<int> adj[N];
int c[N];
int dist[N];
vector<int> atD[N];

void dfs(int x, int pa){
	for(int i : adj[x]){
		if(i==pa) continue;
		dist[i]=dist[x]+1;
		atD[dist[i]].push_back(c[i]);
		dfs(i,x);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>m;
	for(int i=0; i<n-1; i++){
		int a,b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	for(int i=1; i<=n; i++) cin>>c[i];
	
	for(int i=1; i<=n; i++){
		memset(dist,-1,sizeof(dist));
		for(int j=0; j<=n; j++) atD[j].clear();
		dist[i]=0;
		dfs(i,-1);
		unordered_set<int> uniq;
		for(int j=1; j<=n; j++){
			//if(i==2) cout<<dist[1]<<"HI"<<endl;
			if(atD[j].size()!=1) continue;
			uniq.insert(atD[j].back());
		}
		cout<<(uniq.size())<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 70 ms 620 KB Output is correct
3 Correct 55 ms 620 KB Output is correct
4 Correct 98 ms 748 KB Output is correct
5 Runtime error 3 ms 780 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 70 ms 620 KB Output is correct
3 Correct 55 ms 620 KB Output is correct
4 Correct 98 ms 748 KB Output is correct
5 Runtime error 3 ms 780 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -