제출 #568553

#제출 시각아이디문제언어결과실행 시간메모리
568553piOOEDuathlon (APIO18_duathlon)C++17
100 / 100
174 ms33552 KiB
//#define _GLIBCXX_DEBUG //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> // //using namespace __gnu_pbds; // //template<typename T> //using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<>>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define trace(x) cout << #x << ": " << (x) << endl; #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define uniq(x) x.resize(unique(all(x)) - begin(x)) #define sz(s) ((int) size(s)) #define pii pair<int, int> #define mp(x, y) make_pair(x, y) #define int128 __int128 #define pb push_back #define popb pop_back #define eb emplace_back #define fi first #define se second #define itn int typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef double db; typedef unsigned int uint; template<typename T> bool ckmn(T &x, T y) { if (x > y) { x = y; return true; } return false; } template<typename T> bool ckmx(T &x, T y) { if (x < y) { x = y; return true; } return false; } int bit(int x, int b) { return (x >> b) & 1; } int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; } const ll infL = 3e18; const int infI = 1000000000 + 7; const int infM = 0x3f3f3f3f; //a little bigger than 1e9 const ll infML = 0x3f3f3f3f3f3f3f3fLL; //4.5e18 const int N = 100002, M = 200002; const int mod = 998244353; const ld eps = 1e-9; vector<pair<int, int>> g[N]; vector<int> gr[N * 3]; int tin[N], fup[N], T = 0, n, m, last = 0, k, col[M], U[M], V[M], sz[N * 3], nn[N * 3]; int nww = 0; bool used[N * 3]; ll ans = 0; void precalc(int v, int p) { ++nww; used[v] = true; tin[v] = fup[v] = T++; for (auto [to, i]: g[v]) { if (to == p) continue; if (!used[to]) { precalc(to, v); ckmn(fup[v], fup[to]); } else { ckmn(fup[v], tin[to]); } } } void zhfs(int v, int j) { if (j != -1) { gr[col[j] + n].push_back(v); gr[v].push_back(col[j] + n); } used[v] = true; for (auto [to, i]: g[v]) { if (i == j) continue; if (!used[to]) { if (j == -1 || fup[to] >= tin[v]) { col[i] = last++; gr[v].push_back(col[i] + n); gr[col[i] + n].push_back(v); } else { col[i] = col[j]; } zhfs(to, i); } else if (tin[to] < tin[v]) { col[i] = col[j]; } } } void dfs(int v, int p) { sz[v] = (v < n); used[v] = true; int cntt = 0; for (int to : gr[v]) { if (!used[to]) ++cntt; } for (int to: gr[v]) { if (!used[to]) { dfs(to, v); if (v >= n) { ans -= cntt * 1LL * sz[to] * (sz[to] - 1); } sz[v] += sz[to]; } } if (v >= n) { ans -= cntt * 1LL * (nww - sz[v]) * (nww - sz[v] - 1); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; U[i] = a, V[i] = b; g[a].eb(b, i), g[b].eb(a, i); } for (int i = 0; i < n; ++i) { if (!used[i]) { nww = 0; precalc(i, -1); nn[i] = nww; ans += nww * 1LL * (nww - 1) * (nww - 2); } } memset(used, 0, sizeof(used)); for (int i = 0; i < n; ++i) { if (!used[i]) { zhfs(i, -1); } } k = n + last; memset(used, 0, sizeof(used)); for (int i = 0; i < k; ++i) { if (!used[i]) { nww = nn[i]; dfs(i, -1); } } cout << ans; return 0; }
#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...