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>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 100005, K = 320, INF = 1e9;
int n, m, q;
vector<int> edge[MXN], edge_inv[MXN];
bitset<MXN> b;
int dis[MXN];
vector<pii> w[MXN];
void DP(int id) {
vector<pii> br, tmp;
for (auto &i : edge_inv[id]) {
for (auto &[j, x] : w[i]) br.push_back(mp(j, x + 1));
}
sort(br.begin(), br.end());
for (int i = 0, j = 0; i < br.size(); i = j) {
while (j < br.size() && br[i].fs == br[j].fs) j++;
tmp.push_back(br[j - 1]);
}
tmp.push_back(mp(id, 0));
sort(tmp.begin(), tmp.end(), [](pii a, pii b) -> bool {
return (a.sc == b.sc ? a.fs < b.fs : a.sc > b.sc);
});
while (tmp.size() > 321) tmp.pop_back();
w[id] = tmp;
}
void TS(int sr) {
fill(dis + 1, dis + n + 1, -INF);
dis[sr] = 0;
for (int id = sr - 1; id; id--) {
for (auto &i : edge[id]) dis[id] = max(dis[id], dis[i] + 1);
}
}
int calc(int t, vector<int> &v) {
// if (v.size() <= K) {
// for (auto [i, x] : w[t]) {
// if (b[i]) continue;
// return x;
// }
// return -1;
// } else {
TS(t);
int ans = -1;
FOR(i, 1, t + 1) {
if (b[i]) continue;
ans = max(ans, dis[i]);
}
return ans;
// }
return 0;
}
void miku() {
cin >> n >> m >> q;
while (m--) {
int x, y;
cin >> x >> y;
edge[x].push_back(y);
edge_inv[y].push_back(x);
}
FOR(i, 1, n + 1) DP(i);
while (q--) {
int t, y;
vector<int> v;
cin >> t >> y;
v.resize(y);
for (auto &i : v) {
cin >> i;
b[i] = true;
}
cout << calc(t, v) << '\n';
for (auto &i : v) {
b[i] = false;
}
}
// FOR(i, 1, n + 1) {
// debug(i);
// for (auto &[id, x] : w[i]) debug(id, x);
// }
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'void DP(int)':
bitaro.cpp:34: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]
34 | for (int i = 0, j = 0; i < br.size(); i = j) {
| ~~^~~~~~~~~~~
bitaro.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while (j < br.size() && br[i].fs == br[j].fs) 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... |