Language: C++

#include <bits/stdc++.h>
#define MAXN 100001
#define MAXM 200001
using namespace std;
struct edge{
    int nod, c;
    edge(int nod, int c):nod(nod), c(c) {}
};
vector<vector<edge>> G;
char viz[MAXN];
int n, m;
int bfs(int nod, int caut, int cost) {
    //cout << "vizitez nodul " << nod << "cu costul " << cost << " caut " << caut << endl;
    if(nod == caut) {
        //cout << "am gasit cu costul " << cost << endl;
        return cost;
    }
    for(edge i : G[nod]) {
        if(viz[i.nod] == 0) {
            viz[i.nod] = 1;
            return bfs(i.nod, caut, cost + i.c);
        }
    }
    return 0;
}
int main() {
    cin >> n >> m;
    G.resize(n+1);
    for(int i = 0; i < m; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        memset(viz, 0, MAXN);
        viz[l] = 1;
        //cout << "bfs pt " << l << endl;
        int dg = bfs(l, r, 0);
        //cout << "dg: " << dg << endl;
        //cout << "viz\n";
        
        if(dg != d && dg != 0) {
            cout << "No\n";
            return 0;
        }
        G[l].push_back(edge(r, d));
        //G[r].push_back(edge(l, d));
    }
    cout << "Yes\n";
}
#include <bits/stdc++.h>
#define MAXN 100001
#define MAXM 200001
using namespace std;
struct edge{
    int nod, c;
    edge(int nod, int c):nod(nod), c(c) {}
};
vector<vector<edge>> G;
char viz[MAXN];
int n, m;
int bfs(int nod, int caut, int cost) {
    //cout << "vizitez nodul " << nod << "cu costul " << cost << " caut " << caut << endl;
    if(nod == caut) {
        //cout << "am gasit cu costul " << cost << endl;
        return cost;
    }
    for(edge i : G[nod]) {
        if(viz[i.nod] == 0) {
            viz[i.nod] = 1;
            return bfs(i.nod, caut, cost + i.c);
        }
    }
    return 0;
}
int main() {
    cin >> n >> m;
    G.resize(n+1);
    for(int i = 0; i < m; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        memset(viz, 0, MAXN);
        viz[l] = 1;
        //cout << "bfs pt " << l << endl;
        int dg = bfs(l, r, 0);
        //cout << "dg: " << dg << endl;
        //cout << "viz\n";
        
        if(dg != d && dg != 0) {
            cout << "No\n";
            return 0;
        }
        //G[l].push_back(edge(r, d));
        G[r].push_back(edge(l, d));
    }
    cout << "Yes\n";
}


Compiler output:
a.cc:52:8: error: redefinition of 'struct edge'
   52 | struct edge{
      |        ^~~~
a.cc:5:8: note: previous definition of 'struct edge'
    5 | struct edge{
      |        ^~~~
a.cc:56:22: error: redefinition of 'std::vector<std::vector<edge> > G'
   56 | vector<vector<edge>> G;
      |                      ^
a.cc:9:22: note: 'std::vector<std::vector<edge> > G' previously declared here
    9 | vector<vector<edge>> G;
      |                      ^
a.cc:57:6: error: redefinition of 'char viz [100001]'
   57 | char viz[MAXN];
      |      ^~~
a.cc:10:6: note: 'char viz [100001]' previously declared here
   10 | char viz[MAXN];
      |      ^~~
a.cc:58:5: error: redefinition of 'int n'
   58 | int n, m;
      |     ^
a.cc:11:5: note: 'int n' previously declared here
   11 | int n, m;
      |     ^
a.cc:58:8: error: redefinition of 'int m'
   58 | int n, m;
      |        ^
a.cc:11:8: note: 'int m' previously declared here
   11 | int n, m;
      |        ^
a.cc:59:5: error: redefinition of 'int bfs(int, int, int)'
   59 | int bfs(int nod, int caut, int cost) {
      |     ^~~
a.cc:12:5: note: 'int bfs(int, int, int)' previously defined here
   12 | int bfs(int nod, int caut, int cost) {
      |     ^~~
a.cc:73:5: error: redefinition of 'int main()'
   73 | int main() {
      |     ^~~~
a.cc:26:5: note: 'int main()' previously defined here
   26 | int main() {
      |     ^~~~