# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155485 | Akashi | Duathlon (APIO18_duathlon) | C++14 | 206 ms | 28624 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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; d[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);
d[nod] += d[it];
low[nod] = min(low[nod], low[it]);
if(low[it] >= h[nod]){
++nrc;
v2[nod].push_back(nrc + n);
while(!st.empty() && st.top() != nod){
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;
}
Compilation message (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... |