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;
namespace {
const int MXN = 100005, K = 320, INF = 1e9;
int n, m, q;
vector<int> edge[MXN], edge_inv[MXN];
int ns[MXN];
pii dp[MXN][K * 2];
pii pd[3][K * 2];
bitset<MXN> b;
int dis[MXN];
void DP(int id) {
pd[0][0] = mp(0, id);
int nn = 1, nnn;
for (auto &pre : edge_inv[id]) {
debug(id, pre);
copy(dp[pre], dp[pre] + ns[pre], pd[2]);
FOR(i, 0, ns[pre]) pd[2][i].fs++;
merge(pd[0], pd[0] + nn, pd[2], pd[2] + ns[pre], pd[1], greater<pii>());
nnn = nn + ns[pre];
nn = 0;
FOR(i, 0, nnn) {
if (b[pd[1][i].sc]) continue;
b[pd[1][i].sc] = true;
pd[0][nn] = pd[1][i];
nn++;
}
FOR(i, 0, nn) b[pd[0][i].sc] = false;
nn = min(nn, K);
}
copy(pd[0], pd[0] + nn, dp[id]);
ns[id] = nn;
}
void PRE() {
FOR(i, 1, n + 1) DP(i);
// FOR(i, 1, n + 1) {
// cout << ns[i] << '\n';
// FOR(j, 0, ns[i]) cout << '<' << dp[i][j].fs << ' ' << dp[i][j].sc << '>' << ' ';
// cout << '\n';
// }
}
void BAO(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) {
auto DO = [&]() -> int {
if (t <= K) {
FOR(i, 0, ns[t]) {
auto [w, x] = dp[t][i];
if (!b[x]) return w;
}
return -1;
} else {
BAO(t);
int ans = -1;
FOR(i, 1, t + 1) {
if (b[i]) continue;
ans = max(ans, dis[i]);
}
return ans;
}
};
for (auto &i : v) b[i] = true;
int x = DO();
for (auto &i : v) b[i] = false;
return x;
}
}
vector<int> solve(int N, int M, int Q, vector<int> &S, vector<int> &E, vector<int> &T, vector<vector<int>> &Y) {
::n = N;
::m = M;
::q = Q;
FOR(i, 0, M) {
edge[S[i]].push_back(E[i]);
edge_inv[E[i]].push_back(S[i]);
}
PRE();
vector<int> ans;
FOR(i, 0, q) {
ans.push_back(calc(T[i], Y[i]));
}
return ans;
}
void miku() {
int n, m, q;
vector<vector<int>> y;
cin >> n >> m >> q;
vector<int> s(m), e(m);
FOR(i, 0, m) cin >> s[i] >> e[i];
vector<int> t(q);
FOR(i, 0, q) {
int k;
cin >> t[i] >> k;
y.push_back(vector<int>(k));
for (auto &i : y.back()) cin >> i;
}
vector<int> ans = solve(n, m, q, s, e, t, y);
for (auto &i : ans) cout << i << '\n';
}
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 {anonymous}::DP(int)':
bitaro.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
bitaro.cpp:35:13: note: in expansion of macro 'debug'
35 | debug(id, pre);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |