Submission #409565

#TimeUsernameProblemLanguageResultExecution timeMemory
409565juggernautDuathlon (APIO18_duathlon)C++17
100 / 100
232 ms61336 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif #define MAXN 400009 #define ll long long #define pb(x) push_back(x) #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; class Articulation { public: std::vector<int> keyV, bcc[MAXN]; int cnt; int gao(int n, const std::vector<int> e[]) { memset(tag, use = 0, sizeof(tag[0]) * n); memset(low, cnt = 0, sizeof(low[0]) * n); std::fill_n(bcc, n, keyV = std::vector<int>()); for (int i = 0; i < n; ++i) if (!tag[i]) dfs(i, 1, e); return cnt; } private: int tag[MAXN], low[MAXN], dot[MAXN], use; void dfs(int x, int dep, const std::vector<int> e[]) { int src = 0, out = 1 < dep; dot[use++] = x; tag[x] = low[x] = dep; for (auto &y: e[x]) { if (!tag[y]) { dfs(y, dep + 1, e); low[x] = std::min(low[x], low[y]); if (low[y] >= tag[x]) { if (++out == 2) keyV.push_back(x); while (dot[--use] != y) bcc[dot[use]].push_back(cnt); bcc[x].push_back(cnt); bcc[y].push_back(cnt++); } } else if (tag[y] != tag[x] - 1 || src++) { low[x] = std::min(low[x], tag[y]); } } } } bcc; vector<int> G[MAXN]; //APIO 2018 Duathlon /* Articulation based BCC(Biconnected Component) */ vector<int>adj[MAXN]; void add(int u,int v){ adj[u].pb(v); adj[v].pb(u); } int vis[MAXN],sub[MAXN],n,m; int comp_sz[MAXN]; void dfs(int nd,int pr){ sub[nd]=(nd<n); vis[nd]=1; for(auto to:adj[nd]) if(to!=pr) dfs(to,nd),sub[nd]+=sub[to]; } ll C2(int x){ return (x*1LL*(x-1)); } ll C3(int x){ return (C2(x)*1LL*(x-2)); } ll ans=0; void dfs1(int nd,int pr,int root){ if(nd<n){ for(auto to:adj[nd]){ if(to!=pr){ ans-=(comp_sz[to]-1)*1LL*C2(sub[root]-sub[to]); dfs1(to,nd,root); } else{ ans-=(comp_sz[to]-1)*1LL*C2(sub[nd]); } } } else{ for(auto to:adj[nd]) if(to!=pr) dfs1(to,nd,root); } } int main(){ scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ int u,v; scanf("%d%d",&u,&v); u--;v--; G[u].pb(v);G[v].pb(u); } int C = bcc.gao(n,G); for(int i=0;i<n;i++) for(auto to:bcc.bcc[i]){ add(i, to+n); comp_sz[to+n]++; } vector<int>roots; for(int i=n;i<n+C;i++) if(!vis[i]){ roots.pb(i); dfs(i,-1); } for(auto root:roots){ ans+=C3(sub[root]); dfs1(root,-1,root); } printf("%lld\n",ans); }

Compilation message (stderr)

count_triplets.cpp: In function 'void usaco(std::string)':
count_triplets.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |   scanf("%d%d",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~
#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...