# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973862 | 2024-05-02T12:01:14 Z | PieArmy | Hard route (IZhO17_road) | C++17 | 529 ms | 101572 KB |
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} int n; ll dp[500001][3][3],ans=0,say=1; vector<int>komsu[500001]; void ekle(int loc,int x,ll cnt){ if(x>dp[loc][0][0]){ swap(dp[loc][1],dp[loc][2]); swap(dp[loc][0],dp[loc][1]); dp[loc][0][0]=x; dp[loc][0][1]=0; dp[loc][0][2]=0; } else if(x>dp[loc][1][0]){ swap(dp[loc][1],dp[loc][2]); dp[loc][1][0]=x; dp[loc][1][1]=0; dp[loc][1][2]=0; if(x==dp[loc][0][0]){ dp[loc][1][1]=dp[loc][0][1]; dp[loc][1][2]=dp[loc][0][2]; } } else if(x>dp[loc][2][0]){ dp[loc][2][0]=x; dp[loc][2][1]=0; dp[loc][2][2]=0; if(x==dp[loc][1][0]){ dp[loc][2][1]=dp[loc][1][1]; dp[loc][2][2]=dp[loc][1][2]; } } for(int i=0;i<3;i++){ if(x==dp[loc][i][0]){ dp[loc][i][2]+=dp[loc][i][1]*cnt; dp[loc][i][1]+=cnt; } } } void dfs1(int pos,int root){ dp[pos][0][1]=1; for(int x:komsu[pos]){ if(x==root)continue; dfs1(x,pos); ekle(pos,dp[x][0][0]+1,dp[x][0][1]); } } void dfs2(int pos,int root){ if(root){ if(dp[root][0][0]-1==dp[pos][0][0]){ ll y=dp[root][1][1]; if(dp[root][1][0]-1==dp[pos][0][0]){ y-=dp[pos][0][1]; } ekle(pos,dp[root][1][0]+1,y); } else{ ekle(pos,dp[root][0][0]+1,dp[root][0][1]); } } if(dp[pos][0][0]&&dp[pos][1][0]&&dp[pos][2][0]){ ll art=0; if(dp[pos][1][0]==dp[pos][2][0]){ art=dp[pos][1][2]; } else{ art=dp[pos][1][1]*dp[pos][2][1]; } if(dp[pos][0][0]*(dp[pos][1][0]+dp[pos][2][0])>ans){ ans=dp[pos][0][0]*(dp[pos][1][0]+dp[pos][2][0]); say=art; } else if(dp[pos][0][0]*(dp[pos][1][0]+dp[pos][2][0])==ans){ say+=art; } } for(int x:komsu[pos]){ if(x==root)continue; dfs2(x,pos); } } void code(){ cin>>n; for(int i=1;i<n;i++){ int a,b;cin>>a>>b; komsu[a].pb(b); komsu[b].pb(a); } dfs1(1,0); dfs2(1,0); cout<<ans<<" "<<say; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12892 KB | Output is correct |
2 | Correct | 3 ms | 12892 KB | Output is correct |
3 | Correct | 3 ms | 12892 KB | Output is correct |
4 | Correct | 3 ms | 12892 KB | Output is correct |
5 | Correct | 3 ms | 13148 KB | Output is correct |
6 | Correct | 3 ms | 12892 KB | Output is correct |
7 | Correct | 3 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 3 ms | 12892 KB | Output is correct |
11 | Correct | 3 ms | 12956 KB | Output is correct |
12 | Correct | 3 ms | 12892 KB | Output is correct |
13 | Correct | 3 ms | 12948 KB | Output is correct |
14 | Correct | 3 ms | 12892 KB | Output is correct |
15 | Correct | 3 ms | 12912 KB | Output is correct |
16 | Correct | 3 ms | 12892 KB | Output is correct |
17 | Correct | 3 ms | 12892 KB | Output is correct |
18 | Correct | 3 ms | 12892 KB | Output is correct |
19 | Correct | 3 ms | 12892 KB | Output is correct |
20 | Correct | 3 ms | 12888 KB | Output is correct |
21 | Correct | 3 ms | 12916 KB | Output is correct |
22 | Correct | 3 ms | 12892 KB | Output is correct |
23 | Correct | 3 ms | 12892 KB | Output is correct |
24 | Correct | 3 ms | 13144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12892 KB | Output is correct |
2 | Correct | 3 ms | 12892 KB | Output is correct |
3 | Correct | 3 ms | 12892 KB | Output is correct |
4 | Correct | 3 ms | 12892 KB | Output is correct |
5 | Correct | 3 ms | 13148 KB | Output is correct |
6 | Correct | 3 ms | 12892 KB | Output is correct |
7 | Correct | 3 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 3 ms | 12892 KB | Output is correct |
11 | Correct | 3 ms | 12956 KB | Output is correct |
12 | Correct | 3 ms | 12892 KB | Output is correct |
13 | Correct | 3 ms | 12948 KB | Output is correct |
14 | Correct | 3 ms | 12892 KB | Output is correct |
15 | Correct | 3 ms | 12912 KB | Output is correct |
16 | Correct | 3 ms | 12892 KB | Output is correct |
17 | Correct | 3 ms | 12892 KB | Output is correct |
18 | Correct | 3 ms | 12892 KB | Output is correct |
19 | Correct | 3 ms | 12892 KB | Output is correct |
20 | Correct | 3 ms | 12888 KB | Output is correct |
21 | Correct | 3 ms | 12916 KB | Output is correct |
22 | Correct | 3 ms | 12892 KB | Output is correct |
23 | Correct | 3 ms | 12892 KB | Output is correct |
24 | Correct | 3 ms | 13144 KB | Output is correct |
25 | Correct | 4 ms | 13148 KB | Output is correct |
26 | Correct | 4 ms | 13148 KB | Output is correct |
27 | Correct | 4 ms | 13144 KB | Output is correct |
28 | Correct | 4 ms | 13144 KB | Output is correct |
29 | Correct | 4 ms | 13148 KB | Output is correct |
30 | Correct | 4 ms | 13148 KB | Output is correct |
31 | Correct | 4 ms | 13148 KB | Output is correct |
32 | Correct | 5 ms | 13404 KB | Output is correct |
33 | Correct | 4 ms | 13148 KB | Output is correct |
34 | Correct | 4 ms | 13148 KB | Output is correct |
35 | Correct | 4 ms | 13148 KB | Output is correct |
36 | Correct | 5 ms | 13148 KB | Output is correct |
37 | Correct | 4 ms | 13148 KB | Output is correct |
38 | Correct | 4 ms | 13400 KB | Output is correct |
39 | Correct | 5 ms | 13148 KB | Output is correct |
40 | Correct | 5 ms | 13148 KB | Output is correct |
41 | Correct | 4 ms | 13344 KB | Output is correct |
42 | Correct | 5 ms | 13148 KB | Output is correct |
43 | Correct | 5 ms | 13148 KB | Output is correct |
44 | Correct | 4 ms | 13148 KB | Output is correct |
45 | Correct | 4 ms | 13144 KB | Output is correct |
46 | Correct | 5 ms | 12892 KB | Output is correct |
47 | Correct | 4 ms | 13148 KB | Output is correct |
48 | Correct | 4 ms | 13148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12892 KB | Output is correct |
2 | Correct | 3 ms | 12892 KB | Output is correct |
3 | Correct | 3 ms | 12892 KB | Output is correct |
4 | Correct | 3 ms | 12892 KB | Output is correct |
5 | Correct | 3 ms | 13148 KB | Output is correct |
6 | Correct | 3 ms | 12892 KB | Output is correct |
7 | Correct | 3 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 3 ms | 12892 KB | Output is correct |
11 | Correct | 3 ms | 12956 KB | Output is correct |
12 | Correct | 3 ms | 12892 KB | Output is correct |
13 | Correct | 3 ms | 12948 KB | Output is correct |
14 | Correct | 3 ms | 12892 KB | Output is correct |
15 | Correct | 3 ms | 12912 KB | Output is correct |
16 | Correct | 3 ms | 12892 KB | Output is correct |
17 | Correct | 3 ms | 12892 KB | Output is correct |
18 | Correct | 3 ms | 12892 KB | Output is correct |
19 | Correct | 3 ms | 12892 KB | Output is correct |
20 | Correct | 3 ms | 12888 KB | Output is correct |
21 | Correct | 3 ms | 12916 KB | Output is correct |
22 | Correct | 3 ms | 12892 KB | Output is correct |
23 | Correct | 3 ms | 12892 KB | Output is correct |
24 | Correct | 3 ms | 13144 KB | Output is correct |
25 | Correct | 4 ms | 13148 KB | Output is correct |
26 | Correct | 4 ms | 13148 KB | Output is correct |
27 | Correct | 4 ms | 13144 KB | Output is correct |
28 | Correct | 4 ms | 13144 KB | Output is correct |
29 | Correct | 4 ms | 13148 KB | Output is correct |
30 | Correct | 4 ms | 13148 KB | Output is correct |
31 | Correct | 4 ms | 13148 KB | Output is correct |
32 | Correct | 5 ms | 13404 KB | Output is correct |
33 | Correct | 4 ms | 13148 KB | Output is correct |
34 | Correct | 4 ms | 13148 KB | Output is correct |
35 | Correct | 4 ms | 13148 KB | Output is correct |
36 | Correct | 5 ms | 13148 KB | Output is correct |
37 | Correct | 4 ms | 13148 KB | Output is correct |
38 | Correct | 4 ms | 13400 KB | Output is correct |
39 | Correct | 5 ms | 13148 KB | Output is correct |
40 | Correct | 5 ms | 13148 KB | Output is correct |
41 | Correct | 4 ms | 13344 KB | Output is correct |
42 | Correct | 5 ms | 13148 KB | Output is correct |
43 | Correct | 5 ms | 13148 KB | Output is correct |
44 | Correct | 4 ms | 13148 KB | Output is correct |
45 | Correct | 4 ms | 13144 KB | Output is correct |
46 | Correct | 5 ms | 12892 KB | Output is correct |
47 | Correct | 4 ms | 13148 KB | Output is correct |
48 | Correct | 4 ms | 13148 KB | Output is correct |
49 | Correct | 330 ms | 82004 KB | Output is correct |
50 | Correct | 347 ms | 84244 KB | Output is correct |
51 | Correct | 347 ms | 86096 KB | Output is correct |
52 | Correct | 342 ms | 79440 KB | Output is correct |
53 | Correct | 275 ms | 82816 KB | Output is correct |
54 | Correct | 274 ms | 85144 KB | Output is correct |
55 | Correct | 273 ms | 79696 KB | Output is correct |
56 | Correct | 285 ms | 81848 KB | Output is correct |
57 | Correct | 292 ms | 87284 KB | Output is correct |
58 | Correct | 295 ms | 84560 KB | Output is correct |
59 | Correct | 332 ms | 84652 KB | Output is correct |
60 | Correct | 297 ms | 83540 KB | Output is correct |
61 | Correct | 525 ms | 101572 KB | Output is correct |
62 | Correct | 500 ms | 95568 KB | Output is correct |
63 | Correct | 499 ms | 78996 KB | Output is correct |
64 | Correct | 529 ms | 75220 KB | Output is correct |
65 | Correct | 478 ms | 72532 KB | Output is correct |
66 | Correct | 465 ms | 71248 KB | Output is correct |
67 | Correct | 519 ms | 70812 KB | Output is correct |
68 | Correct | 471 ms | 70224 KB | Output is correct |
69 | Correct | 515 ms | 70236 KB | Output is correct |
70 | Correct | 512 ms | 70136 KB | Output is correct |
71 | Correct | 457 ms | 69948 KB | Output is correct |
72 | Correct | 471 ms | 70184 KB | Output is correct |
73 | Correct | 509 ms | 70120 KB | Output is correct |
74 | Correct | 451 ms | 70224 KB | Output is correct |
75 | Correct | 460 ms | 70308 KB | Output is correct |
76 | Correct | 464 ms | 70328 KB | Output is correct |
77 | Correct | 340 ms | 70980 KB | Output is correct |
78 | Correct | 241 ms | 72128 KB | Output is correct |