#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
/*
* approach :- for each [p][0] and [p][1] , i store the cycle. now for each node,
* i need to find the distance and the cycle size. distance can be a pair of p [0] , p [1]
* then put it in a map , then using upper/lower bound , can find each query's answer
* don't know how to implement so leaving it :feelssadman:
*/
const int N = 150002;
int p;
int best[N][2];
int dp[N][2];
int place[N][2] , cycle[N][2] , si[N][2] , parent[N][2];
int num;
int dfs(int node , int pre){
if(dp[node][pre]!=-2)return dp[node][pre];
if(vis[node][pre] == 1){
cycle[node][pre] = ++num;
place[node][pre] = 1;
int siz = 1;
int cur = best[node][pre];
int pre1;
if(best[cur][0] == node && best[cur][1] != node)pre1 = 1;
else pre1 = 0;
while(cur != node && pre1 != pre){
place[cur][pre1] = ++siz;
if(best[best[cur][pre1]][0] == cur && best[best[cur][pre1]][1] != cur)pre1 = 1;
else pre1 = 0;
cur = best[cur][pre1];
}
si[num] = siz;
vis[node][pre] = 2;
return -18;
}
if(vis[node][pre] == 2)return 0;
vis[node[pre] = 1;
int next = best[node][pre];
int npre= 0;
if(best[next][0] == node && best[node][1] != node){
npre = 1;
}
int x = dfs(next , npre);
if(x <= -18){
parent[node][pre] = best[node][pre];
dp[node][pre] = 1;
}
if(x == -1)return dp[node][pre] = x;
if(vis[node][pre] != 2){
return dp[node][pre] = 1 + x;
}
return dp[node][pre] = x;
}
void count_routes(int n, int m, int p1, int r[][2], int q, int g[]){
p = p1;
vector<int> lol[n + 5];
for(int i = 0; i < m; i++){
lol[r[i][0]].pb(r[i][1]);
lol[r[i][1]].pb(r[i][0]);
}
for(int i = 0; i < n; i++){
best[i][0] = lol[i][0];
if(lol[i].size() > 1)best[i][1] = lol[i][1];
else best[i][1] = best[i][0];
}
memset(vis,0,sizeof vis);
for(int i = 0; i <= n; i++){
dp[i][0] = dp[i][1] = -2;
f[i][0] = f[i][1] = -1;
place[i][0] = place[i][1] = -1;
cycle[i][0] = cylce[i][1] = -1;
parent[i][0] = parent[i][1] = -1;
si[i][0] = si[i][1] = 0;
}
num = 0;
int ans = 0;
for(int i = 0; i < n; i++){
ans += dfs(i , 0);
}
if(cycle[p][0] == cycle[p][1]){
map<int,vector<int>> m;
for(int i = 0; i < n; i++){
}
}
answer(ans);
}
Compilation message
garden.cpp: In function 'int dfs(int, int)':
garden.cpp:36:5: error: 'vis' was not declared in this scope; did you mean 'vs'?
36 | if(vis[node][pre] == 1){
| ^~~
| vs
garden.cpp:50:11: error: incompatible types in assignment of 'int' to 'int [2]'
50 | si[num] = siz;
| ~~~~~~~~^~~~~
garden.cpp:54:5: error: 'vis' was not declared in this scope; did you mean 'vs'?
54 | if(vis[node][pre] == 2)return 0;
| ^~~
| vs
garden.cpp:55:2: error: 'vis' was not declared in this scope; did you mean 'vs'?
55 | vis[node[pre] = 1;
| ^~~
| vs
garden.cpp:55:10: error: invalid types 'int[int]' for array subscript
55 | vis[node[pre] = 1;
| ^
garden.cpp:55:19: error: expected ']' before ';' token
55 | vis[node[pre] = 1;
| ^
| ]
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:86:9: error: 'vis' was not declared in this scope; did you mean 'vs'?
86 | memset(vis,0,sizeof vis);
| ^~~
| vs
garden.cpp:89:3: error: 'f' was not declared in this scope
89 | f[i][0] = f[i][1] = -1;
| ^
garden.cpp:91:17: error: 'cylce' was not declared in this scope; did you mean 'cycle'?
91 | cycle[i][0] = cylce[i][1] = -1;
| ^~~~~
| cycle