#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 |
1 |
Correct |
2 ms |
3180 KB |
Output is correct |
2 |
Correct |
2 ms |
3180 KB |
Output is correct |
3 |
Correct |
2 ms |
3180 KB |
Output is correct |
4 |
Correct |
2 ms |
3180 KB |
Output is correct |
5 |
Correct |
3 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3200 KB |
Output is correct |
7 |
Correct |
3 ms |
3180 KB |
Output is correct |
8 |
Correct |
4 ms |
3180 KB |
Output is correct |
9 |
Correct |
4 ms |
3180 KB |
Output is correct |
10 |
Correct |
4 ms |
3180 KB |
Output is correct |
11 |
Correct |
3 ms |
3180 KB |
Output is correct |
12 |
Correct |
4 ms |
3308 KB |
Output is correct |
13 |
Correct |
4 ms |
3180 KB |
Output is correct |
14 |
Correct |
3 ms |
3200 KB |
Output is correct |
15 |
Correct |
3 ms |
3180 KB |
Output is correct |
16 |
Correct |
5 ms |
3180 KB |
Output is correct |
17 |
Correct |
5 ms |
3180 KB |
Output is correct |
18 |
Correct |
4 ms |
3180 KB |
Output is correct |
19 |
Correct |
3 ms |
3180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3180 KB |
Output is correct |
2 |
Correct |
2 ms |
3180 KB |
Output is correct |
3 |
Correct |
2 ms |
3180 KB |
Output is correct |
4 |
Correct |
2 ms |
3180 KB |
Output is correct |
5 |
Correct |
3 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3200 KB |
Output is correct |
7 |
Correct |
3 ms |
3180 KB |
Output is correct |
8 |
Correct |
4 ms |
3180 KB |
Output is correct |
9 |
Correct |
4 ms |
3180 KB |
Output is correct |
10 |
Correct |
4 ms |
3180 KB |
Output is correct |
11 |
Correct |
3 ms |
3180 KB |
Output is correct |
12 |
Correct |
4 ms |
3308 KB |
Output is correct |
13 |
Correct |
4 ms |
3180 KB |
Output is correct |
14 |
Correct |
3 ms |
3200 KB |
Output is correct |
15 |
Correct |
3 ms |
3180 KB |
Output is correct |
16 |
Correct |
5 ms |
3180 KB |
Output is correct |
17 |
Correct |
5 ms |
3180 KB |
Output is correct |
18 |
Correct |
4 ms |
3180 KB |
Output is correct |
19 |
Correct |
3 ms |
3180 KB |
Output is correct |
20 |
Correct |
111 ms |
6640 KB |
Output is correct |
21 |
Correct |
114 ms |
5612 KB |
Output is correct |
22 |
Correct |
123 ms |
6252 KB |
Output is correct |
23 |
Correct |
100 ms |
5356 KB |
Output is correct |
24 |
Correct |
162 ms |
6636 KB |
Output is correct |
25 |
Correct |
165 ms |
6636 KB |
Output is correct |
26 |
Correct |
167 ms |
6636 KB |
Output is correct |
27 |
Correct |
172 ms |
7656 KB |
Output is correct |
28 |
Correct |
174 ms |
7940 KB |
Output is correct |
29 |
Correct |
180 ms |
8164 KB |
Output is correct |
30 |
Correct |
157 ms |
7148 KB |
Output is correct |
31 |
Correct |
165 ms |
7148 KB |
Output is correct |
32 |
Correct |
162 ms |
7148 KB |
Output is correct |
33 |
Correct |
160 ms |
6636 KB |
Output is correct |
34 |
Correct |
162 ms |
6508 KB |
Output is correct |
35 |
Correct |
158 ms |
6636 KB |
Output is correct |
36 |
Execution timed out |
2099 ms |
6700 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3180 KB |
Output is correct |
2 |
Correct |
2 ms |
3180 KB |
Output is correct |
3 |
Correct |
2 ms |
3180 KB |
Output is correct |
4 |
Correct |
2 ms |
3180 KB |
Output is correct |
5 |
Correct |
3 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3200 KB |
Output is correct |
7 |
Correct |
3 ms |
3180 KB |
Output is correct |
8 |
Correct |
4 ms |
3180 KB |
Output is correct |
9 |
Correct |
4 ms |
3180 KB |
Output is correct |
10 |
Correct |
4 ms |
3180 KB |
Output is correct |
11 |
Correct |
3 ms |
3180 KB |
Output is correct |
12 |
Correct |
4 ms |
3308 KB |
Output is correct |
13 |
Correct |
4 ms |
3180 KB |
Output is correct |
14 |
Correct |
3 ms |
3200 KB |
Output is correct |
15 |
Correct |
3 ms |
3180 KB |
Output is correct |
16 |
Correct |
5 ms |
3180 KB |
Output is correct |
17 |
Correct |
5 ms |
3180 KB |
Output is correct |
18 |
Correct |
4 ms |
3180 KB |
Output is correct |
19 |
Correct |
3 ms |
3180 KB |
Output is correct |
20 |
Correct |
111 ms |
6640 KB |
Output is correct |
21 |
Correct |
114 ms |
5612 KB |
Output is correct |
22 |
Correct |
123 ms |
6252 KB |
Output is correct |
23 |
Correct |
100 ms |
5356 KB |
Output is correct |
24 |
Correct |
162 ms |
6636 KB |
Output is correct |
25 |
Correct |
165 ms |
6636 KB |
Output is correct |
26 |
Correct |
167 ms |
6636 KB |
Output is correct |
27 |
Correct |
172 ms |
7656 KB |
Output is correct |
28 |
Correct |
174 ms |
7940 KB |
Output is correct |
29 |
Correct |
180 ms |
8164 KB |
Output is correct |
30 |
Correct |
157 ms |
7148 KB |
Output is correct |
31 |
Correct |
165 ms |
7148 KB |
Output is correct |
32 |
Correct |
162 ms |
7148 KB |
Output is correct |
33 |
Correct |
160 ms |
6636 KB |
Output is correct |
34 |
Correct |
162 ms |
6508 KB |
Output is correct |
35 |
Correct |
158 ms |
6636 KB |
Output is correct |
36 |
Execution timed out |
2099 ms |
6700 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |