Submission #255380

#TimeUsernameProblemLanguageResultExecution timeMemory
255380uacoder123Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
4 ms4992 KiB
#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; void dfs(int node) { vis1[node]=1; for(int i=0;i<al[node].size();++i) if(!vis1[al[node][i]]) { dfs(al[node][i]); for(int j=0;j<lis[al[node][i]].size();++j) lis[node].pb(mp(1+lis[al[node][i]][j].F,lis[al[node][i]][j].S)); } lis[node].pb(mp(0,node)); sort(all(lis[node]),greater<ii>()); while(lis[node].size()>r) lis[node].pop_back(); } void dfs1(int node) { ans[node]=0; for(int i=0;i<al[node].size();++i) { 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; r=sqrt(n); for(int i=0;i<m;++i) { int f,s; cin>>f>>s; al[s].pb(f); } for(int i=n-1;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(int j=0;j<lis[s].size();++j) if(vis[lis[s][j].S]==0) { an=lis[s][j].F; break; } } else { dfs1(s); an=ans[s]; } for(int j=0;j<v.size();++j) vis[v[j]]=0; v.clear(); cout<<an<<endl; } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void dfs(int)':
bitaro.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<al[node].size();++i)
               ~^~~~~~~~~~~~~~~~
bitaro.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=0;j<lis[al[node][i]].size();++j)
                   ~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(lis[node].size()>r)
         ~~~~~~~~~~~~~~~~^~
bitaro.cpp: In function 'void dfs1(int)':
bitaro.cpp:39: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:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=0;j<lis[s].size();++j)
                   ~^~~~~~~~~~~~~~
bitaro.cpp:90:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<v.size();++j)
                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...