# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121947 | 2019-06-27T09:07:41 Z | KLPP | Designated Cities (JOI19_designated_cities) | C++14 | 466 ms | 38236 KB |
#include<bits/stdc++.h> using namespace std; typedef long long int lld; typedef pair<lld,lld> pii; #define rep(i,a,b) for(int i=a;i<b;i++) #define trav(a,v) for(auto a:v) vector<pii> nei[200000]; vector<pii> nei_d[200000]; lld dist[200000]; bool visited[200000]; void DFS(int node){ //cout<<node<<endl; visited[node]=true; trav(p,nei_d[node]){ if(!visited[p.first]){ dist[p.first]=dist[node]+p.second; DFS(p.first); } } } lld ans; void DFS2(int node){ visited[node]=true; trav(p,nei[node]){ if(!visited[p.first]){ ans+=p.second; DFS2(p.first); } } } int main(){ int n; scanf("%d",&n); rep(i,0,n-1){ int x,y; lld z,w; scanf("%d %d %lld %lld",&x,&y,&z,&w); x--;y--; nei[x].push_back(pii(y,z)); nei[y].push_back(pii(x,w)); nei_d[x].push_back(pii(y,z-w)); nei_d[y].push_back(pii(x,w-z)); } rep(i,0,n){ dist[i]=0; visited[i]=false; } dist[0]=0; DFS(0); //rep(i,0,n)cout<<dist[i]<<endl; pii best=pii(0,0); rep(i,0,n){ best=max(best,pii(dist[i],i)); } int start=best.second; ans=0; rep(i,0,n)visited[i]=false; DFS2(start); printf("%d\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
2 | Incorrect | 466 ms | 38236 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
2 | Incorrect | 466 ms | 38236 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 9728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |