# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
37740 | 2017-12-27T13:12:09 Z | DenXman111 | Hard route (IZhO17_road) | C++14 | 2000 ms | 156264 KB |
#include <iostream> #include <cstdio> #include <algorithm> #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <map> #include <vector> #include <cstring> #include <iomanip> #include <set> #include <sstream> #include <ctime> #define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d)) #define sqr(a) (a)*(a) #define p_b push_back #define m_p make_pair #define fi first #define se second #define endl "\n" typedef long long ll; typedef long double ld; const int MAXINT = 2147483640; const ll MAXLL = 9223372036854775800LL; const ll MAXN = 1123456; const ll MOD = 1123456769; using namespace std; vector < int > ss[MAXN]; vector < pair < int, int > > ways[MAXN]; int len[MAXN]; void dfs(int v, int pr){ multiset < int > s; ways[v].clear(); len[v] = 0; for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) { dfs(ss[v][i], v); len[v] = max(len[v], len[ss[v][i]] + 1); s.insert(len[ss[v][i]] + 1); } for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) { set < int > :: iterator it = --(s.end()); int x = ss[v][i]; if (len[x] + 1 == *it) --it; int y = 0; if (s.size() > 1) y = *it; for (int j = 0; j < ways[x].size(); j++) ways[v].p_b(m_p(ways[x][j].fi + 1, max(ways[x][j].se, y))); } if (ss[v].size() == 1 && pr != 0) ways[v].p_b(m_p(0, 0)), len[v] = 0; } int main() { // freopen("road.in", "r", stdin); // freopen("road.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); srand(time(0)); int n, m, i, j, x, y; cin >> n; for (i = 1; i < n; i++){ cin >> x >> y; ss[x].p_b(y); ss[y].p_b(x); } vector < ll > ans; for (i = 1; i <= n; i++) if (ss[i].size() == 1) { dfs(i, 0); for (j = 0; j < ways[i].size(); j++) ans.p_b(ll(ways[i][j].fi) * ways[i][j].se); } sort(ans.begin(), ans.end()); if (ans.size()) x = ans.back(); else x = 0; y = 0; for (i = ans.size() - 1; i >= 0; i--) if (ans[i] == x) ++y; cout << x << " " << y / 2 << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 59232 KB | Output is correct |
2 | Correct | 13 ms | 59232 KB | Output is correct |
3 | Correct | 16 ms | 59232 KB | Output is correct |
4 | Correct | 13 ms | 59232 KB | Output is correct |
5 | Correct | 9 ms | 59232 KB | Output is correct |
6 | Correct | 6 ms | 59232 KB | Output is correct |
7 | Correct | 23 ms | 59232 KB | Output is correct |
8 | Correct | 16 ms | 59232 KB | Output is correct |
9 | Correct | 16 ms | 59232 KB | Output is correct |
10 | Correct | 9 ms | 59232 KB | Output is correct |
11 | Correct | 19 ms | 59368 KB | Output is correct |
12 | Correct | 16 ms | 59368 KB | Output is correct |
13 | Correct | 19 ms | 59368 KB | Output is correct |
14 | Correct | 19 ms | 59368 KB | Output is correct |
15 | Correct | 16 ms | 59232 KB | Output is correct |
16 | Correct | 19 ms | 59232 KB | Output is correct |
17 | Correct | 16 ms | 59232 KB | Output is correct |
18 | Correct | 26 ms | 59232 KB | Output is correct |
19 | Correct | 13 ms | 59232 KB | Output is correct |
20 | Correct | 13 ms | 59232 KB | Output is correct |
21 | Correct | 13 ms | 59232 KB | Output is correct |
22 | Correct | 16 ms | 59232 KB | Output is correct |
23 | Correct | 6 ms | 59232 KB | Output is correct |
24 | Correct | 9 ms | 59548 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 59232 KB | Output is correct |
2 | Correct | 13 ms | 59232 KB | Output is correct |
3 | Correct | 16 ms | 59232 KB | Output is correct |
4 | Correct | 13 ms | 59232 KB | Output is correct |
5 | Correct | 9 ms | 59232 KB | Output is correct |
6 | Correct | 6 ms | 59232 KB | Output is correct |
7 | Correct | 23 ms | 59232 KB | Output is correct |
8 | Correct | 16 ms | 59232 KB | Output is correct |
9 | Correct | 16 ms | 59232 KB | Output is correct |
10 | Correct | 9 ms | 59232 KB | Output is correct |
11 | Correct | 19 ms | 59368 KB | Output is correct |
12 | Correct | 16 ms | 59368 KB | Output is correct |
13 | Correct | 19 ms | 59368 KB | Output is correct |
14 | Correct | 19 ms | 59368 KB | Output is correct |
15 | Correct | 16 ms | 59232 KB | Output is correct |
16 | Correct | 19 ms | 59232 KB | Output is correct |
17 | Correct | 16 ms | 59232 KB | Output is correct |
18 | Correct | 26 ms | 59232 KB | Output is correct |
19 | Correct | 13 ms | 59232 KB | Output is correct |
20 | Correct | 13 ms | 59232 KB | Output is correct |
21 | Correct | 13 ms | 59232 KB | Output is correct |
22 | Correct | 16 ms | 59232 KB | Output is correct |
23 | Correct | 6 ms | 59232 KB | Output is correct |
24 | Correct | 9 ms | 59548 KB | Output is correct |
25 | Correct | 1486 ms | 156256 KB | Output is correct |
26 | Correct | 1516 ms | 156264 KB | Output is correct |
27 | Correct | 1343 ms | 156180 KB | Output is correct |
28 | Correct | 1326 ms | 156256 KB | Output is correct |
29 | Execution timed out | 2000 ms | 119624 KB | Execution timed out |
30 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 59232 KB | Output is correct |
2 | Correct | 13 ms | 59232 KB | Output is correct |
3 | Correct | 16 ms | 59232 KB | Output is correct |
4 | Correct | 13 ms | 59232 KB | Output is correct |
5 | Correct | 9 ms | 59232 KB | Output is correct |
6 | Correct | 6 ms | 59232 KB | Output is correct |
7 | Correct | 23 ms | 59232 KB | Output is correct |
8 | Correct | 16 ms | 59232 KB | Output is correct |
9 | Correct | 16 ms | 59232 KB | Output is correct |
10 | Correct | 9 ms | 59232 KB | Output is correct |
11 | Correct | 19 ms | 59368 KB | Output is correct |
12 | Correct | 16 ms | 59368 KB | Output is correct |
13 | Correct | 19 ms | 59368 KB | Output is correct |
14 | Correct | 19 ms | 59368 KB | Output is correct |
15 | Correct | 16 ms | 59232 KB | Output is correct |
16 | Correct | 19 ms | 59232 KB | Output is correct |
17 | Correct | 16 ms | 59232 KB | Output is correct |
18 | Correct | 26 ms | 59232 KB | Output is correct |
19 | Correct | 13 ms | 59232 KB | Output is correct |
20 | Correct | 13 ms | 59232 KB | Output is correct |
21 | Correct | 13 ms | 59232 KB | Output is correct |
22 | Correct | 16 ms | 59232 KB | Output is correct |
23 | Correct | 6 ms | 59232 KB | Output is correct |
24 | Correct | 9 ms | 59548 KB | Output is correct |
25 | Correct | 1486 ms | 156256 KB | Output is correct |
26 | Correct | 1516 ms | 156264 KB | Output is correct |
27 | Correct | 1343 ms | 156180 KB | Output is correct |
28 | Correct | 1326 ms | 156256 KB | Output is correct |
29 | Execution timed out | 2000 ms | 119624 KB | Execution timed out |
30 | Halted | 0 ms | 0 KB | - |