This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define X first
#define Y second
constexpr int N = 1e5 + 5;
constexpr int SQ = 100;
int mark[N], dp[N];
vector<pii> best[N];
vector<int> adj[N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--; v--;
adj[v].push_back(u);
}
int timer = 1;
for (int i = 0; i < n; i++) {
vector<pii> now;
now.emplace_back(0, i);
for (auto &j : adj[i]) {
for (pii const& p : best[j]) {
now.emplace_back(p.X + 1, p.Y);
}
}
sort(begin(now), end(now), greater<>());
for (int j = 0; best[i].size() <= SQ && j < now.size(); j++) {
if (mark[now[j].Y] == timer)
continue;
mark[now[j].Y] = timer;
best[i].push_back(now[j]);
}
timer++;
}
while (q --> 0) {
int t, cnt;
cin >> t >> cnt;
t--;
for (int i = 0; i < cnt; i++) {
int u; cin >> u; u--;
mark[u] = timer;
}
if (cnt > SQ) {
memset(dp, 0, n * sizeof(dp[0]));
for (int i = 0; i < n; i++) {
if (mark[i] == timer)
dp[i] = -1;
for (auto &j : adj[i]) if (dp[j] != -1) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
cout << dp[t] << '\n';
} else {
int ans = -1;
for (pii const& p : best[t]) {
if (mark[p.Y] != timer) {
ans = p.X;
break;
}
}
cout << ans << '\n';
}
timer++;
}
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:39:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int j = 0; best[i].size() <= SQ && j < now.size(); j++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |