Submission #1030209

#TimeUsernameProblemLanguageResultExecution timeMemory
1030209SamuellH12Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
2041 ms37692 KiB
#include <bits/stdc++.h> #define optimize ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define ALL(x) x.begin(), x.end() #define endl "\n" #define vi vector<int> #define pii pair<int,int> const int MAXN = 1e5 + 1; const int SQRT = 10; using namespace std; int block[MAXN], dp[MAXN], tempo; vi trafo[MAXN], order; vector<pii> best[MAXN]; int main(){ ios::sync_with_stdio(false); int n, m, q; scanf("%d %d %d", &n, &m, &q); for(int i=0, u, v; i<m; i++) { scanf("%d %d", &u, &v); trafo[v].emplace_back(u); dp[u]++; } deque<int> fila; for(int i=1; i<=n; i++) if(dp[i] == 0) fila.emplace_back(i); while(!fila.empty()) { auto u = fila.front(); fila.pop_front(); order.emplace_back(u); for(auto v : trafo[u]) if(--dp[v] == 0) fila.emplace_back(v); } reverse(ALL(order)); for(auto u : order) { best[u].emplace_back(0, u); for(auto v : trafo[u]) for(auto [x, w] : best[v]) best[u].emplace_back(x-1, w); sort(ALL(best[u])); best[u].resize(min(SQRT, (int)(unique(ALL(best[u])) - best[u].begin()))); } int t, y; while(q--) { tempo++; // cin >> t >> y; scanf("%d %d", &t, &y); for(int i=0, x; i<y; i++) { // cin >> x; scanf("%d", &x); block[x] = tempo; } int ans = -1; for(auto [x, w] : best[t]) if(block[w] != tempo) { ans = -x; break; } if(ans == -1) for(auto u : order) { dp[u] = (block[u] == tempo ? -1 : 0); for(auto v : trafo[u]) if(~dp[v]) dp[u] = max(dp[u], dp[v]+1); if(u == t){ ans = dp[u]; break; } } printf("%d\n", ans); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d %d", &t, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:65:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...