# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
79820 | 2018-10-16T16:12:34 Z | Pajaraja | Hard route (IZhO17_road) | C++17 | 551 ms | 29532 KB |
#include <bits/stdc++.h> #define MAXN 500000 using namespace std; vector<int> g[MAXN]; int d[MAXN]; long long pot,cnt; void dfsD(int s,int f,int di) { d[s]=di; for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfsD(g[s][i],s,di+1); } int dfsp(int s,int f) { int mx=0; for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) mx=max(mx,dfsp(g[s][i],s)); d[s]=mx+1; return mx+1; } void calc(int s,int f,long long mx,long long du) { if(s!=f && g[s].size()==1) { if(du*mx==pot) cnt++; if(du*mx>pot) {pot=du*mx; cnt=1;} return; } int mxi=0; long long mx1=0,mx2=0; for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) if(d[g[s][i]]>mx1) {mx1=d[g[s][i]]; mxi=i;} for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) if(i!=mxi) mx2=max(mx2,(long long)d[g[s][i]]); calc(g[s][mxi],s,max(mx,mx2),du+1); for(int i=0;i<g[s].size();i++) if(g[s][i]!=f && i!=mxi) calc(g[s][i],s,max(mx,mx1),du+1); } int main() { int n,u=1,v=1; scanf("%d",&n); for(int i=0;i<n-1;i++) { int t1,t2; scanf("%d%d",&t1,&t2); g[t1].push_back(t2); g[t2].push_back(t1); } dfsD(1,1,0); for(int i=1;i<=n;i++) if(d[i]>d[u]) u=i; dfsD(u,u,0); for(int i=1;i<=n;i++) if(d[i]>d[v]) v=i; for(int i=1;i<=n;i++) if(g[i].size()==1) { dfsp(i,i); calc(i,i,0,0); } printf("%lld %lld",pot,cnt/2); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12024 KB | Output is correct |
2 | Correct | 12 ms | 12280 KB | Output is correct |
3 | Correct | 12 ms | 12280 KB | Output is correct |
4 | Correct | 12 ms | 12372 KB | Output is correct |
5 | Correct | 12 ms | 12372 KB | Output is correct |
6 | Correct | 12 ms | 12372 KB | Output is correct |
7 | Correct | 13 ms | 12372 KB | Output is correct |
8 | Correct | 12 ms | 12372 KB | Output is correct |
9 | Correct | 12 ms | 12400 KB | Output is correct |
10 | Correct | 13 ms | 12504 KB | Output is correct |
11 | Correct | 12 ms | 12504 KB | Output is correct |
12 | Correct | 12 ms | 12504 KB | Output is correct |
13 | Correct | 12 ms | 12556 KB | Output is correct |
14 | Correct | 12 ms | 12556 KB | Output is correct |
15 | Correct | 12 ms | 12556 KB | Output is correct |
16 | Correct | 12 ms | 12556 KB | Output is correct |
17 | Correct | 12 ms | 12556 KB | Output is correct |
18 | Correct | 12 ms | 12556 KB | Output is correct |
19 | Correct | 12 ms | 12556 KB | Output is correct |
20 | Correct | 12 ms | 12556 KB | Output is correct |
21 | Correct | 12 ms | 12556 KB | Output is correct |
22 | Correct | 12 ms | 12556 KB | Output is correct |
23 | Correct | 12 ms | 12556 KB | Output is correct |
24 | Correct | 13 ms | 12556 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12024 KB | Output is correct |
2 | Correct | 12 ms | 12280 KB | Output is correct |
3 | Correct | 12 ms | 12280 KB | Output is correct |
4 | Correct | 12 ms | 12372 KB | Output is correct |
5 | Correct | 12 ms | 12372 KB | Output is correct |
6 | Correct | 12 ms | 12372 KB | Output is correct |
7 | Correct | 13 ms | 12372 KB | Output is correct |
8 | Correct | 12 ms | 12372 KB | Output is correct |
9 | Correct | 12 ms | 12400 KB | Output is correct |
10 | Correct | 13 ms | 12504 KB | Output is correct |
11 | Correct | 12 ms | 12504 KB | Output is correct |
12 | Correct | 12 ms | 12504 KB | Output is correct |
13 | Correct | 12 ms | 12556 KB | Output is correct |
14 | Correct | 12 ms | 12556 KB | Output is correct |
15 | Correct | 12 ms | 12556 KB | Output is correct |
16 | Correct | 12 ms | 12556 KB | Output is correct |
17 | Correct | 12 ms | 12556 KB | Output is correct |
18 | Correct | 12 ms | 12556 KB | Output is correct |
19 | Correct | 12 ms | 12556 KB | Output is correct |
20 | Correct | 12 ms | 12556 KB | Output is correct |
21 | Correct | 12 ms | 12556 KB | Output is correct |
22 | Correct | 12 ms | 12556 KB | Output is correct |
23 | Correct | 12 ms | 12556 KB | Output is correct |
24 | Correct | 13 ms | 12556 KB | Output is correct |
25 | Correct | 307 ms | 12992 KB | Output is correct |
26 | Correct | 328 ms | 13172 KB | Output is correct |
27 | Correct | 330 ms | 13240 KB | Output is correct |
28 | Correct | 324 ms | 13240 KB | Output is correct |
29 | Correct | 404 ms | 13240 KB | Output is correct |
30 | Correct | 383 ms | 13240 KB | Output is correct |
31 | Correct | 408 ms | 13336 KB | Output is correct |
32 | Correct | 416 ms | 13336 KB | Output is correct |
33 | Correct | 18 ms | 13460 KB | Output is correct |
34 | Correct | 19 ms | 13624 KB | Output is correct |
35 | Correct | 19 ms | 13624 KB | Output is correct |
36 | Correct | 18 ms | 13624 KB | Output is correct |
37 | Correct | 16 ms | 13792 KB | Output is correct |
38 | Correct | 16 ms | 13828 KB | Output is correct |
39 | Correct | 18 ms | 13828 KB | Output is correct |
40 | Correct | 19 ms | 13828 KB | Output is correct |
41 | Correct | 24 ms | 13828 KB | Output is correct |
42 | Correct | 37 ms | 13828 KB | Output is correct |
43 | Correct | 51 ms | 13828 KB | Output is correct |
44 | Correct | 90 ms | 13828 KB | Output is correct |
45 | Correct | 164 ms | 13912 KB | Output is correct |
46 | Correct | 179 ms | 13912 KB | Output is correct |
47 | Correct | 436 ms | 14068 KB | Output is correct |
48 | Correct | 551 ms | 14072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12024 KB | Output is correct |
2 | Correct | 12 ms | 12280 KB | Output is correct |
3 | Correct | 12 ms | 12280 KB | Output is correct |
4 | Correct | 12 ms | 12372 KB | Output is correct |
5 | Correct | 12 ms | 12372 KB | Output is correct |
6 | Correct | 12 ms | 12372 KB | Output is correct |
7 | Correct | 13 ms | 12372 KB | Output is correct |
8 | Correct | 12 ms | 12372 KB | Output is correct |
9 | Correct | 12 ms | 12400 KB | Output is correct |
10 | Correct | 13 ms | 12504 KB | Output is correct |
11 | Correct | 12 ms | 12504 KB | Output is correct |
12 | Correct | 12 ms | 12504 KB | Output is correct |
13 | Correct | 12 ms | 12556 KB | Output is correct |
14 | Correct | 12 ms | 12556 KB | Output is correct |
15 | Correct | 12 ms | 12556 KB | Output is correct |
16 | Correct | 12 ms | 12556 KB | Output is correct |
17 | Correct | 12 ms | 12556 KB | Output is correct |
18 | Correct | 12 ms | 12556 KB | Output is correct |
19 | Correct | 12 ms | 12556 KB | Output is correct |
20 | Correct | 12 ms | 12556 KB | Output is correct |
21 | Correct | 12 ms | 12556 KB | Output is correct |
22 | Correct | 12 ms | 12556 KB | Output is correct |
23 | Correct | 12 ms | 12556 KB | Output is correct |
24 | Correct | 13 ms | 12556 KB | Output is correct |
25 | Correct | 307 ms | 12992 KB | Output is correct |
26 | Correct | 328 ms | 13172 KB | Output is correct |
27 | Correct | 330 ms | 13240 KB | Output is correct |
28 | Correct | 324 ms | 13240 KB | Output is correct |
29 | Correct | 404 ms | 13240 KB | Output is correct |
30 | Correct | 383 ms | 13240 KB | Output is correct |
31 | Correct | 408 ms | 13336 KB | Output is correct |
32 | Correct | 416 ms | 13336 KB | Output is correct |
33 | Correct | 18 ms | 13460 KB | Output is correct |
34 | Correct | 19 ms | 13624 KB | Output is correct |
35 | Correct | 19 ms | 13624 KB | Output is correct |
36 | Correct | 18 ms | 13624 KB | Output is correct |
37 | Correct | 16 ms | 13792 KB | Output is correct |
38 | Correct | 16 ms | 13828 KB | Output is correct |
39 | Correct | 18 ms | 13828 KB | Output is correct |
40 | Correct | 19 ms | 13828 KB | Output is correct |
41 | Correct | 24 ms | 13828 KB | Output is correct |
42 | Correct | 37 ms | 13828 KB | Output is correct |
43 | Correct | 51 ms | 13828 KB | Output is correct |
44 | Correct | 90 ms | 13828 KB | Output is correct |
45 | Correct | 164 ms | 13912 KB | Output is correct |
46 | Correct | 179 ms | 13912 KB | Output is correct |
47 | Correct | 436 ms | 14068 KB | Output is correct |
48 | Correct | 551 ms | 14072 KB | Output is correct |
49 | Runtime error | 51 ms | 29532 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
50 | Halted | 0 ms | 0 KB | - |