Submission #534733

#TimeUsernameProblemLanguageResultExecution timeMemory
534733LoboBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1644 ms70964 KiB
#include<bits/stdc++.h> using namespace std; // const long long inf = (long long) 1e18 + 10; const int inf = (int) 1e9 + 10; // #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 110000 #define B 55 int n, m, q, dp1[maxn], mark[maxn], lst[maxn]; vector<pair<int,int>> dp[maxn]; vector<int> g[maxn], g1[maxn]; void solve() { cin >> n >> m >> q; for(int i = 1; i <= m; i++) { int u,v; cin >> u >> v; g[u].pb(v); g1[v].pb(u); } //pegar os B melhores de cada um for(int i = 1; i <= n; i++) { priority_queue<pair<int,pair<int,int>>> pq; for(auto v : g1[i]) { pq.push(mp(dp[v][0].fr,mp(v,0))); } while(pq.size() && dp[i].size() <= B) { int v = pq.top().sc.fr; int id = pq.top().sc.sc; pq.pop(); if(lst[dp[v][id].sc] != i) dp[i].pb(mp(dp[v][id].fr+1,dp[v][id].sc)); lst[dp[v][id].sc] = i; id++; if(id != dp[v].size()) { pq.push(mp(dp[v][id].fr,mp(v,id))); } } if(dp[i].size() < B) { dp[i].pb(mp(0,i)); } } while(q--) { int u; cin >> u; int qtd; cin >> qtd; vector<int> bl; while(qtd--) { int v; cin >> v; bl.pb(v); mark[v] = 1; } if(bl.size() < B) { int ans = -1; int id = 0; while(id != dp[u].size()) { if(mark[dp[u][id].sc]) { id++; continue; } ans = dp[u][id].fr; break; } cout << ans << endl; } else { for(int i = 1; i <= u; i++) { dp1[i] = 0; if(mark[i]) dp1[i] = -1; for(auto v : g1[i]) { if(dp1[v] != -1) dp1[i] = max(dp1[i],dp1[v]+1); } } cout << dp1[u] << endl; } // cout << u << endl; for(auto v : bl) mark[v] = 0; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) solve(); }

Compilation message (stderr)

bitaro.cpp: In function 'void solve()':
bitaro.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             if(id != dp[v].size()) {
      |                ~~~^~~~~~~~~~~~~~~
bitaro.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             while(id != dp[u].size()) {
      |                   ~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...