Submission #95057

#TimeUsernameProblemLanguageResultExecution timeMemory
95057Mahdi_JfriBitaro’s Party (JOI18_bitaro)C++14
7 / 100
202 ms24544 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back typedef vector<pair<int,int>> vii; const int maxn = 1e5 + 20; const int sq = maxn; vector<int> in[maxn]; vii path[maxn]; int dp[maxn] , mx[maxn] , all[maxn]; bool is[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n , m , q; cin >> n >> m >> q; for(int i = 0; i < m; i++) { int a , b; cin >> a >> b; a-- , b--; in[b].pb(a); } memset(mx , -1 , sizeof mx); for(int v = 0; v < n; v++) { int t = 0; all[t++] = v , mx[v] = 0; for(auto u : in[v]) for(auto w : path[u]) { mx[w.second] = max(mx[w.second] , w.first + 1); all[t++] = w.second; } for(int i = 0; i < t; i++) if(mx[all[i]] != -1) path[v].pb({mx[all[i]] , all[i]}) , mx[all[i]] = -1; sort(path[v].begin() , path[v].end()); reverse(path[v].begin() , path[v].end()); while(path[v].size() > sq) path[v].pop_back(); } while(q--) { int v , sz; cin >> v >> sz; v--; vector<int> tmp(sz); for(auto &x : tmp) cin >> x , x--; for(auto x : tmp) is[x] = 1; int ans; // if(sz > sq) // { for(int i = 0; i <= v; i++) { dp[i] = -1e9; if(!is[i]) dp[i] = 0; for(auto u : in[i]) dp[i] = max(dp[i] , dp[u] + 1); } dp[v] = max(dp[v] , -1); ans = dp[v]; // cout << dp[v] << endl; // } // else // { int res; bool f = 0; for(auto x : path[v]) if(!is[x.second]) { res = x.first; // cout << x.first << endl; f = 1; break; } if(!f) res = -1; //cout << -1 << endl; // } if(res != ans) cout << 1/0; cout << res << endl; for(auto x : tmp) is[x] = 0; } }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:104:13: warning: division by zero [-Wdiv-by-zero]
    cout << 1/0;
            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...