Submission #500072

#TimeUsernameProblemLanguageResultExecution timeMemory
500072kaxzertDuathlon (APIO18_duathlon)C++17
0 / 100
10 ms12152 KiB
/** ⚡⚡ ⚡⚡ ⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡⚡⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡ ⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡⚡⚡⚡⚡ ⚡⚡⚡⚡⚡ ⚡⚡ ⚡⚡ ⚡⚡ **/ #include<bits/stdc++.h> using namespace std; #define fto(i, a, b) for(int i = a; i <= b; ++i) #define fdto(i, a, b) for(int i = a; i >= b; --i) #define bugarr(a, i, j) cout << #a << "{" << i << "..." << j << "}:"; fto(k, i, j-1) cout << a[k] << ", "; cout << a[j] << endl; #define ll long long #define db double #define ldb long double #define ff first #define ss second #define pb push_back #define mp make_pair #define eb emplace_back #define vt vector #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define trav(i, a) for(auto &i : a) #define sz(a) (int)a.size() #define pi(a, b) pair<a, b> #define fast ios::sync_with_stdio(false); cin.tie(0) string to_bit(int n) { string res = ""; while(n > 0) { res += to_string(n&1); n >>= 1; } return res; } void setIO(string s) { if (sz(s) != 0) { freopen((s+".inp").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } void setIOusaco(string s) { if (sz(s) != 0) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } template<typename T, typename V> bool ckmin(T &a, V b) {return (b < a)? a = b, true : false;} template<typename T, typename V> bool ckmax(T &a, V b) {return (b > a)? a = b, true : false;} void print(int x) {cout << x;} void print(long long x) {cout << x;} void print(unsigned x) {cout << x;} void print(unsigned long long x) {cout << x;} void print(double x) {cout << fixed << x;} void print(long double x) {cout << fixed << x;} void print(char x) {cout << "'" << x << "'";} void print(string x) {cout << '"' << x << '"';} void print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void print(const pair<T, V> &x) {cout << '{'; print(x.ff); cout << ", "; print(x.ss); cout << '}';} template<typename T> void print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? ", " : ""), print(i); cout << "}";} void _print() {cout << "]" << endl;} template <typename T, typename... V> void _print(T t, V... v) {print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifdef TAP #define bug(x...) cout << "[" << #x << "] = ["; _print(x) #else #define bug(x...) #endif const int maxN = 100008; int low[maxN], num[maxN], cnt, color[maxN], articulation[maxN], root, child, n, m, dd[maxN]; vt<int> ke[maxN], block_ke[maxN*4]; ll cnt_color[maxN*4], ans; vt<vt<pi(int, int)> > bvccs; stack<pi(int, int)> s; void dfs(int u, int p = 0) { num[u] = low[u] = ++cnt; trav(v, ke[u]) { if (v == p) continue; if (num[v] == 0) { s.push({u, v}); if (u == root) ++child; dfs(v, u); if (low[v] >= num[u]) { articulation[u] = 1; vt<pi(int, int)> bvcc; while(s.top().ff != u || s.top().ss != v) { bvcc.pb(s.top()); s.pop(); } bvcc.pb(s.top()); s.pop(); bvccs.pb(bvcc); } ckmin(low[u], low[v]); } else { if (num[u] > num[v]) s.push({u, v}); ckmin(low[u], num[v]); } } } ll dfs2(int u, int p = 0, int is_cut = 1) { num[u] = 1; ll res = (is_cut ? 1 : cnt_color[u]); ll cntsth = 0; vt<ll> f; trav(v, block_ke[u]) { if (v == p) continue; f.pb(dfs2(v, u, is_cut^1)); if (is_cut == 0) ++cntsth; } if (is_cut == 0 && p != 0) ++cntsth; ll sth = accumulate(all(f), 0LL); f.pb(n-sth-res); ll sum = sth + (n-sth-res); bug(u, f, is_cut); trav(x, f) { ans += x*(sum-x)*res; bug(sum, sum-x); bug(ans); } if (is_cut^1) { if (cnt_color[u] >= 3) { ans += (cnt_color[u])*(cnt_color[u]-1)*(cnt_color[u]-2)*6LL; } if (cnt_color[u] >= 2) { trav(x, f) { ans += (cnt_color[u])*(cnt_color[u]-1)/2*x*4LL; } } if (cnt_color[u]+cntsth >= 3) { ans += (cnt_color[u]+cntsth-1)*(cnt_color[u]+cntsth-2)*cntsth; } } bug(u); bug(ans); return sth+res; } int main() { #ifndef TAP setIO("duatholon2018"); //setIOusaco("duatholon2018"); #endif fast; cin >> n >> m; fto(i, 1, m) { int u, v; cin >> u >> v; ke[u].pb(v); ke[v].pb(u); } fto(i, 1, n) { if (num[i] == 0) { root = i; child = 0; dfs(i, 0); articulation[i] = (child > 1); } } int dem = 0; fto(i, 1, n) { if (articulation[i]) { color[i] = ++dem; } } auto add = [&](int u) -> void { if (articulation[u]) { if (dd[u] != dem) { block_ke[dem].pb(color[u]); block_ke[color[u]].pb(dem); dd[u] = dem; } } else { cnt_color[dem] += dd[u]^1; dd[u] |= 1; color[u] = dem; } }; vt<int> dd(n+1, 0); trav(bvcc, bvccs) { ++dem; trav(canh, bvcc) { add(canh.ff); add(canh.ss); } } fto(i, 1, dem) { num[i] = 0; } fto(i, 1, dem) { if (num[i] == 0) { dfs2(i); } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'void setIO(std::string)':
count_triplets.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen((s+".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen((s+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp: In function 'void setIOusaco(std::string)':
count_triplets.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen((s+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen((s+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...