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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=2e6+5;
vector<int>h,g[mxn],st;
vector<int>gg[mxn];
bool vis[mxn]{0};
int di[mxn]{0},lo[mxn]{0},cur=0;
ll cnt=0,n;
ll sz[mxn]{0};
void dfs(int u,int p){
di[u]=lo[u]=++cur;
st.pb(u);cnt++;
for(auto v:g[u]){
if(!di[v]){
dfs(v,u);
lo[u]=min(lo[u],lo[v]);
if(lo[v]>=di[u]){
while(st.back()!=v){
gg[v+n].pb(st.back());
st.pop_back();
}gg[v+n].pb(v);st.pop_back();
gg[u].pb(v+n);
}
}else if(v!=p){
lo[u]=min(lo[u],di[v]);
}
}
}ll rs=0;
void solve(int u,int p){
if(u<=n)sz[u]=1;
for(auto v:gg[u]){
if(v==p)continue;
solve(v,u);sz[u]+=sz[v];
if(u>n)rs-=sz(gg[u])*(sz[v])*(sz[v]-1);
}
if(u>n)rs-=sz(gg[u])*(n-sz[u])*(n-sz[u]-1);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int m;cin>>n>>m;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;g[a].pb(b);g[b].pb(a);
}
for(int i=1;i<=n;i++){
if(di[i])continue;cnt=0;
dfs(i,i);st.clear();
rs+=cnt*(cnt-1)*(cnt-2);
solve(i,i);
}cout<<rs;
}
Compilation message (stderr)
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:58:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
58 | if(di[i])continue;cnt=0;
| ^~
count_triplets.cpp:58:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
58 | if(di[i])continue;cnt=0;
| ^~~
# | 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... |