Language: C++

#include<iostream>
#include<vector>
using namespace std;
int dist[100005];
vector<int> G[100005];
int N,a,b,c,Q,K;
int dfs(int nod)
{
for(auto it:G[nod])
{
if(!dist[it.first])
{
dist[it.first]=dist[nod]+it.second;
dfs(it.first);
}
}
}
int main()
{
    cin>>N;
for(int i=1;i<N;i++){cin>>a>>b>>c;G[a].push_back({b,c});G[b].push_back({a,c});}
cin>>Q>>K;
dist[K]=1;
dfs(K);
while(Q--){cin>>a>>b;cout<<dist[a]+dist[b]-2<<"\n";}
}


Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:11:13: error: request for member 'first' in 'it', which is of non-class type 'int'
   11 | if(!dist[it.first])
      |             ^~~~~
a.cc:13:9: error: request for member 'first' in 'it', which is of non-class type 'int'
   13 | dist[it.first]=dist[nod]+it.second;
      |         ^~~~~
a.cc:13:29: error: request for member 'second' in 'it', which is of non-class type 'int'
   13 | dist[it.first]=dist[nod]+it.second;
      |                             ^~~~~~
a.cc:14:8: error: request for member 'first' in 'it', which is of non-class type 'int'
   14 | dfs(it.first);
      |        ^~~~~
a.cc:17:1: warning: no return statement in function returning non-void [-Wreturn-type]
   17 | }
      | ^
a.cc: In function 'int main()':
a.cc:21:49: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   21 | for(int i=1;i<N;i++){cin>>a>>b>>c;G[a].push_back({b,c});G[b].push_back({a,c});}
      |                                   ~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:21:71: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   21 | for(int i=1;i<N;i++){cin>>a>>b>>c;G[a].push_back({b,c});G[b].push_back({a,c});}
      |                                                         ~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~