# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
155492 | Akashi | 철인 이종 경기 (APIO18_duathlon) | C++14 | 193 ms | 28424 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
int n, m, nr, nrc;
bool f[100005], viz[200005], art[100005];
int h[100005], low[100005], d[200005];
vector <int> v[100005];
vector <int> v2[200005];
stack <int> st;
long long Sol;
int dfs(int nod, int papa = 0){
f[nod] = 1;
st.push(nod);
++nr;
int cnt = 0;
for(auto it : v[nod]){
if(papa == it) continue ;
if(!f[it]){
++cnt;
h[it] = low[it] = h[nod] + 1;
dfs(it, nod);
low[nod] = min(low[nod], low[it]);
if(low[it] >= h[nod]){
++nrc;
v2[nod].push_back(nrc + n);
while(v2[nrc + n].empty() || v2[nrc + n].back() != it){
v2[nrc + n].push_back(st.top());
st.pop();
}
}
}
else low[nod] = min(low[nod], low[it]);
}
}
void bdfs(int nod){
viz[nod] = 1;
if(nod <= n) d[nod] = 1;
for(auto it : v2[nod]){
if(viz[it]) continue ;
bdfs(it);
d[nod] += d[it];
if(nod > n) Sol = Sol - 1LL * v2[nod].size() * d[it] * (d[it] - 1);
}
if(nod > n) Sol = Sol - 1LL * (nr - d[nod]) * (nr - d[nod] - 1) * v2[nod].size();
}
int main()
{
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
scanf("%d%d", &n, &m);
int x, y;
for(int i = 1; i <= m ; ++i){
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
for(int i = 1; i <= n ; ++i){
if(f[i]) continue ;
nr = 0;
dfs(i);
Sol = Sol + 1LL * nr * (nr - 1) * (nr - 2);
if(nr > 2) bdfs(i);
}
printf("%lld", Sol);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |