#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int>& a, pair<int, int>& b){
return a.second > b.second;
}
signed main() {
int n, m ,q;
cin >> n >> m >> q;
vector<vector<int>> adj(n+5);
int s, e;
for(int i = 1; i <= m; i++) {
cin >> s >> e;
adj[e].push_back(s);
}
vector<int> pos(n + 5, -1);
vector<vector<pair<int, int>>> len(n+5);
for(int i = 1; i < n+1; i++) {
len[i].push_back({i, 0});
for (auto u : adj[i]) {
for (auto x : len[u]) {
if (pos[x.first] != -1 && x.second+1 > len[i][pos[x.first]].second) len[i][pos[x.first]].second=x.second+1;
else len[i].push_back({x.first, x.second + 1});
}
sort(len[i].begin(), len[i].end(), compare);
while (len[i].size() > 100) {
pos[len[i].back().first] = -1;
len[i].pop_back();
}
for(int j = 0; j < len[i].size(); j++) {
pos[len[i][j].first] = j;
}
}
for(int j = 0; j < len[i].size(); j++) {
pos[len[i][j].first] = -1;
}
}
vector<int> dp(n + 5, -1);
vector<bool> busy(n+5);
for(int i = 1; i <q+1; i++) {
int src, t;
cin >> src >> t;
vector<int> c(t);
for (int j = 0; j < t; j++) {
cin >> c[j];
busy[c[j]] = true;
}
int ans = -1;
if (t > 100) {
for(int j = 1; j < src+1; j++) {
for (int u : adj[j]) {
if (dp[u] != -1 && dp[u]+1 > dp[j]) dp[j]=dp[u]+1;
}
if (!busy[j] && dp[j] < 0) dp[j]=0;
if (j == src) {
ans = dp[j];
break;
}
}
fill(dp.begin(), dp.begin() + src + 1, -1);
} else {
for (auto x : len[src]) {
if (!busy[x.first]) {
ans = x.second;
break;
}
}
}
cout << (ans < 0 ? -1 : ans) << "\n";
for (int u : c) {
busy[u] = false;
}
}
}
Compilation message
bitaro.cpp: In function 'int main()':
bitaro.cpp:33:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = 0; j < len[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
bitaro.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int j = 0; j < len[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1372 KB |
Output is correct |
7 |
Correct |
5 ms |
1308 KB |
Output is correct |
8 |
Correct |
7 ms |
2144 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
6 ms |
2124 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
5 ms |
1624 KB |
Output is correct |
13 |
Correct |
6 ms |
1884 KB |
Output is correct |
14 |
Correct |
4 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1044 KB |
Output is correct |
16 |
Correct |
5 ms |
1372 KB |
Output is correct |
17 |
Correct |
5 ms |
1644 KB |
Output is correct |
18 |
Correct |
5 ms |
1120 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1372 KB |
Output is correct |
7 |
Correct |
5 ms |
1308 KB |
Output is correct |
8 |
Correct |
7 ms |
2144 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
6 ms |
2124 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
5 ms |
1624 KB |
Output is correct |
13 |
Correct |
6 ms |
1884 KB |
Output is correct |
14 |
Correct |
4 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1044 KB |
Output is correct |
16 |
Correct |
5 ms |
1372 KB |
Output is correct |
17 |
Correct |
5 ms |
1644 KB |
Output is correct |
18 |
Correct |
5 ms |
1120 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
20 |
Correct |
626 ms |
5196 KB |
Output is correct |
21 |
Correct |
622 ms |
5208 KB |
Output is correct |
22 |
Correct |
608 ms |
5208 KB |
Output is correct |
23 |
Correct |
607 ms |
5208 KB |
Output is correct |
24 |
Correct |
628 ms |
137808 KB |
Output is correct |
25 |
Correct |
607 ms |
138656 KB |
Output is correct |
26 |
Correct |
628 ms |
139092 KB |
Output is correct |
27 |
Correct |
726 ms |
176980 KB |
Output is correct |
28 |
Correct |
641 ms |
176980 KB |
Output is correct |
29 |
Correct |
685 ms |
176884 KB |
Output is correct |
30 |
Correct |
620 ms |
176468 KB |
Output is correct |
31 |
Correct |
667 ms |
171348 KB |
Output is correct |
32 |
Correct |
645 ms |
176720 KB |
Output is correct |
33 |
Correct |
513 ms |
106104 KB |
Output is correct |
34 |
Correct |
505 ms |
95628 KB |
Output is correct |
35 |
Correct |
518 ms |
106064 KB |
Output is correct |
36 |
Correct |
540 ms |
142856 KB |
Output is correct |
37 |
Correct |
588 ms |
133176 KB |
Output is correct |
38 |
Correct |
586 ms |
142928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
1372 KB |
Output is correct |
7 |
Correct |
5 ms |
1308 KB |
Output is correct |
8 |
Correct |
7 ms |
2144 KB |
Output is correct |
9 |
Correct |
6 ms |
2140 KB |
Output is correct |
10 |
Correct |
6 ms |
2124 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
5 ms |
1624 KB |
Output is correct |
13 |
Correct |
6 ms |
1884 KB |
Output is correct |
14 |
Correct |
4 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1044 KB |
Output is correct |
16 |
Correct |
5 ms |
1372 KB |
Output is correct |
17 |
Correct |
5 ms |
1644 KB |
Output is correct |
18 |
Correct |
5 ms |
1120 KB |
Output is correct |
19 |
Correct |
5 ms |
1628 KB |
Output is correct |
20 |
Correct |
626 ms |
5196 KB |
Output is correct |
21 |
Correct |
622 ms |
5208 KB |
Output is correct |
22 |
Correct |
608 ms |
5208 KB |
Output is correct |
23 |
Correct |
607 ms |
5208 KB |
Output is correct |
24 |
Correct |
628 ms |
137808 KB |
Output is correct |
25 |
Correct |
607 ms |
138656 KB |
Output is correct |
26 |
Correct |
628 ms |
139092 KB |
Output is correct |
27 |
Correct |
726 ms |
176980 KB |
Output is correct |
28 |
Correct |
641 ms |
176980 KB |
Output is correct |
29 |
Correct |
685 ms |
176884 KB |
Output is correct |
30 |
Correct |
620 ms |
176468 KB |
Output is correct |
31 |
Correct |
667 ms |
171348 KB |
Output is correct |
32 |
Correct |
645 ms |
176720 KB |
Output is correct |
33 |
Correct |
513 ms |
106104 KB |
Output is correct |
34 |
Correct |
505 ms |
95628 KB |
Output is correct |
35 |
Correct |
518 ms |
106064 KB |
Output is correct |
36 |
Correct |
540 ms |
142856 KB |
Output is correct |
37 |
Correct |
588 ms |
133176 KB |
Output is correct |
38 |
Correct |
586 ms |
142928 KB |
Output is correct |
39 |
Correct |
733 ms |
138392 KB |
Output is correct |
40 |
Correct |
607 ms |
137596 KB |
Output is correct |
41 |
Correct |
1000 ms |
138064 KB |
Output is correct |
42 |
Correct |
744 ms |
138324 KB |
Output is correct |
43 |
Correct |
637 ms |
137556 KB |
Output is correct |
44 |
Incorrect |
729 ms |
6352 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |