이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n,m,q,aa,bb;
int vis[100001];
vector<int> adj[100001];
int x;
const int ss=200;
int dp[100001];
int calc(int ind){
for(int i=0;i<ind+1;i++){
dp[i]=0;
if(vis[i]){
dp[i]=-1;
}
for(auto j:adj[i]){
if(dp[j]!=-1){
dp[i]=max(dp[i],dp[j]+1);
}
}
}
return dp[ind];
}
pair<int,int> dist[100001][ss];
int ind[100001];
vector<int> freq[100001];
int pre(){
for(int i=0;i<n;i++){
//priority_queue<pair<int,int>> sso;
int ma=0;
for(auto j:adj[i]){
for(int k=0;k<ind[j];k++){
//sso.push(dist[j][k]);
freq[dist[j][k].a+1].pb(dist[j][k].b);
// cout<<dist[j][k].a+1<<" "<<dist[j][k].b<<endl;
ma=max(ma,dist[j][k].a+1);
}
}
//cout<<ma<<":"<<endl;
int co=0;
freq[0].pb(i);
while(co<ss){
if(freq[ma].size()==0){
ma-=1;
}
// cout<<ma<<endl;
if(ma<0){
break;
}
int tt=freq[ma].back();
if(vis[tt]){
freq[ma].pop_back();
continue;
}
vis[tt]=1;
dist[i][co]={ma,tt};
freq[ma].pop_back();
// cout<<i<<","<<ma<<","<<tt<<endl;
co+=1;
}
for(int j=0;j<co;j++){
vis[dist[i][j].b]=0;
}
/*if(co<ss){
dist[i][co]={0,i};
co+=1;
}*/
ind[i]=co;
for(auto j:adj[i]){
for(int k=0;k<ind[j];k++){
if(freq[dist[j][k].a+1].size()){
freq[dist[j][k].a+1].pop_back();
}
}
}
// cout<<i<<" "<<co<<endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>q;
for(int i=0;i<n;i++){
vis[i]=0;
}
for(int i=0;i<m;i++){
cin>>aa>>bb;
adj[bb-1].pb(aa-1);
}
pre();
int indd,nn;
for(int ii=0;ii<q;ii++){
cin>>indd>>nn;
indd-=1;
vector<int> cur;
int co=0;
for(int j=0;j<nn;j++){
cin>>x;
x-=1;
// if(adj[x].size()==0){
vis[x]=1;
cur.pb(x);
co+=1;
// }
}
if(co>=ss){
cout<<calc(indd)<<endl;
}
else{
int st=0;
for(int i=0;i<ind[indd];i++){
if(vis[dist[indd][i].b]){
continue;
}
st=1;
cout<<dist[indd][i].a<<endl;
break;
}
if(st==0){
cout<<-1<<endl;
}
}
for(auto j:cur){
vis[j]=0;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'int pre()':
bitaro.cpp:84:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |