답안 #518961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518961 2022-01-25T09:30:25 Z fatemetmhr Unique Cities (JOI19_ho_t5) C++17
4 / 100
157 ms 476 KB
//  ~Be name khoda~  //

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define cl       clear
#define endll    '\n'

const int maxn  =  1e6   + 10;
const int maxn5 =  2e3   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  2e18;

bool mark[maxn5];
int cnt[maxn5], a[maxn5], h[maxn5];
vector <int> adj[maxn5];

inline void dfs(int v){
	mark[v] = true;
	cnt[h[v]]++;
	for(auto u : adj[v]) if(!mark[u]){
		h[u] = h[v] + 1;
		dfs(u);
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n, m; cin >> n >> m;
	for(int i = 0; i < n - 1; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++){
		h[i] = 0;
		memset(mark, false, sizeof mark);
		memset(cnt, 0, sizeof cnt);
		dfs(i);
		memset(mark, false, sizeof mark);
		int ans = 0;
		for(int j = 0; j < n; j++)
			if(i != j && cnt[h[j]] == 1){
				ans += (!mark[a[j]]);
				mark[a[j]] = true;
			}
		cout << ans << '\n';
	}
}















# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 79 ms 424 KB Output is correct
3 Correct 23 ms 432 KB Output is correct
4 Correct 77 ms 444 KB Output is correct
5 Correct 93 ms 432 KB Output is correct
6 Correct 104 ms 460 KB Output is correct
7 Correct 93 ms 460 KB Output is correct
8 Correct 82 ms 436 KB Output is correct
9 Correct 99 ms 332 KB Output is correct
10 Correct 93 ms 428 KB Output is correct
11 Correct 94 ms 428 KB Output is correct
12 Correct 52 ms 436 KB Output is correct
13 Correct 115 ms 460 KB Output is correct
14 Correct 90 ms 460 KB Output is correct
15 Correct 88 ms 460 KB Output is correct
16 Correct 44 ms 456 KB Output is correct
17 Correct 80 ms 464 KB Output is correct
18 Correct 83 ms 460 KB Output is correct
19 Correct 95 ms 432 KB Output is correct
20 Correct 157 ms 460 KB Output is correct
21 Correct 104 ms 464 KB Output is correct
22 Correct 86 ms 332 KB Output is correct
23 Correct 97 ms 336 KB Output is correct
24 Correct 93 ms 436 KB Output is correct
25 Correct 94 ms 432 KB Output is correct
26 Correct 60 ms 452 KB Output is correct
27 Correct 111 ms 476 KB Output is correct
28 Correct 83 ms 460 KB Output is correct
29 Correct 86 ms 460 KB Output is correct
30 Correct 48 ms 332 KB Output is correct
31 Correct 84 ms 476 KB Output is correct
32 Correct 78 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 79 ms 424 KB Output is correct
3 Correct 23 ms 432 KB Output is correct
4 Correct 77 ms 444 KB Output is correct
5 Correct 93 ms 432 KB Output is correct
6 Correct 104 ms 460 KB Output is correct
7 Correct 93 ms 460 KB Output is correct
8 Correct 82 ms 436 KB Output is correct
9 Correct 99 ms 332 KB Output is correct
10 Correct 93 ms 428 KB Output is correct
11 Correct 94 ms 428 KB Output is correct
12 Correct 52 ms 436 KB Output is correct
13 Correct 115 ms 460 KB Output is correct
14 Correct 90 ms 460 KB Output is correct
15 Correct 88 ms 460 KB Output is correct
16 Correct 44 ms 456 KB Output is correct
17 Correct 80 ms 464 KB Output is correct
18 Correct 83 ms 460 KB Output is correct
19 Correct 95 ms 432 KB Output is correct
20 Correct 157 ms 460 KB Output is correct
21 Correct 104 ms 464 KB Output is correct
22 Correct 86 ms 332 KB Output is correct
23 Correct 97 ms 336 KB Output is correct
24 Correct 93 ms 436 KB Output is correct
25 Correct 94 ms 432 KB Output is correct
26 Correct 60 ms 452 KB Output is correct
27 Correct 111 ms 476 KB Output is correct
28 Correct 83 ms 460 KB Output is correct
29 Correct 86 ms 460 KB Output is correct
30 Correct 48 ms 332 KB Output is correct
31 Correct 84 ms 476 KB Output is correct
32 Correct 78 ms 468 KB Output is correct
33 Runtime error 1 ms 460 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -