# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47775 | Talant | Bitaro’s Party (JOI18_bitaro) | C++17 | 0 ms | 0 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 mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;
int n,m,q;
int l,r;
int t,y,x;
int d[N],u[N];
vector <int> g[N];
priority_queue<pair<int,int> > q;
void djk(int v) {
for (int i = 1; i <= n; i ++)
d[i] = -inf;
d[v] = 0;
q.push({0,v});
while (!q.empty()) {
int v = q.top().sc,cur = q.top().fr;
q.pop();
if (cur < d[v])
continue;
for (auto to : g[v]) {
if (d[v] + 1 > d[to]) {
d[to] = d[v] + 1;
q.push({d[to],to});
}
}
}
}
main () {
scan(n);scan(m);scan(q);
for (int i = 1; i <= m; i ++) {
scan(l);scan(r);
g[r].pb(l);
}
while (q --) {
scan(t);scan(y);
djk(t);
int ans = -1;
for (int i = 1; i <= y; i ++) {
scan(x);
u[x] = 1;
}
for (int i = 1; i <= n; i ++)
if (!u[i]) ans = max(ans,d[i]);
printf("%d\n", ans);
}
}