# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
167642 |
2019-12-09T08:06:02 Z |
EntityIT |
Mag (COCI16_mag) |
C++14 |
|
490 ms |
79208 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
#define fi first
#define se second
using LL = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() );
int n;
vector<int> x, dep;
vector<vector<int> > gr;
int dfs(int u, int pr) {
dep[u] = dep[pr] + 1;
int ret = u;
for (int v : gr[u]) if (v != pr && x[v] == 1) {
int tmp = dfs(v, u);
if (dep[tmp] > dep[ret]) ret = tmp;
}
return ret;
}
void solve(int u, int pr, int& mx) {
dep[u] = dep[pr] + 1;
mx = max(mx, dep[u]);
for (int v : gr[u]) if (v != pr && x[v] == 1) solve(v, u, mx);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
gr.assign(n, {} );
for (int i = 0; i < n - 1; ++i) {
int u, v; cin >> u >> v; --u; --v;
gr[u].emplace_back(v);
gr[v].emplace_back(u);
}
x.assign(n, 0);
for (int i = 0; i < n; ++i) cin >> x[i];
if (!count(all(x), 1) ) {
cout << *min_element(all(x) ) << "/1\n";
cout.flush();
return 0;
}
dep.assign(n, -1);
int ans = 0;
for (int u = 0; u < n; ++u) if (dep[u] == -1 && x[u] == 1) {
int rt = dfs(u, u);
dep[rt] = 0; solve(rt, rt, ans);
}
cout << "1/" << ans << '\n';
cout.flush();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
423 ms |
77664 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
473 ms |
67820 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
477 ms |
76060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
463 ms |
79208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
8156 KB |
Output is correct |
2 |
Incorrect |
490 ms |
78016 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
429 ms |
71496 KB |
Output is correct |
2 |
Incorrect |
479 ms |
78828 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
77344 KB |
Output is correct |
2 |
Correct |
391 ms |
39928 KB |
Output is correct |