Submission #273051

# Submission time Handle Problem Language Result Execution time Memory
273051 2020-08-19T03:07:01 Z super_j6 Mag (COCI16_mag) C++14
0 / 120
458 ms 147704 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, k = 20;
int n;
int a[mxn], d[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;
		d[i] = !~-a[i] * (d[c] + 1);
		dfs(i, c);
		if(!~-a[i]) upd(c, f1[i] + 1);
		if(!~-a[c]) upd(i, d[c] + 1);
	}
}

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];
	
	d[0] = -!!~-a[0];
	dfs(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 17 ms 23936 KB Output is correct
2 Incorrect 16 ms 23936 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 370 ms 100344 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 458 ms 147704 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 420 ms 85880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 88932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 29944 KB Output is correct
2 Incorrect 425 ms 86296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 396 ms 83324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 415 ms 86648 KB Output isn't correct
2 Halted 0 ms 0 KB -