#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;
bool vis[3*N]{0};
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(cur+n);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);vis[u]=1;
for(auto v:bst[u]){
if(vis[u])continue;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15216 KB |
Output is correct |
3 |
Correct |
3 ms |
15192 KB |
Output is correct |
4 |
Correct |
3 ms |
15196 KB |
Output is correct |
5 |
Correct |
3 ms |
15196 KB |
Output is correct |
6 |
Correct |
3 ms |
15196 KB |
Output is correct |
7 |
Incorrect |
3 ms |
15196 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15216 KB |
Output is correct |
3 |
Correct |
3 ms |
15192 KB |
Output is correct |
4 |
Correct |
3 ms |
15196 KB |
Output is correct |
5 |
Correct |
3 ms |
15196 KB |
Output is correct |
6 |
Correct |
3 ms |
15196 KB |
Output is correct |
7 |
Incorrect |
3 ms |
15196 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
34248 KB |
Output is correct |
2 |
Correct |
52 ms |
33940 KB |
Output is correct |
3 |
Incorrect |
56 ms |
29716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
15192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
26004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
15192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
26192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15216 KB |
Output is correct |
3 |
Correct |
3 ms |
15192 KB |
Output is correct |
4 |
Correct |
3 ms |
15196 KB |
Output is correct |
5 |
Correct |
3 ms |
15196 KB |
Output is correct |
6 |
Correct |
3 ms |
15196 KB |
Output is correct |
7 |
Incorrect |
3 ms |
15196 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15216 KB |
Output is correct |
3 |
Correct |
3 ms |
15192 KB |
Output is correct |
4 |
Correct |
3 ms |
15196 KB |
Output is correct |
5 |
Correct |
3 ms |
15196 KB |
Output is correct |
6 |
Correct |
3 ms |
15196 KB |
Output is correct |
7 |
Incorrect |
3 ms |
15196 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |