제출 #383415

#제출 시각아이디문제언어결과실행 시간메모리
383415luciocfBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1843 ms426728 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef pair<int, int> pii; const int maxn = 2e5+10; const int inf = 1e9+10; int n, m, q; int dp[maxn]; int visto[maxn]; bool mark[maxn], block[maxn]; int ptr[maxn]; vector<pii> dist[maxn]; vector<int> grafo[2][maxn], ord; void dfs(int u) { mark[u] = 1; for (auto v: grafo[0][u]) if (!mark[v]) dfs(v); ord.push_back(u); } void solve(int t) { for (int i = 1; i <= n; i++) dp[i] = -inf; dp[t] = 0; for (int i = ord.size()-1; i >= 0; i--) { int u = ord[i]; for (auto v: grafo[1][u]) dp[u] = max(dp[u], 1 + dp[v]); } } int main(void) { scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); grafo[0][v].push_back(u); grafo[1][u].push_back(v); } for (int i = 1; i <= n; i++) if (!mark[i]) dfs(i); for (auto u: ord) { for (auto v: grafo[0][u]) ptr[v] = 0; for (int t = 1; t <= 321; t++) { pii pp = {-1, -1}; for (auto v: grafo[0][u]) { while (dist[u].size() && ptr[v] < dist[v].size() && visto[dist[v][ptr[v]].ss]) ptr[v]++; if (ptr[v] < dist[v].size()) pp = max(pp, {dist[v][ptr[v]].ff+1, dist[v][ptr[v]].ss}); } if (pp.ff == -1) { dist[u].push_back({0, u}); break; } else { dist[u].push_back(pp); visto[pp.ss] = 1; for (auto v: grafo[0][u]) { if (ptr[v] < dist[v].size() && pp == make_pair(dist[v][ptr[v]].ff+1, dist[v][ptr[v]].ss)) { ptr[v]++; break; } } } } for (auto pp: dist[u]) visto[pp.ss] = 0; } while (q--) { int t, y; scanf("%d %d", &t, &y); vector<int> lista; for (int i = 1; i <= y; i++) { int u; scanf("%d", &u); lista.push_back(u); block[u] = 1; } int ans = -inf; if (y > 320) { solve(t); for (int i = 1; i <= n; i++) if (!block[i]) ans = max(ans, dp[i]); } else { for (auto pp: dist[t]) { if (!block[pp.ss]) { ans = pp.ff; break; } } } if (ans < 0) printf("-1\n"); else printf("%d\n", ans); for (auto u: lista) block[u] = 0; } }

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'int main()':
bitaro.cpp:82:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     while (dist[u].size() && ptr[v] < dist[v].size() && visto[dist[v][ptr[v]].ss])
      |                              ~~~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:85:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     if (ptr[v] < dist[v].size())
      |         ~~~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:101:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |      if (ptr[v] < dist[v].size() && pp == make_pair(dist[v][ptr[v]].ff+1, dist[v][ptr[v]].ss))
      |          ~~~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:117:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  117 |   scanf("%d %d", &t, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:124:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  124 |    scanf("%d", &u);
      |    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...