# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
646838 | tvladm2009 | Bitaro’s Party (JOI18_bitaro) | C++14 | 2077 ms | 149100 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 <bits/stdc++.h>
using ll = long long;
int const nmax = 100000;
int dp[1 + nmax];
std::vector<int> g[1 + nmax];
std::vector<std::pair<int, int>> sol[1 + nmax];
bool viz[1 + nmax], b[1 + nmax];
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
for(int i = 1;i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
}
for(int i = 1;i <= n; i++)
sol[i].push_back({0, i});
for(int u = 1;u <= n; u++) {
std::sort(sol[u].rbegin(), sol[u].rend());
for(auto p : sol[u])
viz[p.second] = false;
std::vector<std::pair<int, int>> aux;
for(auto v : sol[u]) {
if(aux.size() >= 120)
break;
if(!viz[v.second]) {
aux.push_back(v);
viz[v.second] = 1;
}
}
std::swap(sol[u], aux);
for(int v : g[u]) {
for(auto p : sol[u])
sol[v].push_back({p.first + 1, p.second});
}
}
while(q--) {
int to, y;
std::cin >> to >> y;
std::vector<int> c(y + 1);
for(int i = 1;i <= y; i++) {
int v;
std::cin >> v;
c[i] = v;
b[v] = true;
}
if(y >= 120) {
for(int i = 1;i <= n; i++) {
if(b[i])
dp[i] = -1;
else
dp[i] = 0;
}
for(int i = 1;i <= n; i++) {
if(dp[i] == -1)
continue;
for(int u : g[i])
dp[u] = std::max(dp[u], dp[i] + 1);
}
printf("%d\n", dp[to]);
} else {
int ans = -1;
for(auto p : sol[to]) {
if(!b[p.second])
ans = std::max(ans, p.first);
}
printf("%d\n", ans);
}
for(int i = 1;i <= y; i++)
b[c[i]] = false;
}
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... |