# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
554398 | Alexandruabcde | Bitaro’s Party (JOI18_bitaro) | C++14 | 1509 ms | 420024 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;
typedef pair <int, int> PII;
constexpr int NMAX = 1e5 + 5;
constexpr int BUCKET = 300;
int N, M, Q;
vector <int> To[NMAX];
vector <int> From[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> Q;
for (int i = 1; i <= M; ++ i ) {
int x, y;
cin >> x >> y;
To[x].push_back(y);
From[y].push_back(x);
}
}
/// length who
vector <pair <int, int> > Best[NMAX];
bool viz[NMAX];
vector <PII> MergeSort (int who, vector <PII> A, vector <PII> Before) {
int i = 0, j = 0;
vector <PII> ans;
while (ans.size() < BUCKET && (i < A.size() || j < Before.size())) {
if (i == A.size()) {
if (!viz[Before[j].second]) {
ans.push_back({Before[j].first + 1, Before[j].second});
}
viz[Before[j].second] = true;
++ j;
}
else if (j == Before.size()) {
if (!viz[A[i].second]) {
ans.push_back(A[i]);
}
viz[A[i].second] = true;
++ i;
}
else {
if (A[i].first >= Before[j].first + 1) {
if (!viz[A[i].second]) {
ans.push_back(A[i]);
}
viz[A[i].second] = true;
++ i;
}
else {
if (!viz[Before[j].second]) {
ans.push_back({Before[j].first+1, Before[j].second});
}
viz[Before[j].second] = true;
++ j;
}
}
}
for (auto it : ans)
viz[it.second] = false;
return ans;
}
void Precompute () {
for (int i = 1; i <= N; ++ i ) {
for (auto it : From[i]) {
Best[i] = MergeSort(i, Best[i], Best[it]);
}
if (Best[i].size() < BUCKET) {
Best[i].push_back({0, i});
}
}
}
bool busy[NMAX];
int dp[NMAX];
void Solve () {
for (; Q; -- Q ) {
int X, Y;
cin >> X >> Y;
vector <int> whom;
for (int i = 1; i <= Y; ++ i ) {
int a;
cin >> a;
whom.push_back(a);
busy[a] = 1;
}
int ans = -1;
if (Y < BUCKET) {
for (auto it : Best[X]) {
if (busy[it.second]) continue;
ans = max(ans, it.first);
}
}
else {
for (int i = 1; i <= N; ++ i )
dp[i] = -1;
dp[X] = 0;
for (int i = X; i >= 1; -- i ) {
for (auto it : To[i]) {
if (dp[it] == -1) continue;
dp[i] = max(dp[i], dp[it] + 1);
}
if (busy[i]) continue;
ans = max(ans, dp[i]);
}
}
cout << ans << '\n';
for (auto it : whom)
busy[it] = 0;
}
}
int main () {
Read();
Precompute();
Solve();
return 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... |