#include "garden.h"
#include "gardenlib.h"
#define pb emplace_back
#include<bits/stdc++.h>
using namespace std;
int up[300005][1000];
vector<int>g[300005];
void dfs(int u,int pr)
{
if(up[u][0]!=-2e9) return;
up[u][0] = pr;
for(auto v:g[u])
{
if(v!=pr) dfs(v,u);
}
}
void setup(int n)
{
int jp=log2(n)+1;
for(int i=0;i<n;i++) up[i][0]=-2e9;
for(int i=0;i<n;i++)
{
if(up[i][0]!=-2e9) continue;
dfs(i,-1);
}
for(int i=1;i<=jp;i++)
{
for(int j=0;j<n;j++)
{
up[j][i] = up[up[j][i-1]][i-1];
}
}
}
void count_routes(int n, int m, int p, int R[][2], int Q, int G[])
{
for(int i=0;i<m;i++)
{
if(g[R[i][0]].size()<=2) g[R[i][0]].pb(R[i][1]);
if(g[R[i][1]].size()<=2) g[R[i][1]].pb(R[i][0]);
}
vector<int>g2[2*n+5];
for(int i=0;i<n;i++)
{
int v = g[i][0];
if(i==g[v][0] and g[v].size()!=1) g2[i].pb(v+n);
else g2[i].pb(v);
int vv;
if(g[i].size()!=1) vv = g[i][1];
else vv = g[i][0];
if(i==g[vv][0]) g2[i+n].pb(vv+n);
else g2[i+n].pb(vv);
}
for(int k=0;k<Q;k++)
{
int d = G[k];
int ans=0;
for(int i=0;i<n;i++)
{
int u=i;
for(int j=0;j<d;j++)
{
u = g2[u][0];
}
if(u==p or u==p+n) ans++;
}
answer(ans);
}
// for(int i=0; i<Q; i++)
// answer(n);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
4 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
10832 KB |
Output is correct |
5 |
Correct |
2 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
10832 KB |
Output is correct |
8 |
Correct |
3 ms |
10832 KB |
Output is correct |
9 |
Correct |
3 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
4 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
10832 KB |
Output is correct |
5 |
Correct |
2 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
10832 KB |
Output is correct |
8 |
Correct |
3 ms |
10832 KB |
Output is correct |
9 |
Correct |
3 ms |
10832 KB |
Output is correct |
10 |
Correct |
7 ms |
10832 KB |
Output is correct |
11 |
Execution timed out |
5063 ms |
13904 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10832 KB |
Output is correct |
2 |
Correct |
4 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
2 ms |
10832 KB |
Output is correct |
5 |
Correct |
2 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
2 ms |
10832 KB |
Output is correct |
8 |
Correct |
3 ms |
10832 KB |
Output is correct |
9 |
Correct |
3 ms |
10832 KB |
Output is correct |
10 |
Correct |
7 ms |
10832 KB |
Output is correct |
11 |
Execution timed out |
5063 ms |
13904 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |