#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef int INT;
#define int long long
#define pb push_back
#define fst first
#define snd second
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define V vector
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
struct edge{
int v, l;
bool operator< (const edge &e){
return l < e.l;
}
};
V<V<edge>> graph;
vvi adj;
vi dists;
int dfs(int u, int depth, int p){
//cout << "dfs " << u << " " << depth << " " << p << endl;
if(u == p and depth != 0) return depth;
int ret = -1;
dists[depth] += u&1;
for(int v : adj[u]) ret = max(ret, dfs(v, depth+1, p));
return ret;
}
void count_routes(INT N, INT M, INT P, INT R[][2], INT Q, INT G[]) {
graph.resize(N);
adj.resize(2*N);
FOR(i, 0, M) {
graph[R[i][0]].pb({R[i][1], i});
graph[R[i][1]].pb({R[i][0], i});
}
FOR(i, 0, N) sort(graph[i].begin(), graph[i].end());
FOR(i, 0, N){
// 0 = from best, 1 = not from best
// move from 2n+1 -> graph[n][0]
// move from 2n -> graph[n][1], should it exist
// We'll only store the opposite
auto e1 = graph[i][0], e2 = graph[i][graph[i].size() > 1];
int l1 = graph[e1.v][0].l, l2 = graph[e2.v][0].l;
adj[ 2*e1.v + (e1.l != l1) ].pb(i<<1|1);
adj[ 2*e2.v + (e2.l != l2) ].pb(i<<1);
}
vi answers(Q, 0);
FOR(i, 0, 2){
dists.assign(4*N, 0);
int p = P<<1|i;
int l = dfs(p, 0, p);
//for(int k : dists) cout << k << " ";
//cout << endl;
//cout << l << endl;
if(l != -1) FOR(i, l, dists.size()) dists[i] += dists[i-l];
FOR(q, 0, Q) answers[q] += dists[ G[q] >= 4*N ? (G[q]-2*N)%l + 2*N : G[q] ];
}
FOR(i, 0, Q) answer(answers[i]);
}
Compilation message
garden.cpp: In function 'void count_routes(INT, INT, INT, INT (*)[2], INT, INT*)':
garden.cpp:12:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
^
garden.cpp:66:21: note: in expansion of macro 'FOR'
if(l != -1) FOR(i, l, dists.size()) dists[i] += dists[i-l];
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
2 ms |
388 KB |
Output is correct |
11 |
Correct |
18 ms |
5112 KB |
Output is correct |
12 |
Correct |
44 ms |
8824 KB |
Output is correct |
13 |
Correct |
73 ms |
27112 KB |
Output is correct |
14 |
Correct |
284 ms |
27768 KB |
Output is correct |
15 |
Correct |
219 ms |
28380 KB |
Output is correct |
16 |
Correct |
178 ms |
21508 KB |
Output is correct |
17 |
Correct |
174 ms |
19128 KB |
Output is correct |
18 |
Correct |
49 ms |
8796 KB |
Output is correct |
19 |
Correct |
199 ms |
27828 KB |
Output is correct |
20 |
Correct |
224 ms |
28484 KB |
Output is correct |
21 |
Correct |
179 ms |
21292 KB |
Output is correct |
22 |
Correct |
179 ms |
19408 KB |
Output is correct |
23 |
Correct |
208 ms |
30604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
2 ms |
388 KB |
Output is correct |
11 |
Correct |
18 ms |
5112 KB |
Output is correct |
12 |
Correct |
44 ms |
8824 KB |
Output is correct |
13 |
Correct |
73 ms |
27112 KB |
Output is correct |
14 |
Correct |
284 ms |
27768 KB |
Output is correct |
15 |
Correct |
219 ms |
28380 KB |
Output is correct |
16 |
Correct |
178 ms |
21508 KB |
Output is correct |
17 |
Correct |
174 ms |
19128 KB |
Output is correct |
18 |
Correct |
49 ms |
8796 KB |
Output is correct |
19 |
Correct |
199 ms |
27828 KB |
Output is correct |
20 |
Correct |
224 ms |
28484 KB |
Output is correct |
21 |
Correct |
179 ms |
21292 KB |
Output is correct |
22 |
Correct |
179 ms |
19408 KB |
Output is correct |
23 |
Correct |
208 ms |
30604 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
19 ms |
5400 KB |
Output is correct |
26 |
Correct |
45 ms |
8952 KB |
Output is correct |
27 |
Correct |
68 ms |
27328 KB |
Output is correct |
28 |
Correct |
207 ms |
28072 KB |
Output is correct |
29 |
Correct |
225 ms |
28852 KB |
Output is correct |
30 |
Correct |
170 ms |
21536 KB |
Output is correct |
31 |
Correct |
175 ms |
19324 KB |
Output is correct |
32 |
Correct |
46 ms |
8696 KB |
Output is correct |
33 |
Correct |
194 ms |
27640 KB |
Output is correct |
34 |
Correct |
231 ms |
28324 KB |
Output is correct |
35 |
Correct |
183 ms |
21604 KB |
Output is correct |
36 |
Correct |
176 ms |
19384 KB |
Output is correct |
37 |
Correct |
209 ms |
30740 KB |
Output is correct |
38 |
Correct |
189 ms |
40628 KB |
Output is correct |