# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62550 | gusfring | Bitaro’s Party (JOI18_bitaro) | C++14 | 1967 ms | 110968 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 pii pair<int, int>
#define fi first
#define se second
const int mxN=1e5, bs=80;
int n, m, q, dp2[mxN], c[mxN];
vector<int> adj[mxN];
vector<pii> dp1[mxN];
priority_queue<pii, vector<pii>, greater<pii>> pq;
bool a[mxN];
int main() {
scanf("%d %d %d", &n, &m, &q);
while(m--) {
int u, v;
scanf("%d %d", &u, &v);
--u, --v;
adj[v].push_back(u);
}
for(int i=0; i<n; ++i) {
pq.push({0, i});
for(int v : adj[i]) {
for(pii p : dp1[v]) {
pq.push({p.fi+1, p.se});
if(pq.size()>bs)
pq.pop();
}
}
while(!pq.empty()) {
dp1[i].push_back(pq.top());
pq.pop();
}
}
while(q--) {
int t, y, ans=-1;
scanf("%d %d", &t, &y);
--t;
for(int i=0; i<y; ++i) {
scanf("%d", &c[i]);
--c[i];
a[c[i]]=1;
}
if(y>bs) {
memset(dp2, -1, 4*(t+1));
for(int i=0; i<=t; ++i) {
dp2[i]=a[i]?-n:0;
for(int v : adj[i])
dp2[i]=max(dp2[v]+1, dp2[i]);
}
ans=max(dp2[t], ans);
} else {
for(int i=dp1[t].size()-1; i>=0; --i) {
if(a[dp1[t][i].se])
continue;
ans=dp1[t][i].fi;
break;
}
}
for(int i=0; i<y; ++i)
a[c[i]]=0;
printf("%d\n", ans);
}
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... |