# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370605 | nafis_shifat | Bitaro’s Party (JOI18_bitaro) | C++14 | 1455 ms | 415084 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 ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5 +5;
const int inf=1e9;
const int B = 320;
int n,m,q;
vector<int> adj[mxn];
vector<pii> city[mxn];
int vis[mxn] = {};
int main() {
cin >> n >> m >> q;
for(int i = 1; i <= m; i++) {
int u,v;
scanf("%d%d",&u, &v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++) {
city[i].push_back({0,i});
vis[i] = 1;
int ind = 1;
for(int j : adj[i]) {
for(pii k : city[j]) {
int u = k.second;
int dist = k.first + 1;
if(vis[u]) {
city[i][vis[u] - 1] = max(city[i][vis[u] - 1],{dist,u});
} else {
ind++;
city[i].push_back({dist,u});
vis[u] = ind;
}
}
}
nth_element(city[i].begin(),city[i].begin() + B,city[i].end(),greater<pii>());
for(pii j : city[i]) vis[j.second] = 0;
while(city[i].size() > B) city[i].pop_back();
}
int blocked[n + 1] = {};
while(q--) {
int d,k;
scanf("%d%d",&d,&k);
vector<int> C;
for(int i = 1; i <= k; i++) {
int x;
scanf("%d",&x);
C.push_back(x);
blocked[x] = 1;
}
if(k >= B) {
int dp[d+1];
for(int i = 1; i <= d; i++) dp[i] = -inf;
dp[d] = 0;
for(int i = d; i >= 1; i--) {
for(int j : adj[i]) {
if(dp[j] < dp[i] + 1) dp[j] = dp[i] + 1;
}
}
int ans = -1;
for(int i = 1; i <= d; i++) {
if(blocked[i]) continue;
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
} else {
int ans = -1;
for(pii i : city[d]) {
int u = i.second;
if(blocked[u]) continue;
ans = max(ans,i.first);
}
printf("%d\n",ans);
}
for(int i : C) blocked[i] = 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... |