# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
273053 |
2020-08-19T03:16:59 Z |
super_j6 |
Mag (COCI16_mag) |
C++14 |
|
515 ms |
157624 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], f[mxn][2];
vector<int> g[mxn];
void upd(int x, int v){
f[x][1] = max(f[x][1], v);
sort(f[x], f[x] + 2);
}
void dfs(int c, int p){
for(int i : g[c]){
if(i == p) continue;
dfs(i, c);
if(!~-a[i]) upd(c, f[i][0] + 1);
}
}
void dfs2(int c, int p){
for(int i : g[c]){
if(i == p) continue;
if(!~-a[c]) upd(i, f[c][f[i][0] + 1 == f[c][0]] + 1);
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 = f[i][0] + f[i][1] + 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 |
18 ms |
23936 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
23936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
418 ms |
95844 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 |
515 ms |
157624 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
438 ms |
66888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
402 ms |
67792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
28376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
398 ms |
64572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
451 ms |
67448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |