# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
337903 |
2020-12-22T05:27:38 Z |
boykut |
Hard route (IZhO17_road) |
C++14 |
|
2000 ms |
196972 KB |
#include <bits/stdc++.h>
using namespace std;
int N;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
N = n;
vector <int> g[n + 1];
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
vector <int> d[1+N], p[1+N];
for (int i = 1; i <= n; i++) {
queue <int> q;
q.push(i);
d[i] = vector <int> (1+N, INT_MAX);
p[i] = vector <int> (1+N, -1);
d[i][i] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int to : g[v]) {
if (d[i][to] != INT_MAX) continue;
d[i][to] = d[i][v] + 1;
p[i][to] = v;
q.push(to);
}
}
}
vector <int> ends;
for (int i = 1; i <= n; i++) {
if (g[i].size() == 1) {
ends.push_back(i);
}
}
int ans = 0, ans_cnt = 0;
for (int i = 0; i < ends.size(); i++) {
int a = ends[i];
for (int j = i + 1; j < ends.size(); j++) {
int b = ends[j];
if (d[b][a] == INT_MAX) continue;
int v = a;
//vector <int> mas;
set <int> st;
while (v != -1) {
// mas.push_back(v);
st.insert(v);
v = p[b][v];
}
//for (int i = 0; i < mas.size(); i++) {
// cout << mas[i] << (i == mas.size()-1?" ":"-");
//}
//cout << "= " << d[b][a] << ' ';
int mx = 0;
for (int from = 1; from <= n; from++) {
if (st.count(from)) continue;
int mn = INT_MAX;
for (int to : st) {
mn = min(mn, d[from][to]);
}
mx = max(mx, mn);
}
if (mx * d[b][a] == ans) {
ans_cnt++;
} else if (mx * d[b][a] > ans) {
ans = mx * d[b][a];
ans_cnt = 1;
}
}
}
cout << ans << ' ' << ans_cnt << '\n';
return 0;
}
Compilation message
road.cpp: In function 'int main()':
road.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < ends.size(); i++) {
| ~~^~~~~~~~~~~~~
road.cpp:47:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j = i + 1; j < ends.size(); j++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
13 ms |
492 KB |
Output is correct |
12 |
Correct |
13 ms |
364 KB |
Output is correct |
13 |
Correct |
14 ms |
364 KB |
Output is correct |
14 |
Correct |
14 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
13 ms |
492 KB |
Output is correct |
12 |
Correct |
13 ms |
364 KB |
Output is correct |
13 |
Correct |
14 ms |
364 KB |
Output is correct |
14 |
Correct |
14 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Execution timed out |
2089 ms |
196972 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
13 ms |
492 KB |
Output is correct |
12 |
Correct |
13 ms |
364 KB |
Output is correct |
13 |
Correct |
14 ms |
364 KB |
Output is correct |
14 |
Correct |
14 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Execution timed out |
2089 ms |
196972 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |