#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2e5+5;
int n,m,fin,k,best[mxn][3],go[mxn][40];
vector<int>vt[mxn];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
n=N,m=M,fin=P,k=G[0]+1;
for(int i=0;i<m;i++){
int u=R[i][0]+1,v=R[i][1]+1;
if(!best[u][0]){
best[u][0]=v;
}
else if(!best[u][1]){
best[u][1]=v;
}
if(!best[v][0]){
best[v][0]=u;
}
else if(!best[v][1]){
best[v][1]=u;
}
}
for(int i=1;i<=n;i++){
if(!best[i][1]){
best[i][1]=best[i][0];
}
}
for(int i=1;i<=n;i++){
cout<<best[i][0]<<' '<<best[i][1]<<endl;
}
for(int u=1;u<=n;u++){
int x=best[u][0],y=best[u][1];
//cout<<x<<' '<<y<<endl;
if(best[x][0]==u){
go[u][0]=x+n;
}
else{
go[u][0]=x;
}
if(best[y][0]==u){
go[u+n][0]=y+n;
}
else{
go[u+n][0]=y;
}
}
for(int i=1;i<32;i++){
for(int u=1;u<=2*n;u++){
go[u][i]=go[go[u][i-1]][i-1];
}
}
int ans=0;
for(int u=1;u<=n;u++){
int node=u;
for(int i=31;i>=0;i--){
if(k&(1<<i)){
node=go[node][i];
}
}
if(node==fin) ans++;
}
answer(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
5272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
5272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
5272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |