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<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define N 100010
ll n,m;
vector<ll> g[N];
bool vis[N];
ll ans;
ll dp1[N],dp2[N];
void dfs(ll x){
vis[x]=1;
ll v1=1,v2=0;
for(auto y:g[x])if(vis[y]==0){
dfs(y);
ans+=v1*dp2[y]+v2*dp1[y];
v1+=dp1[y],v2+=dp2[y];
}
dp1[x]=v1;
dp2[x]=v2+v1;
}
int main(){
ll n,m; cin>>n>>m;
rep(i,m){
ll a,b; cin>>a>>b;
a--,b--;
g[a].push_back(b);
g[b].push_back(a);
}
ans=0;
rep(i,n)vis[i]=0;
rep(i,n){
if(vis[i]==0){
dfs(i);
}
}
ans-=n*(n-1)/2;
ans*=2;
cout<<ans<<endl;
}
# | 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... |