답안 #563261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563261 2022-05-16T16:13:55 Z Karliver Paths (BOI18_paths) C++17
0 / 100
7 ms 7764 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 3e5 + 10;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define sz(x) int(x.size())
template<typename T> void ckmi(T &a, T b) {
	a = (b < a ? b : a);
}

int n, m ,k;
vector<int> g[N];
long long res = 0;
int A[N];
void dfs(int v, int p = -1, int mask = 0) {
	mask |= (1 << A[v]);
	res += 1;
	for(auto c : g[v]) {
		if(c == p || (mask & (1 << A[c])))continue;
		dfs(c, v, mask);
	}
}
void test_case() {
	
	cin >> n >> m >> k;
	
	for(int j = 0;j < n;++j) cin >> A[j], --A[j];
	for(int i = 0;i < n - 1;++i) {
		int a, b;
		cin >> a >> b;
		--a;--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	for(int j = 0;j < n;++j) {
		dfs(j);
		res--;
	}
	
	cout << res << '\n';
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt;
	tt = 1;
	//cin >> tt;
	
	for(int p = 1;p <= tt;++p) {
		//cout << "Case #" << p << ": ";
		test_case();
	}
	
		
	return 0;
}
  
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7352 KB Output is correct
2 Incorrect 4 ms 7380 KB Output isn't correct
3 Halted 0 ms 0 KB -