이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using I=int;
const I N=100000;
const I MIN=-1e9;
vector<I>adjs1[N],adjs2[N];
vector<pair<I,I>>tops[N];
vector<I>curs;
I diss[N];
I tims[N];
I tim=1;
I dfs(I a){
if(tims[a]==tim)return diss[a];
tims[a]=tim;
diss[a]=binary_search(curs.begin(),curs.end(),a)?MIN:0;
for(auto b:adjs2[a])if(dfs(b)!=MIN)diss[a]=max(diss[a],diss[b]+1);
return diss[a];
}
I main(){
cin.tie(0)->sync_with_stdio(0);
I n,m,q;cin>>n>>m>>q;
for(I i=0;i<m;i++){
I s,e;cin>>s>>e,s--,e--;
adjs1[s].push_back(e);
adjs2[e].push_back(s);
}
I siz=sqrt(n/log2(n))/9;
for(I i=0;i<n;i++)tops[i].push_back({0,i});
for(I i=0;i<n;i++){
sort(tops[i].begin(),tops[i].end());
while(tops[i].size()>siz)tops[i].pop_back();
for(auto j:adjs1[i])for(auto[dis,k]:tops[i])tops[j].push_back({dis-1,k});
}
while(q--){
I t,y;cin>>t>>y,t--;
curs.clear();
for(I i=0;i<y;i++){I c;cin>>c,curs.push_back(c-1);}
sort(curs.begin(),curs.end());
I res=MIN;
for(auto[dis,i]:tops[t])if(!binary_search(curs.begin(),curs.end(),i)){res=-dis;break;}
if(res!=MIN){printf("%i\n",res);continue;}
if(tops[t].size()<siz){printf("-1\n");continue;}
tim++;
printf("%i\n",dfs(t)==MIN?-1:diss[t]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'I main()':
bitaro.cpp:31:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
31 | while(tops[i].size()>siz)tops[i].pop_back();
| ~~~~~~~~~~~~~~^~~~
bitaro.cpp:42:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
42 | if(tops[t].size()<siz){printf("-1\n");continue;}
| ~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |