이 제출은 이전 버전의 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>adjs[N];
set<I>bsys[Q];
vector<I>inds[N];
set<pair<I,I>>tops[N];
I ress[Q];
I dp[N];
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--;
adjs[s].push_back(e);
}
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++)tops[i].insert({0,i});
for(I i=0;i<n;i++){
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;
fill_n(dp,i+1,0);
for(auto c:bsys[j])dp[c]=MIN;
for(I k=0;k<i;k++)if(dp[k]!=MIN)for(auto l:adjs[k])if(l<=i)dp[l]=max(dp[l],dp[k]+1);
ress[j]=dp[i];
}
for(auto j:adjs[i])for(auto[dis,k]:tops[i]){
tops[j].insert({dis-1,k});
while(tops[j].size()>siz)tops[j].erase(prev(tops[j].end()));
}
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:35:24: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
35 | if(bsys[j].size()<=siz)continue;
| ~~~~~~~~~~~~~~^~~~~
bitaro.cpp:43:27: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'I' {aka 'int'} [-Wsign-compare]
43 | while(tops[j].size()>siz)tops[j].erase(prev(tops[j].end()));
| ~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |