Submission #133429

# Submission time Handle Problem Language Result Execution time Memory
133429 2019-07-20T15:43:54 Z tdwn Mag (COCI16_mag) C++17
24 / 120
1743 ms 176596 KB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1000100;
vector<int>g[maxn];
ll arr[maxn], n;
ll dp[maxn], result;

void dfs(int node, int p) {
	vector<ll>v;
	for(int i:g[node]) {
		if(i != p) {
			dfs(i, node);

			if(arr[node] == 1 && arr[i] == 1) {
				v.pb(dp[i]);
			}
		}
	}

	sort(v.rbegin(), v.rend());

	if(arr[node] != 1) return;

	if(v.size() == 0) {
		dp[node] = 1LL;
		result = max(result, dp[node]);
	}

	if(v.size() == 1) {
		dp[node] = 1 + v[0];
		result = max(result, dp[node]);
	}
	else if(v.size() > 1){
		dp[node] = 1 + v[0];
		result = max(result, v[0] + v[1] + 1);
	}
}

int main() {
	cin>>n;
	ll a, b;
	for(int i=0;i<n-1;i++) {
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}

	ll minval = LLONG_MAX;
	for(int i=1;i<=n;i++) {
		cin>>arr[i];
		minval = min(minval, arr[i]);
	}

	if(minval != 1) {
		cout<<minval<<"/1\n";
	}
	else {
		dfs(1, -1);
		cout<<"1/"<<result<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1401 ms 110428 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1743 ms 176596 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1593 ms 75588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1598 ms 71868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 204 ms 30088 KB Output is correct
2 Incorrect 1577 ms 76172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1500 ms 73196 KB Output is correct
2 Incorrect 1660 ms 70084 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1638 ms 76176 KB Output is correct
2 Correct 1147 ms 52816 KB Output is correct