Submission #285093

#TimeUsernameProblemLanguageResultExecution timeMemory
285093PlurmBitaro’s Party (JOI18_bitaro)C++11
14 / 100
2095 ms221748 KiB
#include <bits/stdc++.h> using namespace std; const int THRESH = 250; vector<int> ord; vector<int> g[100005]; vector<int> rg[100005]; bool found[100005]; void dfs(int u){ if(found[u]) return; found[u] = true; for(int v : g[u]){ dfs(v); } ord.push_back(u); } vector<pair<int,int> > dp[100005]; // | dp[i] | <= THRESH. bool __used[100005]; vector<pair<int,int> > newVec; void __append(pair<int,int> x){ if(newVec.empty() || !__used[x.second]){ newVec.push_back(x); __used[x.second] = true; } } void merge(vector<pair<int,int> >& dest, vector<pair<int,int> > src){ for(auto& v : src) v.first++; int ptr1 = 0; int ptr2 = 0; while(ptr1 < dest.size() && ptr2 < src.size() && newVec.size() < THRESH){ if(dest[ptr1] > src[ptr2]){ __append(dest[ptr1]); ptr1++; }else{ __append(src[ptr2]); ptr2++; } } while(newVec.size() < THRESH && ptr1 < dest.size()){ __append(dest[ptr1]); ptr1++; } while(newVec.size() < THRESH && ptr2 < src.size()){ __append(src[ptr2]); ptr2++; } for(auto u : newVec) __used[u.second] = false; swap(dest, newVec); newVec.clear(); } bool isBusy[100005]; int subdp[100005]; int recalculateAnswer(int t){ for(int u : ord){ subdp[u] = isBusy[u] ? -10000000 : 0; for(int v : rg[u]){ subdp[u] = max(subdp[u], subdp[v]+1); } } return subdp[t] < 0 ? -1 : subdp[t]; } int main(){ int n, m, q; scanf("%d%d%d",&n,&m,&q); for(int i = 0; i < m; i++){ int s,e; scanf("%d%d",&s,&e); g[s].push_back(e); rg[e].push_back(s); } for(int i = 1; i <= n; i++) dfs(i); reverse(ord.begin(), ord.end()); for(int u : ord){ for(int v : rg[u]){ merge(dp[u], dp[v]); } merge(dp[u], {make_pair(-1, u)}); /* printf("DBG [%d]\n", u); for(auto v : dp[u]){ printf("%d %d\n", v.first, v.second); } */ } int t, y; for(int qq = 0; qq < q; qq++){ scanf("%d%d",&t,&y); vector<int> busy; busy.reserve(y); for(int i = 0; i < y; i++){ int c; scanf("%d",&c); busy.push_back(c); isBusy[c] = true; } int ans = -1; if(y < THRESH-1){ for(auto p : dp[t]){ if(isBusy[p.second]) continue; ans = p.first; break; } }else{ ans = recalculateAnswer(t); } for(int c : busy) isBusy[c] = false; printf("%d\n",ans); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void merge(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >)':
bitaro.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  while(ptr1 < dest.size() && ptr2 < src.size() && newVec.size() < THRESH){
      |        ~~~~~^~~~~~~~~~~~~
bitaro.cpp:29:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  while(ptr1 < dest.size() && ptr2 < src.size() && newVec.size() < THRESH){
      |                              ~~~~~^~~~~~~~~~~~
bitaro.cpp:38:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  while(newVec.size() < THRESH && ptr1 < dest.size()){
      |                                  ~~~~~^~~~~~~~~~~~~
bitaro.cpp:42:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  while(newVec.size() < THRESH && ptr2 < src.size()){
      |                                  ~~~~~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |  scanf("%d%d%d",&n,&m,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |   scanf("%d%d",&s,&e);
      |   ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |   scanf("%d%d",&t,&y);
      |   ~~~~~^~~~~~~~~~~~~~
bitaro.cpp:91:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   91 |    scanf("%d",&c);
      |    ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...