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 int
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,m,q,sq=300,d[100002],fix[100002],ans[100002];
vector<ll>rev[100002],k[100002],ge[100002];
vector<pair<ll,ll> >best[100002],f;
int main(){
ios::sync_with_stdio(false);
cin >> n >> m >> q;
for(int i=1; i<=m; i++){
ll x,y;
cin >> x >> y;
rev[y].pb(x);
}
for(int ind=1; ind<=q; ind++){
ll x,sz;
cin >> x >> sz;
for(int j=0; j<sz; j++){
ll y;
cin >> y;
k[ind].pb(y);
}
if(sz >= sq){
for(int i=1; i<=n; i++)
d[i] = fix[i] = 0;
for(int i=x; i>=1; i--)
for(int j=0; j<rev[i].size(); j++)
d[rev[i][j]] = max(d[rev[i][j]] , d[i] + 1);
for(int i=0; i<k[ind].size(); i++)
fix[k[ind][i]] = 1;
for(int i=1; i<=x; i++)
if(!fix[i])ans[ind] = max(ans[ind] , d[i]);
}
else ge[x].pb(ind);
}
for(int x=1; x<=n; x++){
f.clear();
f.pb(mp(0 , x));
fix[x] = 0;
for(int i=0; i<rev[x].size(); i++){
ll to = rev[x][i];
for(int j=0; j<best[to].size(); j++){
f.pb(mp(best[to][j].f + 1 , best[to][j].s));
fix[best[to][j].s] = 0;
}
}
sort(f.begin() , f.end());
reverse(f.begin() , f.end());
for(int i=0; i<f.size(); i++){
if(fix[f[i].s])continue;
fix[f[i].s] = 1;
best[x].pb(f[i]);
}
while(best[x].size() > sq)best[x].pop_back();
reverse(best[x].begin() , best[x].end());
for(int id=0; id<ge[x].size(); id++){
ll ind = ge[x][id];
for(int i=0; i<best[x].size(); i++)
fix[best[x][i].s] = 0;
for(int i=0; i<k[ind].size(); i++)
fix[k[ind][i]] = 1;
for(int i=0; i<best[x].size(); i++)
if(!fix[best[x][i].s])
ans[ind] = best[x][i].f;
}
}
for(int i=1; i<=q; i++)
cout << ans[i] << '\n';
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:33:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<rev[i].size(); j++)
~^~~~~~~~~~~~~~
bitaro.cpp:35:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<k[ind].size(); i++)
~^~~~~~~~~~~~~~
bitaro.cpp:47:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<rev[x].size(); i++){
~^~~~~~~~~~~~~~
bitaro.cpp:49:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<best[to].size(); j++){
~^~~~~~~~~~~~~~~~
bitaro.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<f.size(); i++){
~^~~~~~~~~
bitaro.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(best[x].size() > sq)best[x].pop_back();
~~~~~~~~~~~~~~~^~~~
bitaro.cpp:63:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int id=0; id<ge[x].size(); id++){
~~^~~~~~~~~~~~~
bitaro.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<best[x].size(); i++)
~^~~~~~~~~~~~~~~
bitaro.cpp:67:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<k[ind].size(); i++)
~^~~~~~~~~~~~~~
bitaro.cpp:69:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<best[x].size(); i++)
~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |