Submission #501570

#TimeUsernameProblemLanguageResultExecution timeMemory
501570kaxzertDuathlon (APIO18_duathlon)C++17
10 / 100
69 ms25596 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) (ll)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 = 200008; int low[maxN], num[maxN], bvcccnt = 1, N, cnt, n, sz[maxN]; vt<int> bvccs_ke[maxN], ke[maxN]; stack<int> s; ll ans; void dfs1(int u, int p = 0) { low[u] = num[u] = ++cnt; s.push(u); ++N; trav(v, ke[u]) { if (v == p) continue; if (num[v] == 0) { dfs1(v, u); ckmin(low[u], low[v]); if (low[v] >= num[u]) { bvccs_ke[u].pb(n+bvcccnt); while(s.top() != u) { bvccs_ke[n+bvcccnt].pb(s.top()); s.pop(); } ++bvcccnt; } } else ckmin(low[u], num[v]); } } void dfs2(int u) { sz[u] = (u <= n); trav(v, bvccs_ke[u]) { dfs2(v); sz[u] += sz[v]; if (u > n) ans -= sz(bvccs_ke[u])*sz[v]*(sz[v]-1); // bug(u, bvccs_ke[u]); // bug(sz[v]); // bug(ans); } if (u > n) ans -= sz(bvccs_ke[u])*(N-sz[u])*(N-sz[u]-1); // bug(u, bvccs_ke[u]); // bug(sz[u]); // bug(ans); } int main() { #ifndef TAP setIO(""); //setIOusaco("duatholon2018"); #endif fast; int m; 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) { N = 0; dfs1(i); ans += N*(N-1)*(N-2); 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...