이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
#define F first
#define S second
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
typedef long long ll;
const ll mxN=1e5+5;
ll n, m, q;
vll adj[mxN];
vll qry[mxN];
ll siz[mxN];
vll y[mxN];
ll dp[mxN];
ll e[mxN];
ll f(ll idx, ll t){
memset(dp, -1, sizeof(dp));
ll re=-1;
dp[t]=0;
while(siz[idx]>0 && y[idx].back()>t){
siz[idx]--;
y[idx].pop_back();
}
for(ll i=t;i>=0;i--){
//cout<<i<<' '<<dp[i]<<'\n';
if(siz[idx]>0 && y[idx].back()==i){
siz[idx]--;
y[idx].pop_back();
}
else{
re=max(re, dp[i]);
}
if(dp[i]!=-1){
for(auto &it:adj[i]){
dp[it]=max(dp[it], dp[i]+1);
}
}
}
return re;
}
void solve(){
cin>>n>>m>>q;
for(ll i=0;i<m;i++){
ll u, v;
cin>>u>>v;
u--; v--;
adj[v].pb(u);
}
for(ll i=0;i<q;i++){
cin>>e[i];
e[i]--;
qry[e[i]].pb(i);
cin>>siz[i];
for(ll j=0;j<siz[i];j++){
ll tep;
cin>>tep;
tep--;
y[i].pb(tep);
}
}
//assert(q==1);
for(ll i=0;i<q;i++){
cout<<f(i, e[i])<<'\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
solve();
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... |