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 <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
vector<pair<int, int>> a[100005];
vector<int> g[100005];
int h = 400, dd[100005], b[100005], f[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
a[1].push_back({0, 1});
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
g[v].push_back(u);
}
memset(b, -1, sizeof b);
for (int i = 1; i <= n; i++) {
a[i].push_back({0, i});
vector<int> v;
for (int w : g[i]) {
for (auto x : a[w]) {
if (b[x.second] == -1) v.push_back(x.second);
if (b[x.second] < x.first + 1) {
b[x.second] = x.first + 1;
}
}
}
for (int w : v) {
a[i].push_back({b[w], w});
b[w] = -1;
}
sort(a[i].begin(), a[i].end(), greater<pair<int, int>>());
while (a[i].size() > h) a[i].pop_back();
}
for (int jj = 0; jj < q; jj++) {
int x, y;
cin >> x >> y;
vector<int> v;
for (int i = 0; i < y; i++) {
int z;
cin >> z;
dd[z] = 1;
v.push_back(z);
}
if (y < h) {
int flag = 0;
for (auto w : a[x]) {
if (dd[w.second] == 0) {
cout << w.first;
flag = 1;
break;
}
}
if (flag == 0) cout << -1;
}
else {
for (int i = 1; i <= x; i++) {
if (dd[i] == 1) {
f[i] = -1e9;
}
else f[i] = 0;
}
for (int i = 1; i <= x; i++) {
for (int w : g[i]) {
f[i] = max(f[i], f[w] + 1);
}
}
if (f[x] < 0) cout << -1;
else cout << f[x];
}
cout << '\n';
for (int w : v) dd[w] = 0;
}
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:37:28: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | while (a[i].size() > h) a[i].pop_back();
| ~~~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |