제출 #201090

#제출 시각아이디문제언어결과실행 시간메모리
201090extraterrestrialMeetings (JOI19_meetings)C++14
29 / 100
2417 ms8912 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]; 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; } vector<pair<int, int>> edge; void Solve(int n) { /*for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { lca[i][j] = i; } else { lca[i][j] = -1; } } }*/ 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(); assert(!was[root]); 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]; timer++; used[have[root][id]] = timer; vector<short> order; for (int i = 0; i < 18; i++) { order.pb(i); } shuffle(all(order), rnd); for (int i = 1; i < sz_have[root]; i++) { if (used[have[root][i]] == timer || have[root][i] == root) { continue; } used[have[root][i]] = timer; bool ok = false; for (int j : order) { if (j >= cc) { continue; } short v; /*if (get(up[root][j], have[root][i]) != -1) { v = get(up[root][j], have[root][i]); } else {*/ v = Query(root, up[root][j], have[root][i]); //} if (v != root) { if (v == up[root][j]) { //update_lca(v, up[root][j], up[root][j]); nh[j][sz_nh[j]] = have[root][i]; sz_nh[j]++; ok = true; break; } else { //update_lca(have[root][i], v, v); used[v] = timer; up[root][j] = v; nh[j][sz_nh[j]] = have[root][i]; sz_nh[j]++; if (v != have[root][i]) { nh[j][sz_nh[j]] = v; sz_nh[j]++; } ok = true; break; } } } if (!ok) { nh[cc][0] = have[root][i]; sz_nh[cc] = 1; up[root][cc] = have[root][i]; cc++; } } for (int i = 0; i < cc; i++) { edge.pb({root, up[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...