제출 #50066

#제출 시각아이디문제언어결과실행 시간메모리
50066tmwilliamlin168철인 이종 경기 (APIO18_duathlon)C++14
100 / 100
178 ms28156 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long inline int in() { int result = 0; char ch = getchar_unlocked(); while (true) { if(ch >= '0' && ch <= '9') break; ch = getchar_unlocked(); } result = ch-'0'; while(true) { ch = getchar_unlocked(); if (ch < '0' || ch > '9') break; result = result*10 + (ch - '0'); } return result; } inline void out(ll x) { ll rev=x; int count = 0; if(x == 0) { putchar_unlocked('0'); return; } while((rev % 10) == 0) { ++count; rev /= 10; } //obtain the count of the number of 0s rev = 0; while(x != 0) { rev = rev*10 + x % 10; x /= 10; } //store reverse of N in rev while(rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10; } while(count--) putchar_unlocked('0'); } const int mxN=1e5; int n, m, dt=1, tin[mxN], low[mxN], st[mxN], sth, bccI; vector<int> adj1[mxN], adj2[2*mxN]; ll sz[2*mxN], n2, ans; void dfs1(int u, int p) { tin[u]=low[u]=dt++; st[sth++]=u; ++n2; for(int v : adj1[u]) { if(!tin[v]) { dfs1(v, u); low[u]=min(low[v], low[u]); if(low[v]>=tin[u]) { adj2[u].push_back(bccI+n); while(adj2[bccI+n].empty()||adj2[bccI+n].back()!=v) adj2[bccI+n].push_back(st[--sth]); ++bccI; } } else if(v!=p) low[u]=min(tin[v], low[u]); } } void dfs2(int u, int p) { sz[u]=u<n; for(int v : adj2[u]) { dfs2(v, u); sz[u]+=sz[v]; if(u>=n) ans-=(adj2[u].size()-(p==-1))*sz[v]*(sz[v]-1); } if(u>=n) ans-=adj2[u].size()*(n2-sz[u])*(n2-sz[u]-1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); n=in(), m=in(); while(m--) { int u=in()-1, v=in()-1; adj1[u].push_back(v); adj1[v].push_back(u); } for(int i=0; i<n; ++i) { if(tin[i]) continue; dfs1(i, -1); ans+=n2*(n2-1)*(n2-2); dfs2(i, -1); n2=0; } out(ans); }
#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...