이 제출은 이전 버전의 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];
vector<ii> lis[100001];
int vis[100001],vis1[100001],ans[100001];
int r=10,co=0;
void dfs(int node)
{
vis1[node]=1;
set<int>se;
set<iii> se1;
for(int i=0;i<al[node].size();++i)
{
if(!vis1[al[node][i]])
dfs(al[node][i]);
se1.insert(mp(lis[al[node][i]][0].F,mp(al[node][i],0)));
}
while(se1.size()!=0&&lis[node].size()<r)
{
auto it=(*(--se1.end()));
if(se.find(lis[it.S.F][it.S.S].S)==se.end())
{
lis[node].pb(mp(1+it.F,lis[it.S.F][it.S.S].S));
se.insert(lis[it.S.F][it.S.S].S);
}
se1.erase(it);
if(it.S.S==lis[it.S.F].size()-1)
se1.insert(mp(lis[it.S.F][it.S.S+1].F,mp(it.S.F,it.S.S+1)));
}
if(lis[node].size()<r)
lis[node].pb(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=0;j<lis[s].size();++j)
{
if(vis[lis[s][j].S]==0)
{
an=lis[s][j].F;
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:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[node].size();++i)
~^~~~~~~~~~~~~~~~
bitaro.cpp:32:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(se1.size()!=0&&lis[node].size()<r)
~~~~~~~~~~~~~~~~^~
bitaro.cpp:41:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it.S.S==lis[it.S.F].size()-1)
~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:44: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:51: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:92:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(auto j=0;j<lis[s].size();++j)
~^~~~~~~~~~~~~~
bitaro.cpp:107: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... |