#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");
vector<vector<int>> graf, res;
int curr, gres[2005];
void dfs(int node, int tata, vector<bool> vis)
{
res[curr].push_back(node);
///cout << node << ' ';
vis[node] = 1;
if(graf[node].size() == 1)
{
dfs(graf[node][0], node, vis);
}
else
{
if(tata == graf[node][0] && !vis[graf[node][1]])
dfs(graf[node][1], node, vis);
else if(!vis[graf[node][0]])
dfs(graf[node][0], node, vis);
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
graf.resize(N + 1);
res.resize(N + 1);
for(int i = 0; i < M; i++)
{
graf[R[i][0]].push_back(R[i][1]);
graf[R[i][1]].push_back(R[i][0]);
}
vector<bool> vis;
vis.resize(N + 1);
for(int i = 0; i < N; i++)
{
curr = i;
dfs(i, -1, vis);
///cout << '\n';
}
for(int j = 0; j < Q; j++)
{
for(int i = 0; i < N; i++)
{
if(res[i][G[j] % res[i].size()] == P)
gres[j]++;
}
answer(gres[j]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
2388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |