Submission #203728

#TimeUsernameProblemLanguageResultExecution timeMemory
203728SegtreeDuathlon (APIO18_duathlon)C++14
8 / 100
145 ms10232 KiB
#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]; ll vcnt,ecnt; bool vis[N]; void dfs(ll x){ if(vis[x])return; vis[x]=1; vcnt++; for(auto y:g[x]){ ecnt++; dfs(y); } } 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); } ll ans=0; rep(i,n)vis[i]=0; rep(i,n){ if(vis[i]==0){ vcnt=ecnt=0; dfs(i); ecnt/=2; if(ecnt==vcnt-1)ans+=vcnt*(vcnt-1)*(vcnt-2)/3; else ans+=vcnt*(vcnt-1)*(vcnt-2); } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...