#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include "gardenlib.h"
using namespace std;
const int MAXN = 150000;
int arr[2 * MAXN + 10];
int dis[2][2 * MAXN + 10];
bool chk[2][2 * MAXN + 10];
void f(int x, int p)
{
chk[p % 2][x] = 1;
if(arr[x] == p)
{
dis[p % 2][x] = 1;
return;
}
if(!chk[p % 2][arr[x]])
f(arr[x], p);
if(dis[p%2][arr[x]])
dis[p % 2][x] = dis[p % 2][arr[x]] + 1;
}
int mem[MAXN + 10][2];
int sum[2][2 * MAXN + 10];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
memset(mem, -1, sizeof mem);
memset(arr, -1, sizeof arr);
for(int i = 0; i < M; i++)
{
int x = R[i][0];
int y = R[i][1];
if(mem[x][0] == -1)
mem[x][0] = y;
else if(mem[x][1] == -1)
mem[x][1] = y;
if(mem[y][0] == -1)
mem[y][0] = x;
else if(mem[y][1] == -1)
mem[y][1] = x;
}
for(int i = 0; i < N; i++)
{
if(mem[mem[i][0]][0] == i && mem[mem[i][0]][1] != -1)
arr[2 * i] = 2 * mem[i][0] + 1;
else
arr[2 * i] = 2 * mem[i][0];
if(mem[i][1] != -1)
{
if(mem[mem[i][1]][0] == i && mem[mem[i][1]][1] != -1)
arr[2 * i + 1] = 2 * mem[i][1] + 1;
else
arr[2 * i + 1] = 2 * mem[i][1];
}
}
for(int r = 0; r < 2; r++)
for(int i = 0; i < 2 * N; i++)
if(!chk[r][i] && arr[i] != -1)
f(i, 2 * P + r);
for(int r = 0; r < 2; r++)
for(int i = 0; i < N; i++)
if(dis[r][2 * i])
sum[r][dis[r][2 * i]]++;
for(int r = 0; r < 2; r++)
{
int c = dis[r][2 * P + r];
if(!c)
continue;
for(int i = 1; i <= 2 * N; i++)
if(c && i - c >= 1)
sum[r][i] += sum[r][i - c];
}
int c = max(dis[0][2 * P], dis[1][2 * P + 1]);
for(int i = 0; i < Q; i++)
{
int t = G[i];
if(t > 2 * N && c)
t -= ((t - 2 * N + c - 1) / c) * c;
if(t > 2 * N)
answer(0);
else
answer(sum[0][t] + sum[1][t]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2780 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
11 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
6 ms |
2812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2780 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
11 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
6 ms |
2812 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
11 ms |
3576 KB |
Output is correct |
12 |
Correct |
23 ms |
4252 KB |
Output is correct |
13 |
Correct |
37 ms |
11088 KB |
Output is correct |
14 |
Correct |
55 ms |
7772 KB |
Output is correct |
15 |
Correct |
57 ms |
8696 KB |
Output is correct |
16 |
Correct |
50 ms |
6436 KB |
Output is correct |
17 |
Correct |
48 ms |
5856 KB |
Output is correct |
18 |
Correct |
20 ms |
3544 KB |
Output is correct |
19 |
Correct |
65 ms |
8340 KB |
Output is correct |
20 |
Correct |
60 ms |
8684 KB |
Output is correct |
21 |
Correct |
51 ms |
5600 KB |
Output is correct |
22 |
Incorrect |
43 ms |
6444 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2780 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
5 ms |
2808 KB |
Output is correct |
7 |
Correct |
11 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
6 ms |
2812 KB |
Output is correct |
10 |
Correct |
4 ms |
2808 KB |
Output is correct |
11 |
Correct |
11 ms |
3576 KB |
Output is correct |
12 |
Correct |
23 ms |
4252 KB |
Output is correct |
13 |
Correct |
37 ms |
11088 KB |
Output is correct |
14 |
Correct |
55 ms |
7772 KB |
Output is correct |
15 |
Correct |
57 ms |
8696 KB |
Output is correct |
16 |
Correct |
50 ms |
6436 KB |
Output is correct |
17 |
Correct |
48 ms |
5856 KB |
Output is correct |
18 |
Correct |
20 ms |
3544 KB |
Output is correct |
19 |
Correct |
65 ms |
8340 KB |
Output is correct |
20 |
Correct |
60 ms |
8684 KB |
Output is correct |
21 |
Correct |
51 ms |
5600 KB |
Output is correct |
22 |
Incorrect |
43 ms |
6444 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |