# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169058 | 2019-12-18T07:00:32 Z | AlexLuchianov | Tropical Garden (IOI11_garden) | C++14 | 15 ms | 14584 KB |
#include "garden.h" #include "gardenlib.h" #include <vector> #include <queue> #include <iostream> using namespace std; using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 300000; int const inf = 1000000000; int f[1 + nmax], scount[1 + nmax]; int dist[1 + nmax], dist2[1 + nmax]; vector<int> graph[1 + nmax]; vector<int> invg[1 + nmax]; void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { for(int i = 0; i < 2 * N; i++) f[i] = -1; for(int i = 0; i < M; i++){ int x = R[i][0], y = R[i][1]; graph[x].push_back(i); graph[y].push_back(i); } for(int i = 0;i < N; i++){ int e = graph[i][0]; int to = R[e][0] + R[e][1] - i; if(graph[to][0] == e) f[2 * i] = 2 * to + 1; else f[2 * i] = 2 * to; if(2 <= graph[i].size()){ int e = graph[i][1]; int to = R[e][0] + R[e][1] - i; if(graph[to][0] == e) f[2 * i + 1] = 2 * to + 1; else f[2 * i + 1] = 2 * to; } else f[2 * i + 1] = f[2 * i]; } for(int i = 0; i < 2 * N; i++) invg[f[i]].push_back(i); for(int i = 0; i < 2 * N; i++) dist[i] = dist2[i] = inf; queue<int> q; q.push(2 * P); dist[2 * P] = 0; while(0 < q.size()){ int node = q.front(); q.pop(); for(int h = 0; h < invg[node].size(); h++){ int to = invg[node][h]; if(dist[to] == inf){ dist[to] = dist[node] + 1; q.push(to); } } } dist[2 * P] = dist[f[2 * P]] + 1; q.push(2 * P + 1); dist2[2 * P + 1] = 0; while(0 < q.size()){ int node = q.front(); q.pop(); for(int h = 0; h < invg[node].size(); h++){ int to = invg[node][h]; if(dist2[to] == inf){ dist2[to] = dist2[node] + 1; q.push(to); } } } dist2[2 * P + 1] = dist2[f[2 * P + 1]] + 1; for(int i = 0; i < Q; i++){ int k = G[i]; int result = 0; for(int j = 0; j < N; j++){ if((k - dist[j * 2]) % dist[2 * P] == 0) result++; if((k - dist2[j * 2]) % dist2[2 * P + 1] == 0) result++; } answer(result); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 14584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 14584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 14584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |