# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030219 | SamuellH12 | Bitaro’s Party (JOI18_bitaro) | C++17 | 2102 ms | 101408 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>
#define ALL(x) x.begin(), x.end()
#define pii pair<int,int>
const int MAXN = 1e5 + 1;
const int SQRT = 35;
using namespace std;
int block[MAXN], dp[MAXN], tempo;
vector<int> trafo[MAXN], order;
vector<pii> best[MAXN];
int main(){
ios::sync_with_stdio(false);
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
for(int i=0, u, v; i<m; i++)
{
scanf("%d %d", &u, &v);
trafo[v].push_back(u);
dp[u]++;
}
deque<int> fila;
for(int i=1; i<=n; i++) if(!dp[i]) fila.push_back(i);
while(!fila.empty())
{
int u = fila.front(); fila.pop_front();
order.push_back(u);
for(int v : trafo[u])
if(--dp[v] == 0)
fila.push_back(v);
}
reverse(ALL(order));
for(int u : order)
{
best[u].push_back(pii(0, u));
for(auto v : trafo[u])
for(auto [x, w] : best[v])
best[u].push_back(pii(x-1, w));
sort(ALL(best[u]));
best[u].resize(min(SQRT, (int)(unique(ALL(best[u])) - best[u].begin())));
}
int t, y;
while(q--)
{
tempo++;
scanf("%d %d", &t, &y);
for(int i=0, x; i<y; i++)
{
scanf("%d", &x);
block[x] = tempo;
}
int ans = -1;
for(auto [x, w] : best[t])
if(block[w] != tempo)
{
ans = -x;
break;
}
if(ans == -1) for(int u : order)
{
dp[u] = (block[u] == tempo ? -1 : 0);
for(auto v : trafo[u])
if(~dp[v])
dp[u] = max(dp[u], dp[v]+1);
if(u == t){ ans = dp[u]; break; }
}
printf("%d\n", ans);
}
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... |