이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e5+5;
const ll K=350;
const ld pi=3.14159265359;
const ll INF=(1LL<<30);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,m,q,x,y,ans=-1,T,is[N],dp[N],id[N];
vector<ll> lis,ed[N],red[N];
vector<pll> pre[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m>>q;
REP(i,m){
cin>>x>>y;
ed[x].pb(y);
red[y].pb(x);
}
REP1(i,n){
for(ll j:red[i])id[j]=0;
REP(j,K){
pll mx=mp(i,0);
for(ll ii:red[i]){
while(id[ii]<SZ(pre[ii])&&is[pre[ii][id[ii]].X])++id[ii];
if(id[ii]>=SZ(pre[ii]))continue;
if(mx.Y<pre[ii][id[ii]].Y+1)mx=mp(pre[ii][id[ii]].X,pre[ii][id[ii]].Y+1);
}
//if(mx.X==i)break;
pre[i].pb(mx);
is[mx.X]=1;
lis.pb(mx.X);
}
for(ll j:lis)is[j]=0;
lis.clear();
}
while(q--){
cin>>x>>T;
REP(i,T)cin>>y,lis.pb(y),is[y]=1;
if(T>=K){
REP1(i,n)dp[i]=-INF;
dp[x]=0;
if(!is[x])ans=0;
for(int i=x-1;i>=1;i--){
for(auto j:ed[i]){
dp[i]=max(dp[i],dp[j]+1);
if(!is[i])ans=max(ans,dp[i]);
}
}
cout<<ans<<"\n";
}else{
for(auto i:pre[x])if(!is[i.X])ans=max(ans,i.Y);
cout<<ans<<"\n";
}
for(ll i:lis)is[i]=0;
ans=-1;
lis.clear();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |