Submission #201131

#TimeUsernameProblemLanguageResultExecution timeMemory
201131extraterrestrialMeetings (JOI19_meetings)C++14
29 / 100
3075 ms8952 KiB
#include "meetings.h" //#pragma GCC optimize("Ofast") //#pragma GCC optimize("no-stack-protector") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() mt19937 rnd(228); const int N = 2010; short lca[N][N], used[N], timer, up[N][20], all; short nh[20][N], have[N][N], sz_nh[20], sz_have[N]; vector<pair<short, short>> pars[N]; short ptr[N], color[N], skip[N]; bool was[N]; inline short get(short a, short b) { if (a > b) { swap(a, b); } return lca[a][b]; } inline void update_lca(short a, short b, short c) { if (a > b) { swap(a, b); } lca[a][b] = c; } int get_color(int v) { if (color[v] != -1) { return color[v]; } if (ptr[v] >= SZ(pars[v])) { exit(0); } return color[v] = get_color(pars[v][ptr[v]].F); } vector<pair<int, int>> edge; void Solve(int n) { short root = rnd() % n; for (int i = 0; i < n; i++) { have[root][sz_have[root]++] = i; } queue<short> q; q.push(root); while (!q.empty()) { int root = q.front(); was[root] = true; q.pop(); if (sz_have[root] == 1) { continue; } short id = (have[root][0] == root ? 1 : 0); short cc = 1; nh[0][0] = have[root][id]; sz_nh[0] = 1; up[root][0] = have[root][id]; color[have[root][id]] = 0; timer++; used[have[root][id]] = timer; for (int i = 1; i < sz_have[root]; i++) { if (used[have[root][i]] == timer || have[root][i] == root) { continue; } color[have[root][i]] = -1; used[have[root][i]] = timer; while (ptr[have[root][i]] < SZ(pars[have[root][i]]) && was[pars[have[root][i]][ptr[have[root][i]]].S]) { ptr[have[root][i]]++; } if (ptr[have[root][i]] < SZ(pars[have[root][i]])) { skip[have[root][i]] = timer; continue; } for (int j = 0; j < cc; j++) { short v; v = (up[root][j] == have[root][i] ? have[root][i] : Query(root, up[root][j], have[root][i])); if (v != root) { if (v != up[root][j]) pars[up[root][j]].pb({have[root][i], v}); else if (have[root][i] != up[root][j]) pars[have[root][i]].pb({up[root][j], v}); up[root][j] = v; nh[j][sz_nh[j]] = have[root][i]; sz_nh[j]++; color[have[root][i]] = j; break; } } if (color[have[root][i]] == -1) { nh[cc][0] = have[root][i]; sz_nh[cc] = 1; up[root][cc] = have[root][i]; color[have[root][i]] = cc; cc++; } } for (int i = 0; i < cc; i++) { edge.pb({root, up[root][i]}); } for (int i = 0; i < sz_have[root]; i++) { if (have[root][i] != root && skip[have[root][i]] == timer) { get_color(have[root][i]); nh[color[have[root][i]]][sz_nh[color[have[root][i]]]] = have[root][i]; sz_nh[color[have[root][i]]]++; } } for (int i = 0; i < cc; i++) { for (int j = 0; j < sz_nh[i]; j++) { have[up[root][i]][j] = nh[i][j]; } sz_have[up[root][i]] = sz_nh[i]; } for (int i = 0; i < cc; i++) { q.push(up[root][i]); } } for (auto &it : edge) { if (it.F > it.S) { swap(it.F, it.S); } Bridge(it.F, it.S); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...