Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define f first
#define pb push_back
#define s second
#define mp make_pair

int d[100100];
vector<pi> aList[100100];
int N,M,a,b,c;

void dfs(int x){
  for (auto i : aList[x]){
    int nxt = 0;
    if (i.f < x)nxt = d[x] - i.s;
    else nxt = d[x] + i.s;
    if (d[i.f] == -1){
      d[i.f] = nxt;
      dfs(i.f);
    }else{
      if (nxt != d[i.f]){
        cout<<"No";
        exit(0);
      }
    }
  }
}

int main(){
  cin >> N >> M;
  for (int i=0;i<M;++i){
    cin>>a>>b>>c;
    aList[a].pb(mp(b,c));
    aList[b].pb(mp(a,c));
  }
  memset(d, -1, sizeof(d));
  for (int i=1;i<=N;++i){ 
    if (d[i] != -1)continue;
    d[i] = 0;
    dfs(i);
  }
  cout<<"Yes";
}#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define f first
#define pb push_back
#define s second
#define mp make_pair

int d[100100];
vector<pi> aList[100100];
int N,M,a,b,c;

void dfs(int x){
  for (auto i : aList[x]){
    int nxt = 0;
    if (i.f < x)nxt = d[x] - i.s;
    else nxt = d[x] + i.s;
    if (d[i.f] == -1){
      d[i.f] = nxt;
      dfs(i.f);
    }else{
      if (nxt != d[i.f]){
        cout<<"No";
        exit(0);
      }
    }
  }
}

int main(){
  cin >> N >> M;
  for (int i=0;i<M;++i){
    cin>>a>>b>>c;
    aList[a].pb(mp(b,c));
    aList[b].pb(mp(a,c));
  }
  memset(d, -1, sizeof(d));
  for (int i=1;i<=N;++i){ 
    if (d[i] != -1)continue;
    d[i] = 0;
    dfs(i);
  }
  cout<<"Yes";
}#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define f first
#define pb push_back
#define s second
#define mp make_pair

int d[100100];
vector<pi> aList[100100];
int N,M,a,b,c;

void dfs(int x){
  for (auto i : aList[x]){
    int nxt = 0;
    if (i.f < x)nxt = d[x] - i.s;
    else nxt = d[x] + i.s;
    if (d[i.f] == -1){
      d[i.f] = nxt;
      dfs(i.f);
    }else{
      if (nxt != d[i.f]){
        cout<<"No";
        exit(0);
      }
    }
  }
}

int main(){
  cin >> N >> M;
  for (int i=0;i<M;++i){
    cin>>a>>b>>c;
    aList[a].pb(mp(b,c));
    aList[b].pb(mp(a,c));
  }
  memset(d, -1, sizeof(d));
  for (int i=1;i<=N;++i){ 
    if (d[i] != -1)continue;
    d[i] = 0;
    dfs(i);
  }
  cout<<"Yes";
}

Compiler output:
a.cc:46:2: error: stray '#' in program
   46 | }#include<bits/stdc++.h>
      |  ^
a.cc:91:2: error: stray '#' in program
   91 | }#include<bits/stdc++.h>
      |  ^
a.cc:46:3: error: 'include' does not name a type
   46 | }#include<bits/stdc++.h>
      |   ^~~~~~~
a.cc:56:5: error: redefinition of 'int d [100100]'
   56 | int d[100100];
      |     ^
a.cc:11:5: note: 'int d [100100]' previously declared here
   11 | int d[100100];
      |     ^
a.cc:57:12: error: redefinition of 'std::vector<std::pair<int, int> > aList [100100]'
   57 | vector<pi> aList[100100];
      |            ^~~~~
a.cc:12:12: note: 'std::vector<std::pair<int, int> > aList [100100]' previously declared here
   12 | vector<pi> aList[100100];
      |            ^~~~~
a.cc:58:5: error: redefinition of 'int N'
   58 | int N,M,a,b,c;
      |     ^
a.cc:13:5: note: 'int N' previously declared here
   13 | int N,M,a,b,c;
      |     ^
a.cc:58:7: error: redefinition of 'int M'
   58 | int N,M,a,b,c;
      |       ^
a.cc:13:7: note: 'int M' previously declared here
   13 | int N,M,a,b,c;
      |       ^
a.cc:58:9: error: redefinition of 'int a'
   58 | int N,M,a,b,c;
      |         ^
a.cc:13:9: note: 'int a' previously declared here
   13 | int N,M,a,b,c;
      |         ^
a.cc:58:11: error: redefinition of 'int b'
   58 | int N,M,a,b,c;
      |           ^
a.cc:13:11: note: 'int b' previously declared here
   13 | int N,M,a,b,c;
      |           ^
a.cc:58:13: error: redefinition of 'int c'
   58 | int N,M,a,b,c;
      |             ^
a.cc:13:13: note: 'int c' previously declared here
   13 | int N,M,a,b,c;
      |             ^
a.cc:60:6: error: redefinition of 'void dfs(int)'
   60 | void dfs(int x){
      |      ^~~
a.cc:15:6: note: 'void dfs(int)' previously defined here
   15 | void dfs(int x){
      |      ^~~
a.cc:77:5: error: redefinition of 'int main()'
   77 | int main(){
      |     ^~~~
a.cc:32:5: note: 'int main()' previously defined here
   32 | int main(){
      |     ^~~~
a.cc:91:3: error: 'include' does not name a type
   91 | }#include<bits/stdc++.h>
      |   ^~~~~~~
a.cc:101:5: error: redefinition of 'int d [100100]'
  101 | int d[100100];
      |     ^
a.cc:11:5: note: 'int d [100100]' previously declared here
   11 | int d[100100];
      |     ^
a.cc:102:12: error: redefinition of 'std::vector<std::pair<int, int> > aList [100100]'
  102 | vector<pi> aList[100100];
      |            ^~~~~
a.cc:12:12: note: 'std::vector<std::pair<int, int> > aList [100100]' previously declared here
   12 | vector<pi> aList[100100];
      |            ^~~~~
a.cc:103:5: error: redefinition of 'int N'
  103 | int N,M,a,b,c;
      |     ^
a.cc:13:5: note: 'int N' previously declared here
   13 | int N,M,a,b,c;
      |     ^
a.cc:103:7: error: redefinition of 'int M'
  103 | int N,M,a,b,c;
      |       ^
a.cc:13:7: note: 'int M' previously declared here
   13 | int N,M,a,b,c;
      |       ^
a.cc:103:9: error: redefinition of 'int a'
  103 | int N,M,a,b,c;
      |         ^
a.cc:13:9: note: 'int a' previously declared here
   13 | int N,M,a,b,c;
      |         ^
a.cc:103:11: error: redefinition of 'int b'
  103 | int N,M,a,b,c;
      |           ^
a.cc:13:11: note: 'int b' previously declared here
   13 | int N,M,a,b,c;
      |           ^
a.cc:103:13: error: redefinition of 'int c'
  103 | int N,M,a,b,c;
      |             ^
a.cc:13:13: note: 'int c' previously declared here
   13 | int N,M,a,b,c;
      |             ^
a.cc:105:6: error: redefinition of 'void dfs(int)'
  105 | void dfs(int x){
      |      ^~~
a.cc:15:6: note: 'void dfs(int)' previously defined here
   15 | void dfs(int x){
      |      ^~~
a.cc:122:5: error: redefinition of 'int main()'
  122 | int main(){
      |     ^~~~
a.cc:32:5: note: 'int main()' previously defined here
   32 | int main(){
      |     ^~~~