Submission #273054

# Submission time Handle Problem Language Result Execution time Memory
273054 2020-08-19T03:24:10 Z super_j6 Mag (COCI16_mag) C++14
60 / 120
487 ms 147016 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

const int mxn = 1000000;
int n;
int a[mxn], f1[mxn], f2[mxn];
vector<int> g[mxn];

void upd(int x, int v){
	f2[x] = max(f2[x], v);
	if(f2[x] > f1[x]) swap(f1[x], f2[x]);
}

void dfs(int c, int p){
	for(int i : g[c]){
		if(i == p) continue;
		dfs(i, c);
		if(!~-a[i]) upd(c, f1[i] + 1);
	}
}

void dfs2(int c, int p){
	for(int i : g[c]){
		if(i == p) continue;
		if(!~-a[c]) upd(i, f1[i] + 1 == f1[c] ? f2[c] : f1[c]);
		dfs2(i, c);
	} 
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	dfs(0, -1);
	dfs2(0, -1);
	
	ll x = 1, y = 0;
	for(int i = 0; i < n; i++){
		ll w = a[i], z = f1[i] + f2[i] + 1;
		if(w * y < x * z) x = w, y = z;
	}
	ll g = __gcd(x, y);
	x /= g, y /= g;
	
	cout << x << "/" << y << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 83288 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 467 ms 126980 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 66552 KB Output is correct
2 Correct 323 ms 66580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 67736 KB Output is correct
2 Correct 89 ms 29820 KB Output is correct
3 Incorrect 487 ms 147016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 28280 KB Output is correct
2 Correct 425 ms 67064 KB Output is correct
3 Correct 400 ms 53496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 64096 KB Output is correct
2 Correct 418 ms 83064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 67312 KB Output is correct
2 Correct 352 ms 53624 KB Output is correct