# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155128 | Akashi | Duathlon (APIO18_duathlon) | C++14 | 177 ms | 35704 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, nrc;
bool viz[100005];
int id[100005], h[100005], low[100005];
vector <int> v[100005];
set <int> v2[100005];
vector <int> ctc[100005];
stack <int> st;
void dfs(int nod, int papa = 0){
st.push(nod);
viz[nod] = 1;
for(auto it : v[nod]){
if(papa == it) continue ;
if(!viz[it]){
h[it] = low[it] = h[nod] + 1;
dfs(it, nod);
low[nod] = min(low[nod], low[it]);
}
else low[nod] = min(low[nod], low[it]);
}
if(low[nod] == h[nod]){
int x;
++nrc;
do{
x = st.top();
st.pop();
id[x] = nrc;
ctc[nrc].push_back(x);
}while(x != nod);
}
}
long long Sol1 = 0;
long long Sol2 = 0;
long long dp[100005][2];
void ctc_dfs(int nod){
viz[nod] = 1;
int sz = ctc[nod].size();
Sol2 = Sol2 + 1LL * sz * 1LL * (sz - 1) * 1LL * (sz - 2);
dp[nod][0] = sz;
dp[nod][1] = 1LL * (sz - 1) * (sz - 1);
for(auto it : v2[nod]){
if(viz[it]) continue ;
ctc_dfs(it);
// Sol1 = Sol1 + 1LL * sz * dp[it][1] + 1LL * (sz - 1) * 1LL * (sz - 1) * 1LL * dp[it][0];
Sol1 = Sol1 + 1LL * dp[it][1] * dp[nod][0] + 1LL * dp[it][0] * dp[nod][1];
dp[nod][0] += dp[it][0];
dp[nod][1] = dp[nod][1] + dp[it][1] + 1LL * sz * dp[it][0];
}
}
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(viz[i]) continue ;
dfs(i);
}
for(int i = 1; i <= nrc ; ++i){
for(auto nod : ctc[i]){
for(auto it : v[nod]){
if(id[it] != id[nod])
v2[i].insert(id[it]);
}
}
}
memset(viz, 0, sizeof(viz));
for(int i = 1; i <= nrc ; ++i){
if(viz[i]) continue ;
ctc_dfs(i);
}
printf("%lld", Sol1 * 2LL + Sol2);
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... |