# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128559 | BThero | Bitaro’s Party (JOI18_bitaro) | C++17 | 2043 ms | 42120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)1e5 + 5;
vector<pair<vector<int>, int> > req[MAXN];
map<int, int> T[MAXN];
multiset<int> S[MAXN];
vector<int> par[MAXN];
bool del[MAXN];
int deg[MAXN];
int ans[MAXN];
int n, m, q;
void solve() {
scanf("%d %d %d", &n, &m, &q);
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d %d", &u, &v);
par[v].pb(u);
++deg[u];
}
for (int i = 1; i <= q; ++i) {
int v, sz;
scanf("%d %d", &v, &sz);
vector<int> tmp(sz);
for (int j = 0; j < sz; ++j) {
scanf("%d", &tmp[j]);
}
req[v].pb(mp(tmp, i));
}
for (int i = 1; i <= n; ++i) {
int mx = -1;
for (int p : par[i]) {
if (mx == -1 || T[p].size() > T[mx].size()) {
mx = p;
}
}
if (mx != -1) {
for (auto it : T[mx]) {
T[i][it.fi] = it.se + 1;
S[i].insert(it.se + 1);
}
if (--deg[mx] == 0) {
T[mx].clear();
S[mx].clear();
}
}
for (int p : par[i]) {
if (p == mx) {
continue;
}
for (auto it : T[p]) {
int cur = T[i][it.fi];
if (it.se + 1 > cur) {
if (cur != 0) {
S[i].erase(S[i].find(cur));
}
S[i].insert(it.se + 1);
T[i][it.fi] = it.se + 1;
}
}
if (--deg[p] == 0) {
T[p].clear();
S[p].clear();
}
}
T[i][i] = 0;
S[i].insert(0);
for (auto it : req[i]) {
vector<int> V = it.fi;
int id = it.se;
for (int x : V) {
auto it = T[i].find(x);
if (it != T[i].end()) {
S[i].erase(S[i].find(it -> se));
}
}
if (S[i].empty()) {
ans[id] = -1;
}
else {
ans[id] = *S[i].rbegin();
}
for (int x : V) {
auto it = T[i].find(x);
if (it != T[i].end()) {
S[i].insert(it -> se);
}
}
}
}
for (int i = 1; i <= q; ++i) {
printf("%d\n", ans[i]);
}
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |