# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644072 | valerikk | Bitaro’s Party (JOI18_bitaro) | C++17 | 2086 ms | 141132 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.
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 100001;
int n, m, q;
vector<int> g[MAXN];
bool bad[MAXN];
int dp[MAXN];
vector<pair<int, int>> best[MAXN];
bool used[MAXN];
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 0; i < m; ++i) {
int s, e;
scanf("%d%d", &s, &e);
--s, --e;
g[s].push_back(e);
}
for (int v = 0; v < n; ++v) {
best[v].push_back({0, v});
}
for (int v = 0; v < n; ++v) {
sort(best[v].rbegin(), best[v].rend());
for (auto p : best[v]) {
used[p.second] = false;
}
vector<pair<int, int>> tmp;
for (auto p : best[v]) {
if (tmp.size() == 100)
break;
if (!used[p.second]) {
tmp.push_back(p);
used[p.second] = true;
}
}
swap(best[v], tmp);
for (int u : g[v]) {
for (auto p : best[v]) {
best[u].push_back({p.first + 1, p.second});
}
}
}
while (q--) {
int t, y;
scanf("%d%d", &t, &y);
--t;
vector<int> c(y);
for (int i = 0; i < y; ++i) {
scanf("%d", &c[i]);
--c[i];
}
for (int i = 0; i < y; ++i) {
bad[c[i]] = true;
}
if (y >= 100) {
for (int v = 0; v < n; ++v) {
dp[v] = bad[v] ? -1 : 0;
}
for (int v = 0; v < n; ++v) {
if (dp[v] == -1)
continue;
for (int u : g[v]) {
dp[u] = max(dp[u], dp[v] + 1);
}
}
printf("%d\n", dp[t]);
} else {
int ans = -1;
for (auto p : best[t]) {
if (!bad[p.second])
ans = max(ans, p.first);
}
printf("%d\n", ans);
}
for (int i = 0; i < y; ++i) {
bad[c[i]] = false;
}
}
}
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... |