This is a rather old problem, but the link is here: here

This problem uses DFS and the code I have right now is this:

```
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
#define space " "
#define sz(x) (int)(x).size()
#define MOD 100007
void setIO(string name = "") {
/*if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}*/
}
int n, q;
int a[1005][1005];
int visited[1005];
bool found;
int ans = 0;
void dfs(int cur, int des, int len){
if(found == true){
return;
}
if(cur == des){
ans = len;
found = true;
return;
}
for(int i = 0; i < n; i++){
if(a[cur][i] != 0 && visited[i] == 0){
visited[i] = 1;
dfs(visited[i], des, len+a[cur][i]);
visited[i] = 0;
}
}
}
int main() {
//setIO("");
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
for(int i = 0; i < n+1; i++){
visited[i] = 0;
for(int j = 0; j < n+1; j++){
a[i][j] = 0;
}
}
for(int i = 0; i < n-1; i++){
int t1, t2, t3;
cin >> t1 >> t2 >> t3;
t1--;
t2--;
a[t1][t2] = t3;
a[t2][t1] = t3;
}
for(int i = 0; i < q; i++){
int b, c;
cin >> b >> c;
b--; c--;
ans = 0;
found = false;
visited[b] = 1;
dfs(b, c, 0);
cout << ans << endl;
}
}
```

I am not passing the example test case and am only get β2 0β as my output instead of β2 7β, does anyone know why?