Submission #1104566

# Submission time Handle Problem Language Result Execution time Memory
1104566 2024-10-24T03:52:57 Z vjudge1 Tropical Garden (IOI11_garden) C++17
49 / 100
6 ms 4944 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

const int MxN = 1005, MxM = 1e4 + 5;
int n, m, p, q, g, r[MxM][2], ans;
vector<pii> v[MxN];

void dfs (int cur, int dist, int w) {
  if (dist == g && cur == p) return void(ans++);
  if (dist >= g) return;
  bool ok = 0;
  if (v[cur].size() >= 1 && v[cur][0].first != w) {
    auto [x, y] = v[cur][0];
    dfs(y, dist + 1, x); ok = 1;
  }
  if (!ok && v[cur].size() >= 2 && v[cur][1].first != w) {
    auto [x, y] = v[cur][1];
    dfs(y, dist + 1, x); ok = 1;
  }
  if (!ok) {
    auto [x, y] = v[cur][0];
    dfs(y, dist + 1, x);
  }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
  n = N; m = M; p = P; q = Q; g = G[0];
  for (int i = 0; i < m; i++) {
    r[i][0] = R[i][0]; r[i][1] = R[i][1];
    v[r[i][0]].emplace_back(i, r[i][1]);
    v[r[i][1]].emplace_back(i, r[i][0]);
  }
  for (int i = 0; i < n; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < n; i++) dfs(i, 0, -1);
  answer(ans);
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Runtime error 6 ms 4944 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Runtime error 6 ms 4944 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -