# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71939 | 2018-08-26T01:48:28 Z | KLPP | Duathlon (APIO18_duathlon) | C++14 | 199 ms | 36592 KB |
#include<iostream> #include<stdio.h> #include<vector> #include<queue> #include<algorithm> using namespace std; typedef long long int lld; lld DP[1000000]; bool visited[1000000]; vector<int>nei[1000000]; lld sumdist[1000000]; lld ans; void DFS(int node){ visited[node]=true; lld sum=0; lld square=0; lld totaldist=0; for(int i=0;i<nei[node].size();i++){ int v=nei[node][i]; if(!visited[v]){ DFS(v); sum+=DP[v]; square+=DP[v]*DP[v]; totaldist+=sumdist[v]+DP[v]-1; } } DP[node]=sum+1; sumdist[node]=totaldist; ans+=sum*sum-square; ans+=2*totaldist; } int main(){ int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; x--;y--; nei[x].push_back(y); nei[y].push_back(x); } ans=0; for(int i=0;i<n;i++){ DP[i]=-1; visited[i]=false; } for(int i=0;i<n;i++){ if(!visited[i]){ DFS(i); } }//for(int i=0;i<n;i++)cout<<sumdist[i]<<endl; cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 23764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 23764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 185 ms | 36592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 36592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 151 ms | 36592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 26 ms | 36592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 199 ms | 36592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 23764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 23764 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |