#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
using namespace std;
const int N=1e5+5;
vi g[N];stack<int>st;
vector<int>bst[500001];ll x=0,n;
ll d[N]{0},lo[N]{0},t=0,ap[N]{0},id[N]{0},cur=1,isap[N]{0},sz[N];
void dfs(int u,int p){x++;
lo[u]=d[u]=++t;st.push(u);
for(auto v:g[u]){
if(!d[v]){
dfs(v,u);
lo[u]=min(lo[u],lo[v]);
if(d[u]<=lo[v]){
bst[u].pb(cur+n);bst[cur+n].pb(u);
while(bst[cur+n].empty()||bst[cur+n].back()!=v){
bst[cur+n].pb(st.top());bst[st.top()].pb(u);st.pop();
}cur++;
}
}
else if(v!=p)lo[u]=min(lo[u],d[v]);
}
}
ll ans=0;
void solve(int u){
sz[u]=(u<=n);
for(auto v:bst[u]){
solve(v);sz[u]+=sz[v];
if(u>n)ans-=sz[v]*(sz[v]-1)*(sz(bst[u])-1);
}
if(u>n)ans-=(x-sz[u])*(x-sz[u]-1)*(sz(bst[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 u,v;cin>>u>>v;
g[u].pb(v);g[v].pb(u);
}
for(int i=1;i<=n;i++){
if(d[i])continue;
dfs(i,i);solve(i);
ans+=(x)*(x-1)*(x-2);x=0,t=0;
}cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
621 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
587 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
621 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
581 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
620 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |