답안 #964601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964601 2024-04-17T07:38:11 Z abczz Bitaro’s Party (JOI18_bitaro) C++14
7 / 100
1053 ms 524288 KB
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define ll long long

using namespace std;

vector <ll> adj[100000];
priority_queue <array<ll, 3>> pq;
queue <ll> Q;
array <ll, 2> dp[100000][330];
ll n, m, q, a, k, b, f, rt = 200, dist[100000], B[100000], in[100000], visited[100000], ver[100000];

void dfs(ll u) {
  visited[u] = q;
  in[u] = 0;
  for (auto v : adj[u]) {
    if (visited[v] != q) dfs(v);
    ++in[v];
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> m >> q;
  for (int i=0; i<m; ++i) {
    cin >> a >> b;
    --a, --b;
    adj[b].push_back(a);
  }
  for (int i=0; i<n; ++i) {
    B[i] = visited[i] = ver[i] = -1;
    while (!pq.empty()) pq.pop();
    pq.push({-1, i, -1});
    for (int j=0; j<rt; ++j) {
      dp[i][j] = {(ll)-1e18, -1};
    }
    for (auto u : adj[i]) {
      pq.push({dp[u][0][0], u, 0});
    }
    for (int j=0; j<rt; ++j) {
      while (!pq.empty()) {
        auto [w, u, x] = pq.top();
        pq.pop();
        if (x != -1 && x != rt-1 && dp[u][x+1][1] != -1) {
          pq.push({dp[u][x+1][0], u, x+1});
        }
        if (x == -1) {
          dp[i][j] = {w+1, u};
          break;
        }
        else if (ver[dp[u][x][1]] != i) {
          dp[i][j] = {w+1, dp[u][x][1]};
          ver[dp[u][x][1]] = i;
          break;
        }
      }
    }
  }
  while (q--) {
    cin >> a >> k;
    --a;
    for (int i=0; i<k; ++i) {
      cin >> b;
      --b;
      B[b] = q;
    }
    if (k < rt) {
      for (int i=0; i<rt; ++i) {
        if (dp[a][i][1] == -1) {
          cout << "-1\n";
          break;
        }
        if (B[dp[a][i][1]] != q) {
          cout << dp[a][i][0] << '\n';
          break;
        }
      }
    }
    else {
      dfs(a);
      Q.push(a);
      dist[a] = 0;
      f = -1;
      while (!Q.empty()) {
        auto u = Q.front();
        Q.pop();
        if (B[u] != q) f = max(f, dist[u]);
        for (auto v : adj[u]) {
          --in[v];
          dist[v] = max(dist[v], dist[u]+1);
          if (!in[v]) Q.push(v);
        }
      }
      cout << f << '\n';
    }
  }
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |         auto [w, u, x] = pq.top();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8120 KB Output is correct
2 Correct 1 ms 3928 KB Output is correct
3 Correct 2 ms 6232 KB Output is correct
4 Correct 2 ms 6232 KB Output is correct
5 Correct 6 ms 9304 KB Output is correct
6 Correct 6 ms 12888 KB Output is correct
7 Correct 6 ms 12892 KB Output is correct
8 Correct 11 ms 12904 KB Output is correct
9 Correct 10 ms 10972 KB Output is correct
10 Correct 12 ms 8028 KB Output is correct
11 Correct 12 ms 9304 KB Output is correct
12 Correct 8 ms 9308 KB Output is correct
13 Correct 12 ms 7944 KB Output is correct
14 Correct 9 ms 7864 KB Output is correct
15 Correct 8 ms 8024 KB Output is correct
16 Correct 9 ms 8024 KB Output is correct
17 Correct 10 ms 8028 KB Output is correct
18 Correct 9 ms 8024 KB Output is correct
19 Correct 9 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8120 KB Output is correct
2 Correct 1 ms 3928 KB Output is correct
3 Correct 2 ms 6232 KB Output is correct
4 Correct 2 ms 6232 KB Output is correct
5 Correct 6 ms 9304 KB Output is correct
6 Correct 6 ms 12888 KB Output is correct
7 Correct 6 ms 12892 KB Output is correct
8 Correct 11 ms 12904 KB Output is correct
9 Correct 10 ms 10972 KB Output is correct
10 Correct 12 ms 8028 KB Output is correct
11 Correct 12 ms 9304 KB Output is correct
12 Correct 8 ms 9308 KB Output is correct
13 Correct 12 ms 7944 KB Output is correct
14 Correct 9 ms 7864 KB Output is correct
15 Correct 8 ms 8024 KB Output is correct
16 Correct 9 ms 8024 KB Output is correct
17 Correct 10 ms 8028 KB Output is correct
18 Correct 9 ms 8024 KB Output is correct
19 Correct 9 ms 8028 KB Output is correct
20 Correct 1022 ms 11912 KB Output is correct
21 Correct 678 ms 13228 KB Output is correct
22 Correct 1053 ms 18312 KB Output is correct
23 Correct 481 ms 18268 KB Output is correct
24 Runtime error 888 ms 524288 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8120 KB Output is correct
2 Correct 1 ms 3928 KB Output is correct
3 Correct 2 ms 6232 KB Output is correct
4 Correct 2 ms 6232 KB Output is correct
5 Correct 6 ms 9304 KB Output is correct
6 Correct 6 ms 12888 KB Output is correct
7 Correct 6 ms 12892 KB Output is correct
8 Correct 11 ms 12904 KB Output is correct
9 Correct 10 ms 10972 KB Output is correct
10 Correct 12 ms 8028 KB Output is correct
11 Correct 12 ms 9304 KB Output is correct
12 Correct 8 ms 9308 KB Output is correct
13 Correct 12 ms 7944 KB Output is correct
14 Correct 9 ms 7864 KB Output is correct
15 Correct 8 ms 8024 KB Output is correct
16 Correct 9 ms 8024 KB Output is correct
17 Correct 10 ms 8028 KB Output is correct
18 Correct 9 ms 8024 KB Output is correct
19 Correct 9 ms 8028 KB Output is correct
20 Correct 1022 ms 11912 KB Output is correct
21 Correct 678 ms 13228 KB Output is correct
22 Correct 1053 ms 18312 KB Output is correct
23 Correct 481 ms 18268 KB Output is correct
24 Runtime error 888 ms 524288 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -