Submission #107368

#TimeUsernameProblemLanguageResultExecution timeMemory
107368alishahali1382Bitaro’s Party (JOI18_bitaro)C++14
7 / 100
2037 ms9852 KiB
#include <bits/stdc++.h> #if defined(__GNUC__) #pragma GCC optimize ("Ofast") #endif using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<pii, int> piii; typedef pair<ll, ll> pll; #define debug(x) cerr<<#x<<'='<<x<<endl; #define debugp(x) cerr<<#x<<"= {"<<x.first<<", "<<x.second<<"}"<<endl; #define all(x) x.begin(), x.end() #define pb push_back #define kill(x) return cout<<x<<'\n', 0; #define SZ(x) ((int) x.size()) const ld eps=1e-7; const int inf=1000000010; const ll INF=10000000000000010LL; const int mod = 1000000007; const int MAXN = 100010, SQ=320; int n, m, q, u, v, x, y, t, a, b, ans; vector<pii> good[MAXN]; int dp[MAXN]; vector<int> G[MAXN]; unordered_map<int, int> mp; bool mark[MAXN]; int dist[MAXN]; bool cmp(int i, int j){ return dist[i]>dist[j];} void merg(vector<pii> &a, vector<pii> &b){ vector<int> tmp; for (pii p:a){ tmp.pb(p.second); dist[p.second]=p.first; } for (pii p:b){ if (dist[p.second]==-1) tmp.pb(p.second); dist[p.second]=max(p.first+1, dist[p.second]); } sort(all(tmp), cmp); int sz=min(SZ(tmp), SQ); a.clear(); for (int i=0; i<sz; i++) a.pb({dist[tmp[i]], tmp[i]}); for (int i:tmp) dist[i]=-1; } void bigquery(){ while (y--){ cin>>x; dp[x]=-inf; } for (int i=1; i<=v; i++) for (int j:G[i]) dp[i]=max(dp[i], dp[j]+1); if (dp[v]<0) dp[v]=-1; cout<<dp[v]<<'\n'; memset(dp, 0, sizeof(dp)); } int smallquery(){ set<int> st; while (y--){ cin>>x; st.insert(x); } for (pii p:good[v]){ if (st.count(p.second)) continue ; if (p.first<0) kill(-1); kill(p.first); } cout<<"-1\n"; } int badquery(){ while (y--) cin>>x; cout<<"-1\n"; } void query(){ cin>>v>>y; if (y>=SQ-10) bigquery(); else if (y > (int)good[v].size()+5) badquery(); else smallquery(); } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); memset(dist, -1, sizeof(dist)); cin>>n>>m>>q; while (m--){ cin>>u>>v; G[v].pb(u); } for (int i=1; i<=n; i++){ good[i].pb({0, i}); //good[i].pb({-inf, 0}); for (int j:G[i]) merg(good[i], good[j]); /* cerr<<i<<" :\n"; for (pii p:good[i]) cerr<<p.second<<' '<<p.first<<endl; cerr<<endl;*/ } while (q--) query(); return 0; } /* 5 6 3 1 2 2 4 3 4 1 3 3 5 4 5 4 1 1 5 2 2 3 2 3 1 4 5 */

Compilation message (stderr)

bitaro.cpp: In function 'int badquery()':
bitaro.cpp:79:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
bitaro.cpp: In function 'int smallquery()':
bitaro.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...