# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
473723 |
2021-09-16T00:44:21 Z |
ntabc05101 |
Mag (COCI16_mag) |
C++14 |
|
454 ms |
135364 KB |
#include<bits/stdc++.h>
using namespace std;
const int mxN = 1000000;
bool choose[mxN];
vector<int> adj[mxN];
int ans = 0;
int d[mxN];
void dfs(int u, int p = -1) {
int mx = -1, mx2 = -1;
for (auto &to: adj[u]) {
if (to != p) {
dfs(to, u);
if (choose[to]) {
mx2 = max(mx2, d[to]);
if (mx2 > mx) {
swap(mx2, mx);
}
}
}
}
if (choose[u]) {
d[u] = 1;
if (~mx) {
ans = max(ans, mx + 1);
d[u] = mx + 1;
}
if (~mx2) {
ans = max(ans, mx + mx2 + 1);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
for (int i = 0, x, y; i < n - 1; i++) {
cin >> x >> y; x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
int mn = 1e9;
for (int i = 0, x; i < n; i++) {
cin >> x;
choose[i] = x == 1;
mn = min(mn, x);
}
if (mn > 1) {
cout << mn << "/1";
}
else {
ans = 1;
dfs(0);
cout << "1/" << ans;
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
357 ms |
84376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
454 ms |
135364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
401 ms |
60308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
388 ms |
60944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
27972 KB |
Output is correct |
2 |
Incorrect |
424 ms |
75664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
58512 KB |
Output is correct |
2 |
Incorrect |
397 ms |
59348 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
408 ms |
60884 KB |
Output is correct |
2 |
Correct |
334 ms |
42984 KB |
Output is correct |