# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
185422 | Akashi | Bitaro’s Party (JOI18_bitaro) | C++14 | 38 ms | 6780 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;
const int N = 1e5;
const int K = 200;
int n, m, q;
bool viz[N + 5];
int h[N + 5], a[N + 5], dist[N + 5];
pair <int, int> d[N + 5][K + 5];
vector <int> v[N + 5], vt[N + 5];
set <pair <int, int> > s;
int main()
{
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n ; ++i)
for(int j = 1; j <= K ; ++j)
d[i][j] = {-1, -1};
int x, y;
for(int i = 1; i <= m ; ++i){
scanf("%d%d", &x, &y);
v[x].push_back(y);
vt[y].push_back(x);
}
for(int i = 1; i <= n ; ++i){
s.clear();
for(auto it : v[i])
h[it] = max(h[it], h[i] + 1);
s.insert({0, i});
for(auto it : vt[i]){
for(int k = 1; k <= K ; ++k){
if(d[it][k].first == -1) break ;
if(s.find({d[it][k].first + 1, d[it][k].second}) != s.end()) continue ;
if(s.size() < K) s.insert({d[it][k].first + 1, d[it][k].second});
else{
if(s.begin()->first < d[it][k].first + 1){
s.erase(s.begin());
s.insert({d[it][k].first + 1, d[it][k].second});
}
else break ;
}
}
}
set <pair <int, int> > :: reverse_iterator it = s.rbegin();
for(int k = 1; k <= K && it != s.rend() ; ++k, ++it) d[i][k] = *it;
}
while(q--){
scanf("%d%d", &x, &y);
for(int i = 1; i <= y ; ++i){
scanf("%d", &a[i]);
viz[a[i]] = 1;
}
int ans = -2;
for(int i = 1; i <= K ; ++i){
if(d[x][i].first == -1) {ans = -1; break ;}
if(!viz[d[x][i].second]) {ans = d[x][i].first; break ;}
}
if(ans == -2){
ans = -1;
dist[x] = 0;
for(int i = x - 1; i >= 1 ; --i){
dist[i] = -30000000;
for(auto it : v[i]) dist[i] = max(dist[it] + 1, dist[i]);
if(!viz[i]) ans = max(dist[i], ans);
}
}
printf("%d\n", ans);
for(int i = 1; i <= y ; ++i) viz[a[i]] = 0;
}
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... |