# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378109 | 2021-03-16T03:22:52 Z | daniel920712 | Designated Cities (JOI19_designated_cities) | C++14 | 2000 ms | 62188 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <map> #include <set> using namespace std; vector < pair < long long , long long > > Next[200005]; map < long long , long long > all[200005]; set < long long > vis[200005]; long long ans[200005]; long long xx[200005]; long long how[200005]; long long N=0,big=1e18; long long x,y,root; pair < long long , long long > A,B; void F(long long here,long long fa) { for(auto i:Next[here]) { if(i.first!=fa) { ans[1]+=i.second; F(i.first,here); } } } void F2(long long here,long long fa) { for(auto i:Next[here]) { if(i.first!=fa) { ans[i.first]=ans[here]-all[here][i.first]+all[i.first][here]; F2(i.first,here); } } } pair < long long , long long > F4(long long here,long long fa,long long con) { pair < long long , long long > a=make_pair(con,here),b=make_pair(con,here),tt; for(auto i:Next[here]) { if(i.first!=fa) { tt=F4(i.first,here,con+i.second); if(tt>a) { b=a; a=tt; } else if(tt>b) b=tt; } } big=min(big,ans[here]-(a.first+b.first-2*con)); if(big==ans[here]-(a.first+b.first-2*con)) { root=here; x=a.second; y=b.second; } return a; } void F3(long long here,long long fa,long long con) { pair < long long , long long > a=make_pair(con,here),tt; for(auto i:Next[here]) { if(i.first!=fa) { F3(i.first,here,con+i.second); //if(tt>a) a=tt; } } big=max(big,con); if(big==con) x=here; //return a; } bool F5(long long here,long long fa) { //vector < pair < long long , long long > > del; long long ok=0; if(here==x||here==y) ok=1; for(auto &i:Next[here]) { if(i.first==fa) continue; if(F5(i.first,here)) { //printf("bb %lld %lld\n",here,i.first); //all[here][i.first]=0; i.second=0; ok=1; } } return ok; } int main() { //freopen("01-04.txt","rt",stdin); long long M,i,j,k,a,b,c,d,where; scanf("%lld",&N); for(i=1;i<N;i++) { scanf("%lld %lld %lld %lld",&a,&b,&c,&d); Next[a].push_back(make_pair(b,c)); Next[b].push_back(make_pair(a,d)); all[a][b]=c; all[b][a]=d; } for(i=1;i<=N;i++) xx[i]=1e18; F(1,-1); F2(1,-1); how[1]=1e18; for(i=1;i<=N;i++) { how[1]=min(how[1],ans[i]); if(how[1]==ans[i]) where=i; } F4(1,-1,0); //printf("%lld %lld %lld\n",root,x,y); F5(root,-1); how[2]=big; for(i=3;i<=N;i++) { y=-1; big=0; F3(root,-1,0); //printf("aa %lld %lld\n",big,x); how[i]=how[i-1]-big; F5(root,-1); } scanf("%lld",&M); while(M--) { scanf("%lld",&a); printf("%lld\n",how[a]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | Output is correct |
2 | Correct | 15 ms | 23788 KB | Output is correct |
3 | Correct | 15 ms | 23788 KB | Output is correct |
4 | Correct | 16 ms | 23788 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 15 ms | 23788 KB | Output is correct |
8 | Correct | 15 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23808 KB | Output is correct |
11 | Correct | 15 ms | 23788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23864 KB | Output is correct |
2 | Execution timed out | 2080 ms | 62188 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23788 KB | Output is correct |
2 | Execution timed out | 2073 ms | 62188 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | Output is correct |
2 | Correct | 15 ms | 23788 KB | Output is correct |
3 | Correct | 15 ms | 23788 KB | Output is correct |
4 | Correct | 16 ms | 23788 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 15 ms | 23788 KB | Output is correct |
8 | Correct | 15 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23808 KB | Output is correct |
11 | Correct | 15 ms | 23788 KB | Output is correct |
12 | Correct | 15 ms | 23788 KB | Output is correct |
13 | Correct | 166 ms | 24172 KB | Output is correct |
14 | Correct | 193 ms | 24636 KB | Output is correct |
15 | Correct | 188 ms | 24428 KB | Output is correct |
16 | Correct | 168 ms | 24556 KB | Output is correct |
17 | Correct | 169 ms | 24300 KB | Output is correct |
18 | Correct | 161 ms | 24300 KB | Output is correct |
19 | Correct | 165 ms | 24428 KB | Output is correct |
20 | Correct | 156 ms | 24336 KB | Output is correct |
21 | Correct | 167 ms | 24428 KB | Output is correct |
22 | Correct | 165 ms | 24300 KB | Output is correct |
23 | Correct | 142 ms | 24300 KB | Output is correct |
24 | Correct | 82 ms | 24300 KB | Output is correct |
25 | Correct | 185 ms | 24684 KB | Output is correct |
26 | Correct | 68 ms | 24300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23864 KB | Output is correct |
2 | Execution timed out | 2080 ms | 62188 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | Output is correct |
2 | Correct | 15 ms | 23788 KB | Output is correct |
3 | Correct | 15 ms | 23788 KB | Output is correct |
4 | Correct | 16 ms | 23788 KB | Output is correct |
5 | Correct | 15 ms | 23808 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 15 ms | 23788 KB | Output is correct |
8 | Correct | 15 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23808 KB | Output is correct |
11 | Correct | 15 ms | 23788 KB | Output is correct |
12 | Correct | 17 ms | 23864 KB | Output is correct |
13 | Execution timed out | 2080 ms | 62188 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |