# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47799 | Just_Solve_The_Problem | Bitaro’s Party (JOI18_bitaro) | C++11 | 26 ms | 11696 KiB |
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;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");
#define random (rand() ^ (rand() << 15))
const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
int sq = 300;
int n, m, q;
vector < int > gr[N], rgr[N];
vector < pii > dp[N];
bool bad[N];
vector < pii > mergevector(vector < pii > v1, vector < pii > v2) {
vector < pii > ret;
int c1, c2;
c1 = c2 = 0;
while (c1 < sz(v1) && c2 < sz(v2) && sz(ret) < sq) {
int val1 = v1[c1].fr;
int val2 = v2[c2].fr + 1;
if (val1 > val2) {
ret.pb(mk(val1, v1[c1].sc));
c1++;
} else {
ret.pb(mk(val2, v2[c2].sc));
c2++;
}
}
while (sz(ret) < sq && c1 < sz(v1)) {
ret.pb(v1[c1++]);
}
while (sz(ret) < sq && c2 < sz(v2)) {
ret.pb(v2[c2++]);
}
return ret;
}
int solve(int v) {
vector < int > dp1;
dp1.resize(n + 1, -inf);
dp1[v] = 0;
int ret = -1;
if (!bad[v]) ret = 0;
for (int i = v; i > 0; i--) {
for (int to : gr[i]) {
dp1[i] = max(dp1[i], dp1[to] + 1);
}
if (!bad[i]) {
ret = max(ret, dp1[i]);
}
}
return ret;
}
main() {
scanf("%d %d %d", &n, &m, &q);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d %d", &u, &v);
gr[u].pb(v);
rgr[v].pb(u);
}
for (int i = 1; i <= n; i++) {
dp[i].pb(mk(0, i));
for (int to : rgr[i]) {
dp[i] = mergevector(dp[i], dp[to]);
}
}
while (q--) {
int t, y;
scanf("%d %d", &t, &y);
vector < int > v;
for (int i = 1; i <= y; i++) {
int x;
scanf("%d", &x);
bad[x] = 1;
v.pb(x);
}
int ans = -1;
if (y < sq) {
ans = solve(t);
} else {
for (auto to : dp[t]) {
if (bad[to.sc]) continue;
ans = max(ans, to.fr);
}
}
printf("%d\n", ans);
for (int to : v) {
bad[to] = 0;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |