Submission #563260

# Submission time Handle Problem Language Result Execution time Memory
563260 2022-05-16T16:12:36 Z Karliver Paths (BOI18_paths) C++17
0 / 100
552 ms 1048576 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 << 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;
}
  
# Verdict Execution time Memory Grader output
1 Runtime error 496 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 552 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 496 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Runtime error 494 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -