이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
vi al[100001];
set<ii> lis[100001];
int vis[100001],vis1[100001],ans[100001];
int r=100,co=0;
void dfs(int node)
{
vis1[node]=1;
set<ii>se;
for(int i=0;i<al[node].size();++i)
{
if(!vis1[al[node][i]])
{
dfs(al[node][i]);
}
for(auto j=(lis[al[node][i]].begin());j!=lis[al[node][i]].end();++j)
{
auto it=se.lower_bound(mp((*j).S,0));
if(it==se.end()||(*it).F!=(*j).S)
{
lis[node].insert(mp(1+(*j).F,(*j).S));
se.insert(mp((*j).S,(*j).F+1));
if(lis[node].size()>r)
{
se.erase(mp((*lis[node].begin()).S,(*(lis[node].begin())).F));
lis[node].erase(lis[node].begin());
}
}
else if((*j).F+1>(*it).S)
{
lis[node].erase(mp((*it).S,(*it).F));
lis[node].insert(mp((*j).F+1,(*it).F));
se.erase(it);
se.insert(mp((*j).S,(*j).F+1));
}
}
}
se.clear();
if(lis[node].size()<r)
lis[node].insert(mp(0,node));
}
void dfs1(int node)
{
ans[node]=0;
vis1[node]=1;
for(int i=0;i<al[node].size();++i)
{
if(vis1[al[node][i]]==0)
{
dfs1(al[node][i]);
}
ans[node]=max(ans[node],1+ans[al[node][i]]);
}
if(ans[node]==0&&vis[node]==1)
ans[node]=-1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,q;
cin>>n>>m>>q;
for(int i=0;i<m;++i)
{
int f,s;
cin>>f>>s;
al[s].pb(f);
}
for(int i=n;i>0;--i)
if(vis1[i]==0)
dfs(i);
vi v;
for(int i=0;i<q;++i)
{
int s,no;
cin>>s>>no;
int an=-1;
for(int j=0;j<no;++j)
{
int f;
cin>>f;
vis[f]=1;
v.pb(f);
}
if(no<r)
{
for(auto j=(--lis[s].end());;--j)
{
if(vis[(*j).S]==0)
{
an=(*j).F;
break;
}
if(j==lis[s].begin())
break;
}
}
else
{
memset(vis1,0,sizeof(vis1));
dfs1(s);
an=ans[s];
}
for(int j=0;j<v.size();++j)
vis[v[j]]=0;
v.clear();
cout<<an<<'\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'void dfs(int)':
bitaro.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[node].size();++i)
~^~~~~~~~~~~~~~~~
bitaro.cpp:38:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lis[node].size()>r)
~~~~~~~~~~~~~~~~^~
bitaro.cpp:54:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lis[node].size()<r)
~~~~~~~~~~~~~~~~^~
bitaro.cpp: In function 'void dfs1(int)':
bitaro.cpp:61:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[node].size();++i)
~^~~~~~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:119:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v.size();++j)
~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |