Submission #49156

#TimeUsernameProblemLanguageResultExecution timeMemory
49156aintaDuathlon (APIO18_duathlon)C++17
100 / 100
379 ms44412 KiB
#include<cstdio> #include<algorithm> #include<vector> #define N_ 201000 using namespace std; int n, m, Num[N_], cnt, chk[N_], Up[N_], BC, C[N_], nn; vector<int>E[N_], Ch[N_], G[N_]; void DFS(int a) { nn++; Num[a] = ++cnt; Up[a] = cnt; for (auto &x : E[a]) { if (Num[x]) { Up[a] = min(Up[a], Num[x]); continue; } DFS(x); Ch[a].push_back(x); if (Up[x] >= Num[a]) { chk[x] = 1; } Up[a] = min(Up[a], Up[x]); } } void Add_Edge(int a, int b) { G[a].push_back(b); G[b].push_back(a); } void Make_BCC(int a, int b) { if(b!=0){ Add_Edge(a, b); } for (auto x : Ch[a]) { if (chk[x]) { BC++; Add_Edge(a, BC); Make_BCC(x, BC); } else { Make_BCC(x, b); } } } long long r1, r2, r3, SS[N_]; void Calc(int a, int pp) { if (a <= n)C[a] = 1; for (auto &x : G[a]) { if (x == pp)continue; Calc(x, a); C[a] += C[x]; } vector<int>T; for (auto &x : G[a]) { if (x != pp)T.push_back(C[x]); else T.push_back(nn - C[a]); } for (auto &t : T) SS[a] += 1ll * t*(t-1); } void Go(int a, int pp) { for (auto &x : G[a]) { if (x == pp)continue; Go(x, a); } if (a > n)return; long long s = 1ll * (nn - 1)*(nn - 2); for (auto &x : G[a]) { long long t; if (x == pp) { t = SS[x] - 1ll * C[a] * (C[a]-1); } else { t = SS[x] - 1ll * (nn - C[x])*(nn - C[x]-1); } s -= t; } r2 += s; } int main() { int i, a, b; scanf("%d%d", &n, &m); for (i = 0; i < m; i++) { scanf("%d%d", &a, &b); E[a].push_back(b); E[b].push_back(a); } BC = n; for (i = 1; i <= n; i++) { if (!Num[i]) { nn = 0; DFS(i); Make_BCC(i, 0); Calc(i, 0); Go(i, 0); } } printf("%lld\n", r2 ); return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
#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...