//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 200010;
int n,m;
vector <int> edge[maxn];
vector <int> tree[maxn];
ll dp[maxn][2],dpp[maxn][2];
int dfn[maxn],low[maxn];
int tot = 0,cnt;
ll ans = 0;
stack <int> s;
void solve(int u,int fa) {
dfn[u] = 1;
if (u<=n) dp[u][0]++;
for (int v:tree[u]) {
if (v==fa) continue;
// debug(u),debug(v);
solve(v,u);
dp[u][0] += dp[v][0];
dp[u][1] += dp[v][1];
if (u<=n) dp[u][1] += dp[v][0];
dpp[u][0] += dpp[v][0];
}
if (u<=n) {
ll cnt = 0;
// debug(u),debug(ans);
for (int v:tree[u]) {
if (v==fa) continue;
ans += cnt*dp[v][0];
cnt += dp[v][0];
ans += dp[v][1];
ans += dpp[v][0] + dpp[v][1];
// debug(dpp[v][1]),debug(dpp[v][0]);
}
// debug(ans);
}
else {
ll cnt = 0;
for (int v:tree[u]) {
if (v==fa) continue;
dpp[u][1] += cnt*dp[v][0];
cnt += dp[v][0];
dpp[u][0] += (SZ(tree[u])-2)*dp[v][0];
}
}
}
void tarjan(int u,int fa) {
dfn[u] = low[u] = tot++;
s.push(u);
for (int v:edge[u]) {
if (v==fa) continue;
if (dfn[v]==-1) {
tarjan(v,u);
low[u] = min(low[u],low[v]);
// cout<<u<<" "<<v<<" "<<dfn[u]<<" "<<low[v]<<endl;
if (low[v]>=dfn[u]) {
while (1) {
int cur = s.top();
s.pop();
tree[cnt].pb(cur);
tree[cur].pb(cnt);
if (cur==v) break;
}
tree[cnt].pb(u);
tree[u].pb(cnt);
cnt++;
}
}
else low[u] = min(low[u],dfn[v]);
}
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
memset(low,-1,sizeof(low));
memset(dfn,-1,sizeof(dfn));
cin>>n>>m;
cnt=n+1;
rep(i,0,m) {
int u,v;
cin>>u>>v;
edge[u].pb(v);
edge[v].pb(u);
}
rep(i,1,n+1) if (dfn[i]==-1) tarjan(i,-1);
memset(dfn,-1,sizeof(dfn));
rep(i,1,n+1) if (dfn[i]==-1) solve(i,-1);
cout<<2*ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
30436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
120 ms |
27060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
104 ms |
27052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |