Submission #365362

# Submission time Handle Problem Language Result Execution time Memory
365362 2021-02-11T14:15:09 Z FatihSolak Mag (COCI16_mag) C++17
12 / 120
509 ms 142272 KB
#include <bits/stdc++.h>
#define N 1000005
using namespace std;
vector<int> adj[N];
int arr[N];
int down[N];
int up[N];
int maxi = 0,mini = 1e9;
void dfs(int v,int p){
	for(auto u:adj[v]){
		if(u == p)continue;
		dfs(u,v);
		if(arr[u] == 1){
			down[v] += down[u] + 1;
		}
	}
}
void dfs2(int v,int p){
	if(arr[p] == 1){
		up[v] = up[p] + 1;
		if(arr[v] == 1){
			up[v] = max(up[v], down[p] - down[v]);
		}
		else up[v] = max(up[v], down[p]+1);
	}
	for(auto u:adj[v]){
		if(u == p)continue;
		dfs2(u,v);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;
	cin >> n;
	for(int i=1;i<n;i++){
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i=1;i<=n;i++){
		if(arr[i] == 1){
			maxi = max(maxi,2*(1+down[i]+up[i]));
		}
		if(arr[i] == 2){
			maxi = max(maxi,down[i]+up[i]);
		}
		mini = min(mini,arr[i]);
	}
	if(maxi == 0){
		cout << mini << "/"<<1;
	}
	else if(maxi & 1){
		cout << 2 << "/" << maxi;
	}
	else cout << 1 << "/" << maxi/2;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23916 KB Output is correct
2 Correct 16 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 378 ms 89716 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 509 ms 142272 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 66668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 376 ms 67712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 28268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 402 ms 64356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 408 ms 67308 KB Output is correct
2 Incorrect 398 ms 46068 KB Output isn't correct