# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721866 | Son | Duathlon (APIO18_duathlon) | C++14 | 125 ms | 28204 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.
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
int n,m;
vector < int > E[100005];
int low[100005], num[100005];
int idx = 0;
vector < int > bcc_group[200005];
int bccs = 1;
vector < int > stck;
int N = 0, sub[200005];
LL ans = 0;
void dfs1( int u, int p ){
low[u] = num[u] = ++idx;
stck.pb(u);
N++;
for ( int v : E[u] ){
if ( num[v] ) low[u] = min( low[u], num[v] );
else {
dfs1(v,u);
low[u] = min(low[u], low[v]);
if ( low[v] >= num[u] ){
bcc_group[u].pb(n + bccs);
while ( !bcc_group[n+bccs].size() || bcc_group[n+bccs].back() != v ){
bcc_group[n+bccs].pb(stck.back());
stck.pop_back();
}
bccs++;
}
}
}
}
void dfs2( int u ){
sub[u] = (u <= n);
for ( int v : bcc_group[u] ){
dfs2(v);
sub[u] += sub[v];
if ( u > n ) ans -= bcc_group[u].size() * 1LL * (sub[v]) * (sub[v]-1);
}
if (u > n){
ans -= bcc_group[u].size() * 1LL * (N-sub[u]) * (N - sub[u] - 1);
}
}
int main(){
scanf("%d%d",&n,&m);
for ( int i = 1; i <= m; i++ ){
int u , v;
scanf("%d%d",&u,&v);
E[u].pb(v);
E[v].pb(u);
}
for ( int i = 1; i <= n; i++ ){
if ( num[i] == 0 ){
N = 0;
dfs1(i,-1);
ans += N * 1LL * (N-1) * (N-2);
dfs2(i);
}
}
printf("%lld\n",ans);
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... |