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 FAST_IO ios_base:;sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE_NAME "BITARO"
#define ll long long
using namespace std;
const int MAXN = 100001;
int n, m, q, t, y;
int d[MAXN];
bool mark[MAXN];
vector<int> adj[MAXN];
void findPath(int uStart)
{
memset(d, 0x3f, sizeof(d));
d[uStart] = 0;
priority_queue<pair<int, int> > pq;
pq.push({0, uStart});
while(!pq.empty()) {
int u = pq.top().second;
int du = -pq.top().first;
pq.pop();
if (du != d[u])
continue;
for (int v : adj[u]) {
if (d[v] > d[u]-1) {
d[v] = d[u]-1;
pq.push({-d[v], v});
}
}
}
}
int main()
{
// ifstream cin(FILE_NAME".INP");
// ofstream cout(FILE_NAME".OUT");
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
adj[v].push_back(u);
}
for (int loop = 1; loop <= q; ++loop) {
cin >> t >> y;
memset(mark, true, sizeof(mark));
for (int i = 1; i <= y; ++i) {
int c;
cin >> c;
mark[c] = false;
}
int res = 0;
findPath(t);
for (int i = 1; i <= n; ++i)
if (mark[i])
res = max(res, -d[i]);
if (res == 0 && mark[t] == false)
res = -1;
cout << res << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |