# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
83692 |
2018-11-09T22:06:52 Z |
jasony123123 |
Mag (COCI16_mag) |
C++11 |
|
1379 ms |
150532 KB |
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define vsort(a) sort(a.begin(), a.end());
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
typedef long long ll;
typedef pair<int, int > pii;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
bool isbigger(pair<ll, ll> &a, pair<ll, ll> &b) {
ll g1 = __gcd(a.first, a.second);
ll g2 = __gcd(b.first, b.second);
a.first /= g1, a.second /= g1, b.first /= g2, b.second /= g2;
return b.second*a.first > b.first*a.second;
}
const int MAXN = 1000010;
int N;
v<int> adj[MAXN];
ll magic[MAXN];
int dpdown[MAXN], dpup[MAXN], dpone[MAXN];
void dfsone(int x, int p) {
int q = dpup[x], w = 0, e = 0; // >=
for (auto c : adj[x]) if (c != p) {
e = dpdown[c];
if (w < e) swap(w, e);
if (q < w) swap(q, w);
assert(q >= w && w >= e);
dfsone(c, x);
}
dpone[x] = q + w;
}
void dfsup(int x, int p) {
if (p != -1 && magic[p] == 1) {
dpup[x] = dpup[p];
for (int s : adj[p]) if (s != x)
dpup[x] = max(dpdown[s], dpup[x]);
dpup[x]++;
}
for (int c : adj[x]) if (c != p)
dfsup(c, x);
}
int dfsdown(int x, int p) {
for (int c : adj[x]) if (c != p)
dpdown[x] = max(dpdown[x], dfsdown(c, x));
if (magic[x] != 1)
dpdown[x] = 0;
else
dpdown[x]++;
return dpdown[x];
}
int main() {
// input
cin >> N;
FOR(i, 0, N - 1) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
FORE(i, 1, N)
cin >> magic[i];
// init and compute dp
memset(dpdown, 0, sizeof dpdown);
memset(dpup, 0, sizeof dpup);
memset(dpone, 0, sizeof dpone);
dfsdown(1, -1);
dfsup(1, -1);
dfsone(1, -1);
// find ans
pair<ll, ll> ans(magic[1], dpone[1] + 1);
FORE(i, 1, N) {
pair<ll, ll> cmp(magic[i], dpone[i] + 1);
if (isbigger(ans, cmp))
ans = cmp;
}
cout << ans.first << "/" << ans.second << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Incorrect |
32 ms |
35720 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
35720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1128 ms |
98532 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
98532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1379 ms |
150532 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1278 ms |
150532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1287 ms |
150532 KB |
Output is correct |
2 |
Incorrect |
186 ms |
150532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
150532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1197 ms |
150532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1299 ms |
150532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |