Submission #484115

#TimeUsernameProblemLanguageResultExecution timeMemory
484115mars4Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
853 ms214604 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; const ll B=100; cin>>n>>m>>k; vector<vector<ll>> v(n); forn(i,0,m) { cin>>l>>r; l--,r--; v[r].push_back(l); } vector<ll> vis(n,-1); vector<vector<pair<ll,ll>>> dist(n); vector<ll> len(n); forn(i,0,n) { vector<ll> nodes; nodes.push_back(i); for(ll pr:v[i]) { for(auto [cnt,frm]:dist[pr]) { if(vis[frm]!=i) { vis[frm]=i; len[frm]=cnt+1; nodes.push_back(frm); } else { len[frm]=max(len[frm],cnt+1); } } } sort(all(nodes),[&](ll u,ll v){ return len[u]>len[v]; }); ll n2=(ll)nodes.size(); forn(j,0,min(n2,B)) { dist[i].push_back({len[nodes[j]],nodes[j]}); } } vector<ll> mark(n,-1); while(k--) { ll node,n2; cin>>node>>n2; node--; vector<ll> na(n2); for(ll &i:na) { cin>>i; i--; mark[i]=k; } ll ans=-1; if(n2>=B) { vector<ll> len2(n); forn(i,0,node+1) { if(mark[i]==k) { len2[i]=-inf; } for(ll j:v[i]) { len2[i]=max(len2[i],len2[j]+1); } } ans=max(ans,len2[node]); } else { for(auto [cnt,frm]:dist[node]) { if(mark[frm]!=k) { ans=cnt; break; } } } cout<<ans<<"\n"; } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:47:5: warning: unused variable 'z' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
bitaro.cpp:47:11: warning: unused variable 't' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
bitaro.cpp:47:15: warning: unused variable 'i' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
bitaro.cpp:47:17: warning: unused variable 'j' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                 ^
bitaro.cpp:47:21: warning: unused variable 'd' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                     ^
bitaro.cpp:47:23: warning: unused variable 'h' [-Wunused-variable]
   47 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...