# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
747723 | 2023-05-24T15:00:22 Z | 1075508020060209tc | Duathlon (APIO18_duathlon) | C++14 | 168 ms | 47228 KB |
#include <bits/stdc++.h> using namespace std; #define int long long int n;int m; vector<int>e[300005]; vector<int>tr[300005]; vector<int>bke[300005]; vector<int>dwe[300005]; int sz[300005];int vis[300005];int dph[300005];int fa[300005]; int ans; void fdfs(int nw){ vis[nw]=1; sz[nw]=1; for(int i=0;i<e[nw].size();i++){ int v=e[nw][i]; if(vis[v]==0){ fa[v]=nw; dph[v]=dph[nw]+1; tr[nw].push_back(v); fdfs(v); sz[nw]+=sz[v]; continue; } if(v==fa[nw]){continue;} if(dph[v]<dph[nw]){ bke[nw].push_back(v); dwe[v].push_back(nw); } } } void dfs1(int nw,int rtsz){ ans+=(rtsz-sz[nw])*(sz[nw]-1); for(int i=0;i<tr[nw].size();i++){ int v=tr[nw][i]; dfs1(v,rtsz); ans+=sz[v]*(rtsz-1-sz[v]); } } int bv; int dfs2(int nw,int rtsz){ int ret=0; for(int i=0;i<tr[nw].size();i++){ int v=tr[nw][i]; int vl=dfs2(v,rtsz); if(vl){ ret=vl; ans+=(sz[v]-vl)*2; } } if(bke[nw].size()){ ret=sz[nw]; bv=bke[nw][0]; } if(dwe[nw].size()){ ret=0; } if(ret){ ans+=(rtsz-sz[bv]+1)*(dph[nw]-dph[bv]-1)*2; } //cout<<nw<<" "<<ret<<endl; return ret; } signed main() { cin>>n>>m; for(int i=1;i<=m;i++){ int a;int b; cin>>a>>b; e[a].push_back(b); e[b].push_back(a); } ans=0; vector<int>rt; for(int i=1;i<=n;i++){ if(vis[i]==0){ rt.push_back(i); fdfs(i); } } for(int i=0;i<rt.size();i++){ dfs1(rt[0],sz[rt[i]]); // dfs2(rt[0],sz[rt[i]]); } cout<<ans<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 28488 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 28488 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 168 ms | 47228 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 28576 KB | Output is correct |
2 | Correct | 17 ms | 28500 KB | Output is correct |
3 | Correct | 16 ms | 28572 KB | Output is correct |
4 | Correct | 17 ms | 28604 KB | Output is correct |
5 | Correct | 16 ms | 28628 KB | Output is correct |
6 | Correct | 18 ms | 28568 KB | Output is correct |
7 | Correct | 18 ms | 28764 KB | Output is correct |
8 | Correct | 18 ms | 28528 KB | Output is correct |
9 | Correct | 17 ms | 28500 KB | Output is correct |
10 | Incorrect | 15 ms | 28500 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 125 ms | 37236 KB | Output is correct |
2 | Correct | 131 ms | 37148 KB | Output is correct |
3 | Correct | 136 ms | 37180 KB | Output is correct |
4 | Correct | 127 ms | 37172 KB | Output is correct |
5 | Correct | 138 ms | 37176 KB | Output is correct |
6 | Correct | 163 ms | 42920 KB | Output is correct |
7 | Correct | 138 ms | 40808 KB | Output is correct |
8 | Correct | 133 ms | 39944 KB | Output is correct |
9 | Correct | 145 ms | 39060 KB | Output is correct |
10 | Incorrect | 130 ms | 37176 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 28520 KB | Output is correct |
2 | Correct | 16 ms | 28576 KB | Output is correct |
3 | Incorrect | 15 ms | 28524 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 135 ms | 37124 KB | Output is correct |
2 | Correct | 127 ms | 37368 KB | Output is correct |
3 | Incorrect | 165 ms | 38656 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 28488 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 28488 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |