이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*input
4 4
1 2
2 3
3 4
4 2
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
const int maxn=1e5+5;
#define pb push_back
#define lowb(x) x&(-x)
#define ll long long
#define MNTO(x,y) x=min(x,y)
#define REP1(i,n) for(int i=1;i<=n;i++)
vector<int> v[maxn];
int vis[maxn];
int dep[maxn],low[maxn];
ll ans=0;
int sz[maxn];
int par[maxn][10];
void dfs(int u,int p){
low[u]=dep[u];
vis[u]=1;
sz[u]=1;
par[u][0]=p;
REP1(j,9){
if(par[u][j-1]==-1) par[u][j]=-1;
else par[u][j]=par[par[u][j-1]][j-1];
}
for(int x:v[u]){
if(x==p) continue;
if(vis[x]){
MNTO(low[u],low[x]);
}
}
for(int x:v[u]){
if(!vis[x]){
dep[x]=dep[u]+1;
dfs(x,u);
sz[u]+=sz[x];
MNTO(low[u],low[x]);
}
}
if(dep[u]>1) ans+=dep[u]-1;
}
void dfs3(int u,int p){
vis[u]=2;
for(int x:v[u]){
if(x==p) continue;
MNTO(low[u],low[x]);
if(vis[x]==1){
dfs3(x,u);
}
}
}
void dfs2(int u,int p){
vis[u]=3;
for(int x:v[u]){
if(x==p) continue;
if(vis[x]==2){
dfs2(x,u);
}
}
if(dep[u]-low[u]>1){
int k=dep[u]-low[u]-1;
int x=u;
while(k){
x=par[x][__lg(lowb(k))];
k-=lowb(k);
}
ans+=sz[x]-sz[u];
}
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,m;
cin>>n>>m;
REP(i,m){
int a,b;
cin>>a>>b;
--a,--b;
v[a].pb(b),v[b].pb(a);
}
REP(i,n){
REP(j,n) vis[j]=0;
dep[i]=0;
dfs(i,-1);
REP(j,9){
REP(k,n) vis[k]=1;
dfs3(i,-1);
}
dfs2(i,-1);
//cout<<ans<<' ';
}
cout<<ans<<'\n';
}
# | 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... |