이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using I=int;
const I N=100000;
const I Q=100000;
const I MIN=-1e9;
vector<I>adjs1[N],adjs2[N];
set<I>bsys[Q];
vector<I>inds[N];
set<I>viss;
vector<pair<I,I>>pres[N],tops[N];
I ress[Q];
I diss[N];
I tims[N];
I tim=1;
I dfs(I a,I i){
if(tims[a]==tim)return diss[a];
tims[a]=tim,diss[a]=bsys[i].count(a)?MIN:0;
for(auto b:adjs2[a])if(dfs(b,i)!=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);
}
fill_n(ress,q,MIN);
for(I i=0;i<q;i++){
I t,y;cin>>t>>y,t--;
inds[t].push_back(i);
for(I j=0;j<y;j++){
I c;cin>>c,c--;
bsys[i].insert(c);
}
}
I siz=sqrt(n/log2(n));
for(I i=0;i<n;i++){
pres[i].push_back({0,i});
sort(pres[i].begin(),pres[i].end());
viss.clear();
for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){
auto[dis,k]=pres[i][j];
if(viss.count(k))continue;
viss.insert(k),tops[i].push_back({dis,k});
}
for(auto j:inds[i]){
for(auto[dis,k]:tops[i])if(!bsys[j].count(k)){ress[j]=-dis;break;}
if(ress[j]!=MIN)continue;
if(bsys[j].size()<siz)continue;
ress[j]=dfs(i,j),tim++;
}
for(auto j:adjs1[i])for(auto[dis,k]:tops[i])pres[j].push_back({dis-1,k});
pres[i].clear(),tops[i].clear();
}
for(I i=0;i<q;i++)printf("%i\n",ress[i]==MIN?-1:ress[i]);
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'I main()':
bitaro.cpp:44:16: warning: comparison of integer expressions of different signedness: 'I' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){
| ~^~~~~~~~~~~~~~~
bitaro.cpp:44:47: 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]
44 | for(I j=0;j<pres[i].size()&&tops[i].size()<siz;j++){
| ~~~~~~~~~~~~~~^~~~
bitaro.cpp:52:24: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
52 | if(bsys[j].size()<siz)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... |