# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
132996 | 2019-07-20T03:47:11 Z | ae04071 | 철인 이종 경기 (APIO18_duathlon) | C++11 | 113 ms | 23952 KB |
#include <bits/stdc++.h> using namespace std; int n,m,cut[100001],dfn[100001],low[100001],o,dn; int bsz[200001]; vector<int> adj[100001],badj[200001]; stack<int> stk; int ts; void addEdge(int u,int v) { badj[u].push_back(v); badj[v].push_back(u); } void dfs(int cur,int p) { ts++; dfn[cur] = low[cur] = ++dn; stk.push(cur); for(auto &it:adj[cur]) if(it!=p) { if(dfn[it]) low[cur] = min(low[cur],dfn[it]); else { dfs(it,cur); low[cur] = min(low[cur],low[it]); if(low[it]>=dfn[cur]) { ++n; if(!cut[cur]) addEdge(n,cur); cut[cur] = 1; while(!stk.empty()) { int v=stk.top(); bsz[n]++; if(cut[v]) addEdge(n, v); stk.pop(); if(v==it) break; } bsz[n]++; } } } } long long ans; int sz[200001]; int cal_dfs(int cur,int p) { sz[cur] = bsz[cur]; for(auto &it:badj[cur]) if(it!=p) sz[cur] += cal_dfs(it,cur); sz[cur] -= ((int)badj[cur].size() - (p>0) - (cur<=o)); if(cur>o) { for(auto &it:badj[cur]) if(it!=p) ans += 1ll*(bsz[cur]-1)*sz[it]*(sz[it]-1); ans += 1ll*(bsz[cur]-1)*(ts-sz[cur]+1)*(ts-sz[cur]); } return sz[cur]; } int main() { scanf("%d%d",&n,&m); for(int i=0,u,v;i<m;i++) { scanf("%d%d",&u,&v); adj[u].push_back(v); adj[v].push_back(u); } o = n; long long ret = 0; for(int i=1;i<=o;i++) if(!dfn[i]) { ts=0; ans=0; dfs(i,0); while(!stk.empty()) stk.pop(); cal_dfs(i, 0); ret += 1ll*ts*(ts-1)*(ts-2) - ans; } printf("%lld\n",ret); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7388 KB | Output is correct |
2 | Correct | 8 ms | 7412 KB | Output is correct |
3 | Correct | 8 ms | 7420 KB | Output is correct |
4 | Correct | 8 ms | 7452 KB | Output is correct |
5 | Correct | 8 ms | 7408 KB | Output is correct |
6 | Correct | 8 ms | 7416 KB | Output is correct |
7 | Incorrect | 8 ms | 7448 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7388 KB | Output is correct |
2 | Correct | 8 ms | 7412 KB | Output is correct |
3 | Correct | 8 ms | 7420 KB | Output is correct |
4 | Correct | 8 ms | 7452 KB | Output is correct |
5 | Correct | 8 ms | 7408 KB | Output is correct |
6 | Correct | 8 ms | 7416 KB | Output is correct |
7 | Incorrect | 8 ms | 7448 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 23944 KB | Output is correct |
2 | Correct | 99 ms | 23952 KB | Output is correct |
3 | Incorrect | 112 ms | 22160 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 7544 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 113 ms | 17488 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 7420 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 113 ms | 17496 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7388 KB | Output is correct |
2 | Correct | 8 ms | 7412 KB | Output is correct |
3 | Correct | 8 ms | 7420 KB | Output is correct |
4 | Correct | 8 ms | 7452 KB | Output is correct |
5 | Correct | 8 ms | 7408 KB | Output is correct |
6 | Correct | 8 ms | 7416 KB | Output is correct |
7 | Incorrect | 8 ms | 7448 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7388 KB | Output is correct |
2 | Correct | 8 ms | 7412 KB | Output is correct |
3 | Correct | 8 ms | 7420 KB | Output is correct |
4 | Correct | 8 ms | 7452 KB | Output is correct |
5 | Correct | 8 ms | 7408 KB | Output is correct |
6 | Correct | 8 ms | 7416 KB | Output is correct |
7 | Incorrect | 8 ms | 7448 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |