제출 #553451

#제출 시각아이디문제언어결과실행 시간메모리
553451urosk철인 이종 경기 (APIO18_duathlon)C++14
0 / 100
206 ms35272 KiB
// __builtin_popcount(x) // __builtin_popcountll(x) #define here cerr<<"===========================================\n" #include <bits/stdc++.h> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} using namespace std; #define maxn 100005 ll n,m; vector<ll> g[maxn]; vector<ll> v[maxn]; ll low[maxn]; ll in[maxn]; bool vis[maxn]; ll it = 1; vector<pll> br; map<pll,bool> mp; ll dsu[maxn]; ll siz[maxn]; ll sub[maxn]; ll root(ll x){ while(x!=dsu[x]){ dsu[x] = dsu[dsu[x]]; x = dsu[x]; } return x; } void upd(ll x,ll y){ x = root(x); y = root(y); dsu[x] = y; siz[y] += siz[x]; } void dfs(ll u,ll par){ in[u] = it++; low[u] = in[u]; for(ll s : g[u]){ if(s==par) continue; if(in[s]==0){ dfs(s,u); low[u] = min(low[u],low[s]); }else low[u] = min(low[u],in[s]); } if(u!=par&&low[u]>in[par]){ br.pb({u,par}); mp[{u,par}] = 1; mp[{par,u}] = 1; } } void dfs2(ll u){ vis[u] = 1; for(ll s : g[u]){ if(mp[{u,s}]) continue; if(vis[s]) continue; upd(u,s); dfs2(s); } } ll ans = 0; ll f3(ll x){ return x*(x-1)*(x-2)/6; } ll f2(ll x){ return x*(x-1)/2; } ll pari[maxn]; ll sizi = 0; void dfs3(ll u,ll par){ pari[u] = par; vis[u] = 1; ans+=f3(siz[u])*6; sub[u] = 0; for(ll s : v[u]){ if(s==par) continue; dfs3(s,u); sub[u]+=sub[s]+siz[s]; } //cerr<<u<< " "<<sub[u]<<" "<<siz[u]<<endl; ans+=(sub[u]*siz[u]*(sizi-siz[u]-sub[u])+f2(siz[u])*sub[u]*2 + f2(siz[u])*(sizi-sub[u]-siz[u])*2)*2; ans-=(siz[u]-1)*sub[u]*2; ans-=(siz[u]-1)*(sizi-siz[u]-sub[u])*2; } ll dfs4(ll u,ll par){ ll sum = siz[u]; for(ll s : v[u]){ if(s==par) continue; sum+=dfs4(s,u); } return sum; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n >> m; for(ll i = 1;i<=m;i++){ ll x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } iota(dsu+1,dsu+n+1,1); fill(siz+1,siz+n+1,1); for(ll i = 1;i<=n;i++) if(in[i]==0) dfs(i,i); //here; for(ll i = 1;i<=n;i++){ if(vis[i]) continue; dfs2(i); } for(pll p : br){ ll x = root(p.fi); ll y = root(p.sc); v[x].pb(y); v[y].pb(x); } fill(vis,vis+n+1,0); //here; //for(ll i = 1;i<=n;i++) cerr<<i<< " "<<root(i)<< " "<<siz[root(i)]<<endl; //here; //for(ll i = 1;i<=n;i++){ //cerr<<"i: "<<i<<endl; //for(ll x : v[i]) cerr<<x<< " "; //cerr<<endl; //} //here; for(ll i = 1;i<=n;i++){ ll j = root(i); if(vis[j]==0){ sizi = dfs4(j,j); //cerr<<"j: "<<j<< " "<<sizi<<endl; dfs3(j,j); //cerr<<endl; } } cout<<ans<<endl; return 0; } /* 4 3 1 2 2 3 3 4 out: 8 */ /* 4 4 1 2 2 3 3 4 4 2 out: 14 */
#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...