Submission #167566

# Submission time Handle Problem Language Result Execution time Memory
167566 2019-12-09T02:30:01 Z puppies_and_rainbows Mag (COCI16_mag) C++14
36 / 120
1713 ms 172964 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
vector<int> adj[1000005];
int cac[1000005];
int cac2[10000005];
int a[1000005];
int ans=0, ans2=0;
bool hv=false;

void dfs(int node, int fa)
{
	pair<int, int> ok={0, 0};
	for(auto i:adj[node])
	{
		if(i==fa) continue;
		dfs(i, node);
		if(cac[i]>=cac[ok.first])
		{
			ok.second=ok.first;
			ok.first=i;
		}
		else if(cac[i]>cac[ok.second])
		{
			ok.second=i;
		}
	}
	if(a[node]==1)
	{
		ans=max(ans, cac[ok.first]+cac[ok.second]+1);
		cac[node]=cac[ok.first]+1;
		for(auto i:adj[node])
		{
			if(i==fa) continue;
			cac2[node]=max(cac2[node], cac2[i]+1);
			if(i==ok.first)
			{
				ans2=max(ans, cac[ok.second]+cac2[i]+1);
			}
			else
			{
				ans2=max(ans2, cac[ok.first]+cac2[i]+1);
			}
		}
	}
	else if(a[node]==2)
	{
		ans2=max(ans2, cac[ok.first]+1);
		cac2[node]=cac[ok.first]+1;
	}
	ans=max(ans, cac[node]);
	ans2=max(ans2, cac2[node]);
}

signed main()
{
	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>>a[i];
		if(a[i]==1) hv=true;
	}
	if(!hv)
	{
		cout<<*min_element(a+1, a+n+1)<<"/1";
		return 0;
	}
	dfs(1, 1);
	if(ans2>2*ans)
	{
		if(ans2%2==0)
		{
			cout<<"1/"<<ans2/2;
		}
		else
		{
			cout<<"2/"<<ans2;
		}
	}
	else
	{
		cout<<"1/"<<ans;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23672 KB Output is correct
2 Correct 24 ms 23804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1349 ms 106852 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1689 ms 171228 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1537 ms 78752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1593 ms 81120 KB Output is correct
2 Correct 231 ms 30328 KB Output is correct
3 Correct 1713 ms 172964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 189 ms 31224 KB Output is correct
2 Incorrect 1529 ms 80852 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1460 ms 77408 KB Output is correct
2 Incorrect 1589 ms 79764 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1539 ms 81008 KB Output is correct
2 Correct 1039 ms 56568 KB Output is correct