Submission #255447

#TimeUsernameProblemLanguageResultExecution timeMemory
255447uacoder123Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
31 ms15104 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]; set<ii> lis[100001]; int vis[100001],vis1[100001],ans[100001]; int r=700; 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(auto j=(lis[al[node][i]].begin());j!=lis[al[node][i]].end();++j) { lis[node].insert(mp(1+(*j).F,(*j).S)); if(lis[node].size()>r) lis[node].erase(lis[node].begin()); } } 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].begin();j!=lis[s].end();++j) { if(vis[(*j).S]==0) { an=(*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; }

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:33:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(lis[node].size()>r)
            ~~~~~~~~~~~~~~~~^~
bitaro.cpp:37: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:44: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:100: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...