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 MAXN 100010
int n;
vector<int> v[MAXN];
vector<int> rv[MAXN];
int fullSolution(int x, vector<bool> &on){
vector<int> pd(n, -1);
pd[x] = 0;
for(int i = x - 1; i >= 0; --i){
for(auto y : v[i]){
if(y <= x && pd[y] != -1){
pd[i] = max(pd[i], pd[y] + 1);
}
}
}
int ans = -1;
for(int i = 0; i <= x; ++i){
// cout << pd[i] << endl;
if(on[i]) ans = max(ans, pd[i]);
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m, q; cin >> n >> m >> q;
for(int i = 0; i < m; ++i){
int a, b; cin >> a >> b; a--, b--;
if(a > b) swap(a, b);
v[a].push_back(b);
rv[b].push_back(a);
}
int block = sqrt(n) + 3;
// cout << block << endl;
vector<vector<pair<int,int>>> bestDists(n);
for(int i = 0; i < n; ++i){
vector<pair<int,int>> tmp;
for(auto x : rv[i]){
for(auto y : bestDists[x]) tmp.push_back(y);
}
for(auto &x : tmp) x.first++;
tmp.push_back({0, i});
// cout << i << endl;
// for(auto x : tmp){
// cout << x.first << " " << x.second << ", ";
// }cout << endl;
vector<bool> occour(n);
sort(tmp.rbegin(), tmp.rend());
for(int j = 0; j < tmp.size() && bestDists[i].size() < block; ++j){
if(!occour[tmp[j].second]){
occour[tmp[j].second] = true;
bestDists[i].push_back(tmp[j]);
}
}
// cout << i << endl;
// for(auto x : bestDists[i]){
// cout << x.first << " " << x.second << ", ";
// }cout << endl;
}
vector<bool> on(n, true);
while(q--){
int x, y; cin >> x >> y; x--;
vector<int> currOff;
while(y--){
int z; cin >> z; z--;
on[z] = false;
currOff.push_back(z);
}
int ans = -1;
for(auto z : bestDists[x]){
if(on[z.second]){
ans = z.first; break;
}
}
if(ans == -1) ans = fullSolution(x, on);
cout << ans << "\n";
for(auto z : currOff) on[z] = true;
}
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int j = 0; j < tmp.size() && bestDists[i].size() < block; ++j){
| ~~^~~~~~~~~~~~
bitaro.cpp:62:58: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | for(int j = 0; j < tmp.size() && bestDists[i].size() < block; ++j){
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |