제출 #336577

#제출 시각아이디문제언어결과실행 시간메모리
336577mehrdad_sohrabiBitaro’s Party (JOI18_bitaro)C++14
14 / 100
2060 ms243052 KiB
#include <bits/stdc++.h> typedef int ll; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second #define endl '\n' //#define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=1e5+100,sq=300; pii mx[N][sq]; vector <int> g[N]; ll vis[N]; ll dp[N]; int32_t main(){ sync; ll n,m,q; cin >> n >> m >> q; for (int i=0;i<m;i++){ ll u,v; cin >> v >> u; g[u].pb(v); } for (int i=1;i<=n;i++){ for (int j=0;j<sq;j++){ mx[i][j]={-1,-1}; } } for (int i=1;i<=n;i++){ vector <int> cnt; for (int j=0;j<g[i].size();j++){ cnt.pb(0); } if (cnt.size()==0) { for (int j=0;j<sq;j++){ mx[i][j]={0,i}; } continue; } for (int j=0;j<sq;j++){ pii p={0,i}; ll id=0; for (int k=0;k<g[i].size();k++){ ll u=g[i][k]; ll z=cnt[k]; if (z<sq && mx[u][z].F>=p.F) p=mx[u][z],id=k,p.F++; } // cout << p.F << " rfh " << p.S << endl; cnt[id]++; mx[i][j]=p; } } // cout << 1 << endl; //return 0; ll cnt=1; while(q--){ cnt++; ll w,t; cin >> w >> t; for (int i=0;i<t;i++){ ll x; cin >> x; vis[x]=cnt; } ll ans=-1; for (int i=0;i<sq;i++){ if (vis[mx[w][i].S]!=cnt){ ans=mx[w][i].F; break; } } if (ans>-1){ cout << ans << endl; continue; } if (ans==-1 && mx[w][sq-1].S==w) { cout << -1 << endl; continue; } memset(dp,0,sizeof dp); for (int i=1;i<=n;i++){ if (vis[i]==cnt) dp[i]=-1; for (auto u : g[i]){ if (dp[u]==-1) continue; dp[i]=max(dp[i],dp[u]+1); } } cout << dp[w] << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j=0;j<g[i].size();j++){
      |                      ~^~~~~~~~~~~~
bitaro.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for (int k=0;k<g[i].size();k++){
      |                          ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...