# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863870 | biximo | Bitaro’s Party (JOI18_bitaro) | C++17 | 813 ms | 93012 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>
#define N 100005
#define BL 100
using namespace std;
typedef pair<int, int> pi;
int n, m, q;
vector<int> paths[N], NOT;
vector<pi> dp[N];
bool added[N];
void dfs() {
for(auto&i: added) i = 0;
for(int cur = 1; cur <= n; cur ++) {
for(int i: paths[cur]) {
int a = 0, b = 0;
vector<pi> temp;
temp.reserve(BL);
while(temp.size() < BL && (a < dp[cur].size() || b < dp[i].size())) {
if(a == dp[cur].size() || (b < dp[i].size() && dp[cur][a].first + 1 < dp[i][b].first)) {
if(!added[dp[i][b].second]) temp.push_back(dp[i][b]);
added[dp[i][b].second] = 1;
b ++;
} else {
if(!added[dp[cur][a].second]) temp.push_back({dp[cur][a].first + 1, dp[cur][a].second});
added[dp[cur][a].second] = 1;
a ++;
}
}
for(int j = 0; j < a; j ++) added[dp[cur][j].second] = 0;
for(int j = 0; j < b; j ++) added[dp[i][j].second] = 0;
swap(temp, dp[i]);
}
}
}
int ANS[N];
bool allowed[N] = {0};
void DP() {
for(int cur = 1; cur <= n; cur ++) {
if(ANS[cur] == -1) continue;
for(int i: paths[cur]) {
ANS[i] = max(ANS[i], ANS[cur] + 1);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
for(int i = 1; i <= n; i ++) {
allowed[i] = 1;
dp[i].reserve(BL);
dp[i].push_back({0, i});
}
while(m--) {
int a, b;
cin >> a >> b;
paths[a].push_back(b);
}
dfs();
while(q--) {
int a, b;
cin >> a >> b;
NOT.resize(b);
for(auto&i: NOT) {
cin >> i;
allowed[i] = 0;
}
if(b >= BL) {
for(int i = 1; i <= n; i ++) {
if(allowed[i]) ANS[i] = 0;
else ANS[i] = -1;
}
DP();
cout << ANS[a] << "\n";
} else {
bool adde = true;
for(auto&[v, i]: dp[a]) {
if(allowed[i]) {
adde = false;
cout << (v) << "\n";
break;
}
}
if(adde) cout << -1 << "\n";
}
for(auto&i: NOT) allowed[i] = 1;
}
}
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... |