criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = std::size_t;
  using container_type =
      std::vector<std::tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return std::get<0>(c[i]); }
  size_type par(const size_type i) const { return std::get<0>(c[i]); }
  value_type &val(const size_type i) { return std::get<1>(c[i]); }
  const value_type &val(const size_type i) const { return std::get<1>(c[i]); }
  size_type &siz(const size_type i) { return std::get<2>(c[i]); }
  size_type siz(const size_type i) const { return std::get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(x)) {
      val(i) = val(i) + val(par(x));
      ret = ret + val(i);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, std::forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      std::swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = std::move(d);
    return true;
  }
};

#include<iostream>

int main() {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Compiler output:
a.cc: In member function 'PotentializedUnionFind<Abelian>::value_type PotentializedUnionFind<Abelian>::potential(size_type)':
a.cc:28:11: error: 'i' was not declared in this scope
   28 |       val(i) = val(i) + val(par(x));
      |           ^
Language: C++

#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = std::size_t;
  using container_type =
      std::vector<std::tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return std::get<0>(c[i]); }
  size_type par(const size_type i) const { return std::get<0>(c[i]); }
  value_type &val(const size_type i) { return std::get<1>(c[i]); }
  const value_type &val(const size_type i) const { return std::get<1>(c[i]); }
  size_type &siz(const size_type i) { return std::get<2>(c[i]); }
  size_type siz(const size_type i) const { return std::get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(i)) {
      val(i) = val(i) + val(par(i));
      ret = ret + val(i);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, std::forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(i)) {
      val(i) = val(i) + val(par(i));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      std::swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = std::move(d);
    return true;
  }
};

#include<iostream>

int main() {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Compiler output:
a.cc: In member function 'PotentializedUnionFind<Abelian>::value_type PotentializedUnionFind<Abelian>::potential(size_type)':
a.cc:27:21: error: 'i' was not declared in this scope
   27 |     while (x != par(i)) {
      |                     ^
a.cc: In member function 'PotentializedUnionFind<Abelian>::size_type PotentializedUnionFind<Abelian>::find(size_type)':
a.cc:49:21: error: 'i' was not declared in this scope
   49 |     while (x != par(i)) {
      |                     ^
Language: C++

#include <cassert>
#include <cstdint>
#include <functional>
#include <tuple>
#include <vector>

template <typename Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using reference = value_type &;
  using const_reference = const value_type &;
  using size_type = std::uint_fast32_t;

private:
  std::vector<std::tuple<bool, size_type, value_type>> tree;
  value_type potential(const size_type x) {
    find(x);
    return std::get<2>(tree[x]);
  }

public:
  PotentializedUnionFind(const size_type size)
      : tree(size, std::forward_as_tuple(1, 1, value_type())) {}
  size_type find(const size_type x) {
    assert(x < tree.size());
    if (std::get<0>(tree[x]))
      return x;
    const size_type t = std::get<1>(tree[x]);
    std::get<1>(tree[x]) = find(t);
    std::get<2>(tree[x]) = std::get<2>(tree[t]) + std::get<2>(tree[x]);
    return std::get<1>(tree[x]);
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return potential(y)+ (-potential(x)));
  }
  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + diff(y, x);
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (std::get<1>(tree[x]) < std::get<1>(tree[y]))
      std::swap(x, y), d = -d;
    std::get<1>(tree[x]) += std::get<1>(tree[y]);
    tree[y] = std::forward_as_tuple(0, x, d);
    return true;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return std::get<1>(tree[find(x)]);
  }
  size_type size() const noexcept { return tree.size(); }
  bool empty() const noexcept { return tree.empty(); }
};
 
#include<iostream>
int main(void) {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

Compiler output:
a.cc: In member function 'PotentializedUnionFind<Abelian>::value_type PotentializedUnionFind<Abelian>::diff(size_type, size_type)':
a.cc:37:41: error: expected ';' before ')' token
   37 |     return potential(y)+ (-potential(x)));
      |                                         ^
a.cc:37:41: error: expected primary-expression before ')' token
Language: C++

#include<iostream>
#include<vector>
#define inf 1e18
#define end(a) {cout<<a;return 0;}
using namespace std;
vector<pair<int,int> > v[100005];
long long dp[100005];
int n,m;
void dpinf(void)
{
	for(int i=0;i<n;i++)
		dp[i]=inf;
}
void ready(void)
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		l--;
		r--;
		v[l].push_back({r,d});
		v[r].push_back({l,-d});  
	}
	dpinf();
}
int main(){
	ready();
	for(int i=0;i<n;i++)
	{
		if(dp[i]==inf)
		{
			queue<int> q;
			q.push(i);
			dp[i]=0;
			while(!q.empty())
			{
				int k=q.front();
				q.pop();
				for(int j=0;j<v[k].size();j++)
				{
					pair<int,int> p=v[k][j];
					int to=p.first,dis=p.second;
					if(dp[to]==inf)
					{
						dp[to]=dp[k]+dis;
						q.push(to); 
					}
					else if(dp[to]!=dp[k]+dis)
						end("No");
				}
			}
		}
	}
	end("Yes");
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:25: error: 'queue' was not declared in this scope
   34 |                         queue<int> q;
      |                         ^~~~~
a.cc:3:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    2 | #include<vector>
  +++ |+#include <queue>
    3 | #define inf 1e18
a.cc:34:31: error: expected primary-expression before 'int'
   34 |                         queue<int> q;
      |                               ^~~
a.cc:35:25: error: 'q' was not declared in this scope
   35 |                         q.push(i);
      |                         ^
Language: C++

#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<cstring>
#include<map>
#include<iomanip>
#include<ctime>
#include<windows.h>
#include<set>
#define sp system("pause");
#define ms(a,b) memset(a,b,sizeof(a));
#define inf 1e18
#define end(a) {cout<<a;return 0;}
using namespace std;
vector<pair<int,int> > v[100005];
long long dp[100005];
int n,m;
void dpinf(void)
{
	for(int i=0;i<n;i++)
		dp[i]=inf;
}
void ready(void)
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		l--;
		r--;
		v[l].push_back({r,d});
		v[r].push_back({l,-d});  
	}
	dpinf();
}
int main(){
	ready();
	for(int i=0;i<n;i++)
	{
		if(dp[i]==inf)
		{
			queue<int> q;
			q.push(i);
			dp[i]=0;
			while(!q.empty())
			{
				int k=q.front();
				q.pop();
				for(int j=0;j<v[k].size();j++)
				{
					pair<int,int> p=v[k][j];
					int to=p.first,dis=p.second;
					if(dp[to]==inf)
					{
						dp[to]=dp[k]+dis;
						q.push(to); 
					}
					else if(dp[to]!=dp[k]+dis)
						end("No");
				}
			}
		}
	}
	end("Yes");
}

Compiler output:
a.cc:13:9: fatal error: windows.h: No such file or directory
   13 | #include<windows.h>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<vector>
using namespace std;
vector <pair<int,int> > u[10005];
int val[100005];
int n,m,a,b,d;
bool tk[10005];
Dfs(int v,int cost)
{
	if(tk[v])
	    return val[v]==cost;
	tk[v]=true;
	val[v]=cost;
	for(int i=0;i<u[v].size();i++)
	{
		pair<int,int> p=u[v][i];
		if(!Dfs(p.first,val[v]+p.second))return false;
	}
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b>>d;
		u[a].push_back(make_pair(b,d));
		u[b].push_back(make_pair(a,-d));
	}
	for(int i=0;i<=n;i++)
	    if(!tk[i]&&!Dfs(i,0))
	    {
	    	cout<<"No";
	    	return 0;
		}
	cout<<"Yes";
	return 0;
}

Compiler output:
a.cc:8:1: error: ISO C++ forbids declaration of 'Dfs' with no type [-fpermissive]
    8 | Dfs(int v,int cost)
      | ^~~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
vector <pair<int,int> > u[10005];
int val[100005];
int n,m,a,b,d;
bool tk[10005];
dfs(int v,int cost)
{
	if(tk[v])
	    return val[v]==cost;
	tk[v]=true;
	val[v]=cost;
	for(int i=0;i<u[v].size();i++)
	{
		pair<int,int> p=u[v][i];
		if(!dfs(p.first,val[v]+p.second))return false;
	}
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b>>d;
		u[a].push_back(make_pair(b,d));
		u[b].push_back(make_pair(a,-d));
	}
	for(int i=0;i<=n;i++)
	    if(!tk[i]&&!dfs(i,0))
	    {
	    	cout<<"No";
	    	return 0;
		}
	cout<<"Yes";
	return 0;
}

Compiler output:
a.cc:8:1: error: ISO C++ forbids declaration of 'dfs' with no type [-fpermissive]
    8 | dfs(int v,int cost)
      | ^~~
Language: C++

#include<bits/stdc++.h>

using namespace std;
int u[200005];
int v[200005];
int w[200005];
int next[200005];
int head[100005];
int dis[100005];
bool vis[100005];
int cnt=0;
void add(int u1,int v1,int w1)
{
	cnt++;
	u[cnt]=u1;
	v[cnt]=v1;
	w[cnt]=w1;
	next[cnt]=head[u1];
	head[u1]=cnt;
}
bool find(int x)
{
	int j=head[x];
	while(j!=-1)
	{
		if(!vis[v[j]])
		{
			vis[v[j]]=true;
			dis[v[j]]=dis[x]+w[j];
			find(v[j]);
		}
		else
		{
			if(dis[v[j]]!=dis[x]+w[j])
			{
				return false;
			}
		}
		j=next[j];
	}
	return true;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) head[i]=-1;
	for(int i=1;i<=m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		add(l,r,d);
		add(r,l,-d);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			vis[i]=true;
			if(find(i)==false)
			{
				cout<<"No"<<endl;
				return 0; 
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
} 

Compiler output:
a.cc: In function 'void add(int, int, int)':
a.cc:18:9: error: reference to 'next' is ambiguous
   18 |         next[cnt]=head[u1];
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
a.cc: In function 'bool find(int)':
a.cc:39:19: error: reference to 'next' is ambiguous
   39 |                 j=next[j];
      |                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
Language: C++

#include <iostream>

using namespace std;
int u[200005];
int v[200005];
int w[200005];
int next[200005];
int head[100005];
int dis[100005];
bool vis[100005];
int cnt=0;
void add(int u1,int v1,int w1)
{
	cnt++;
	u[cnt]=u1;
	v[cnt]=v1;
	w[cnt]=w1;
	next[cnt]=head[u1];
	head[u1]=cnt;
}
bool find(int x)
{
	int j=head[x];
	while(j!=-1)
	{
		if(!vis[v[j]])
		{
			vis[v[j]]=true;
			dis[v[j]]=dis[x]+w[j];
			find(v[j]);
		}
		else
		{
			if(dis[v[j]]!=dis[x]+w[j])
			{
				return false;
			}
		}
		j=next[j];
	}
	return true;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) head[i]=-1;
	for(int i=1;i<=m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		add(l,r,d);
		add(r,l,-d);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			vis[i]=true;
			if(find(i)==false)
			{
				cout<<"No"<<endl;
				return 0; 
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
} 

Compiler output:
a.cc: In function 'void add(int, int, int)':
a.cc:18:9: error: reference to 'next' is ambiguous
   18 |         next[cnt]=head[u1];
      |         ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
a.cc: In function 'bool find(int)':
a.cc:39:19: error: reference to 'next' is ambiguous
   39 |                 j=next[j];
      |                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
Language: C

#include <stdio.h>
#include <stdlib.h>
typedef struct{
    int L;
    int R;
    int D;
}info;

int comp(const void *a, const void *b){
    info s_a = *(info*)a, s_b = *(info*)b;
    if(s_a.L == s_b.L){
        return s_a.R - s_b.R;
    }else{
        return s_a.L - s_b.L;
    }
}

int main(){
    int N, M;
    int i;
    scanf("%d %d", &N, &M);
    info data[M];
    int position[N];

    for(i = 0; i < M; ++i){
        scanf("%d %d %d", &data[i].L, &data[i].R, &data[i].D);
    }

    qsort(data, M, sizeof(info), comp);

    position[data[0].L - 1] = 0;
    for(i = 0; i < N; ++i){
        if(i != data[0].L - 1){
            position[i] = INT32_MAX;
        }
    }
    /*
    for(i = 0; i < M; ++i){
        printf("(L, R, D) = (%d %d %d)\n", data[i].L, data[i].R, data[i].D);
    }
    */

    char flag = 1;

    for(i = 0; i < M; ++i){
        int l = position[data[i].L - 1], r = position[data[i].R - 1];

        if(l == INT32_MAX && r != INT32_MAX){
            position[data[i].L - 1] = r - data[i].D;
        }else if(r == INT32_MAX && l != INT32_MAX){
            position[data[i].R - 1] = l + data[i].D;
        }else if(r != INT32_MAX && l != INT32_MAX){
            flag &= (r - l == data[i].D);
            if(!flag){
                break;
            }
        }
    }

    if(flag){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    /*
    for(i = 0; i < N; ++i){
        if(position[i] != INT32_MAX){
            printf("%d : %d\n", i, position[i]);
        }
    }
    */

    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:34:27: error: 'INT32_MAX' undeclared (first use in this function)
   34 |             position[i] = INT32_MAX;
      |                           ^~~~~~~~~
main.c:3:1: note: 'INT32_MAX' is defined in header '<stdint.h>'; this is probably fixable by adding '#include <stdint.h>'
    2 | #include <stdlib.h>
  +++ |+#include <stdint.h>
    3 | typedef struct{
main.c:34:27: note: each undeclared identifier is reported only once for each function it appears in
   34 |             position[i] = INT32_MAX;
      |                           ^~~~~~~~~
Language: C++

#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
#define MINF -1e12

int main(){
  vector<pair <int, long long> > v[100001];

  int n, m;
  cin >> n >> m;
  for (int cas = 0; cas < m; cas++){
    int l, r; long long d;
    cin >> l >> r >> d;
    v[l].push_back(make_pair(r, d));
    v[r].push_back(make_pair(l, -d));
  }

  long long d[100001];
  for (int i = 0; i < n; i++){
    d[i+1] = MINF;
  }

  for (int i = 1; i <= n; i++){
    if (d[i] == MINF) d[i] = 0;
    for (int j = 0; j < v[i].size(); j++){
      if (d[v[i][j].first] == MINF) d[v[i][j].first] = d[i] + v[i][j].second;
      else {
        if (d[v[i][j].first] != d[i] + v[i][j].second){
          printf("No\n");
          return 0;
        }
      }
    }
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:36:4: error: expected '}' at end of input
   36 |   }
      |    ^
a.cc:8:11: note: to match this '{'
    8 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
long long int n,m,k,i,j=1;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1,};
ll a,b,c;

std::vector<P> tree[100010];
long long int d[100005];
bool flag=false;

void bfs(int node,ll x){
	d[node] = x;
	for(int i=0;i<tree[node].size();i++){
		if(d[tree[node][i].first]==INF){
			bfs(tree[node][i].first,x+tree[node][i].second);
		}else{
			if(d[tree[node][i].first]!=x+tree[node][i].second){
				flag=true;
			}
		}
	}
}

int main(){
	cin>>n>>m;
	for(i=1;i<=m;i++){
		cin>>a>>b>>c;
		tree[a].push_back(P(b,c));
		tree[b].push_back(P(a,-c));
	}
	for(i=1;i<=n;i++)d[i]=INF;
	for(i=1;i<=n;i++){
		if(d[i]==INF &&)bfs(i,0);
	}
	if(flag){
		cout<<"No";
	}else{
		cout<<"Yes";
	}

	cout<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:32: error: expected primary-expression before ')' token
   56 |                 if(d[i]==INF &&)bfs(i,0);
      |                                ^
Language: C

#include<stdio.h>
#include<algorithm>
#define MAXN 100010
using namespace std;
int N, M;
int f[MAXN], dis[MAXN];
void init()
{
	for (int i = 0; i <= N; i++)
	{
		f[i] = i;
	}
}
int find(int x)
{
	if (f[x] == x)
		return x;
	else
	{
		dis[x] = dis[f[x]] + dis[x];
		return f[x] = find(f[x]);
	}
}
int find_father(int x,int y,int z)
{
	int fx = find(x);
	int fy = find(y);
	if (fx == fy)
	{
		return z == (dis[y] - dis[x]);
	}
	f[fy] = fx;
	dis[fy] = dis[x] + z - dis[y];
	return 1;
}
int main()
{
	
	while (~scanf("%d %d", &N, &M))
	{
		init();
		int a = 1;
		int x, y, z;
		for (int i = 1; i <= M; i++)
		{
			scanf("%d %d %d", &x, &y, &z);
			if (a)
				a = find_father(x, y, z);
		}
		if (a)
			printf("Yes\n");
		else
			printf("No\n");
	}
}

Compiler output:
main.c:2:9: fatal error: algorithm: No such file or directory
    2 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C++

import java.util.*;

public class Main {
    static char[][] c;

    public static void main(String[] args) throws InterruptedException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        long[] x = new long[n + 1];
        Set<Integer> a = new HashSet<>();
        Set<M> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            set.add(new M(scan.nextInt(), scan.nextInt(), scan.nextInt()));
        }
        while(!set.isEmpty()) {
            Optional<M> o = set.stream().filter(data -> a.contains(data.l) || a.contains(data.r)).findAny();
            if(o.isPresent()) {
                M c = o.get();
                if(a.contains(c.l)) {
                    if(a.contains(c.r)) {
                        if(x[c.r] - x[c.l] != c.d) {
                            System.out.println("No");
                            return;
                        }
                    }
                    else {
                        x[c.r] = x[c.l] + c.d;
                        a.add(c.r);
                    }
                }
                else {
                    x[c.l] = x[c.r] - c.d;
                    a.add(c.l);
                }
                set.remove(c);
            }
            else {
                M c = set.stream().findAny().get();
                x[c.l] = 0;
                x[c.r] = c.d;
                a.add(c.l);
                a.add(c.r);
                set.remove(c);
            }
        }
        System.out.println("Yes");
    }

    static class M {
        int l;
        int r;
        int d;

        M(int l, int r, int d) {
            this.l = l;
            this.r = r;
            this.d = d;
        }

        public boolean equals(Object obj) {
            M o = (M) obj;
            return this.l == o.l &&this.r == o.r && this.d == o.d;
        }

        public int hashCode() {
            return l * 31 + r * 17 + d;
        }
    }
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: expected unqualified-id before 'public'
    3 | public class Main {
      | ^~~~~~
Language: C++

import java.util.*;

public class Main {
    static char[][] c;

    public static void main(String[] args) throws InterruptedException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        long[] x = new long[n + 1];
        Set<Integer> a = new HashSet<>();
        Set<M> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            set.add(new M(scan.nextInt(), scan.nextInt(), scan.nextInt()));
        }
        while(!set.isEmpty()) {
            Optional<M> o = set.stream().filter(data -> a.contains(data.l) || a.contains(data.r)).findAny();
            if(o.isPresent()) {
                M c = o.get();
                if(a.contains(c.l)) {
                    if(a.contains(c.r)) {
                        if(x[c.r] - x[c.l] != c.d) {
                            System.out.println("No");
                            return;
                        }
                    }
                    else {
                        x[c.r] = x[c.l] + c.d;
                        a.add(c.r);
                    }
                }
                else {
                    x[c.l] = x[c.r] - c.d;
                    a.add(c.l);
                }
                set.remove(c);
            }
            else {
                M c = set.stream().findAny().get();
                x[c.l] = 0;
                x[c.r] = c.d;
                a.add(c.l);
                a.add(c.r);
                set.remove(c);
            }
        }
        System.out.println("Yes");
    }

    static class M {
        int l;
        int r;
        int d;

        M(int l, int r, int d) {
            this.l = l;
            this.r = r;
            this.d = d;
        }

        @Override
        public boolean equals(Object obj) {
            M o = (M) obj;
            return this.l == o.l &&this.r == o.r && this.d == o.d;
        }

        @Override
        public int hashCode() {
            return l * 31 + r * 17 + d;
        }
    }
}

Compiler output:
a.cc:61:9: error: stray '@' in program
   61 |         @Override
      |         ^
a.cc:67:9: error: stray '@' in program
   67 |         @Override
      |         ^
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: expected unqualified-id before 'public'
    3 | public class Main {
      | ^~~~~~
Language: C++

#include<stdio.h>
#include<string>
#include<queue>
#include<iostream>
using namespace std;
int n, m;
vector<pair<int, int>> mp[100000];
struct p {
	int l, r, d;
};

p ps[200000];
int a[100000];
bool dfs(int l, int r, int  d, int pos, int sum, bool f) {
	for (int j = 0; j < mp[pos].size(); j++) {
		if (a[mp[pos][j].first] != 0) {
			continue;
		}
		sum += mp[pos][j].second;
		a[mp[pos][j].first] = 1;
		if (f) {
			if (mp[pos][j].first < l) {
				return dfs(l, r, d, mp[pos][j].first, sum, f);
			}
			else if (mp[pos][j].first == l) {
				if (sum == d) {
					return true;
				}
			}
			return false;
		}
		else {
			if (mp[pos][j].first > l) {
				return dfs(l, r, d, mp[pos][j].first, sum, f);
			}
			else if (mp[pos][j].first == l) {
				if (sum == d) {
					return true;
				}
				return false;
			}
		}
	}
}

int main()
{
	cin >> n >> m;
	int l, r, d;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> d;
		ps[i].r = r;
		ps[i].l = l;
		ps[i].d = d;
		mp[l].push_back(pair<int, int>(r, d));
		mp[r].push_back(pair<int, int>(l, d));
	}
	if (m == 0) {
		cout << "No" << endl;
		return 0;
	}
	queue<int> q;
	for (int i = 0; i < m; i++) {
		r = ps[i].r;
		l = ps[i].l;
		d = ps[i].d;
		bool f = (l - r) > 0;
		if (!dfs(l, r, d, r, 0, f)) {
			cout << "No" << endl;
			return 0;
		}
		memset(a, 0, sizeof(a));
	}
	cout << "Yes" << endl;

	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:72:17: error: 'memset' was not declared in this scope
   72 |                 memset(a, 0, sizeof(a));
      |                 ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<iostream>
  +++ |+#include <cstring>
    5 | using namespace std;
a.cc: In function 'bool dfs(int, int, int, int, int, bool)':
a.cc:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^
Language: C++

#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;

const int N = 1e5+5;
int L[N],R[N],D[N];
int n,m;
int fa[N],r[N];

void init()
{
    for(int i=0; i<=n; i++)
    {
        fa[i] = i;
    }
    memset(r,0,sizeof(r));
}

int Find(int x)
{
    return fa[x]==x ? x : Find(fa[x]);
}

bool Merge(int x, int y, int d)
{
    int fx = Find(x);
    int fy = Find(y);
    if(fx != fy)
    {
        fa[y] = fx;a
        r[y] += r[x] + d;
    }
    else
    {
        if(x==fa[x])
        {
            if(r[y] != d)
                return 0;
        }
        if(r[y]-r[x] != d)
            return 0;
    }
    return 1;
}

int main()
{
    while(scanf("%d%d",&n,&m) != EOF)
    {
        {
            int ok = 1;
            init();
            for(int i=0; i<m; i++)
            {
                scanf("%d%d%d",&L[i],&R[i],&D[i]);
                if(ok && !Merge(L[i],R[i],D[i]))
                {
                    ok = 0;
                }
            }
            if(ok) printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}


Compiler output:
a.cc: In function 'bool Merge(int, int, int)':
a.cc:36:20: error: 'a' was not declared in this scope
   36 |         fa[y] = fx;a
      |                    ^
Language: C

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;

int main()
{
	int n,m;
	bool f=true;
	map<int,int> mp;
	int l,r,d;
	scanf("%d%d",&n,&m);
	if (m)
	{
	    scanf("%d%d%d",&l,&r,&d);
    	mp[l]=0;
    	mp[r]=d;
    }
	for (int i=1;i<m;i++)
	{
		scanf("%d%d%d",&l,&r,&d);
		if (mp.count(l) && mp.count(r)) 
		  {if (d!=mp[r]-mp[l]) f=false;}
		else if (!mp.count(l)) mp[l]=mp[r]-d;
		else mp[r]=mp[l]+d;
	}
	if (f) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
struct edge {
  ll s;
  ll t;
  ll cost;
};

const ll MAX_N = 100000;
const ll MAX_M = 200000;

ll d[MAX_N], l[MAX_M], r[MAX_M], c[MAX_M];
vector<edge> es[MAX_M];

void debug(ll u, ll v) {
  cout << "no " << u << ": ";
  for (ll i = 0; i < v; i++) {
    cout << d[i] << " ";
  }
  cout << endl;
}

bool bellmanford(ll n) {
  fill(d, d+n, LLONG_MAX);
  d[0] = 0;
  for (ll u = 0; u < n; u++) {
    for (ll v = 0; v < n; v++) {
      for (auto e: es[v]) {
	//debug(u, n);
	//cout << e.s << " " << e.t << " " << e.cost << endl;
	if ((d[v] != LLONG_MAX) &&
	    (d[e.t] > (d[v] + e.cost)))
	  {
	    d[e.t] = d[v] + e.cost;
	    if (u == n-1) return true;
	  }
      }
    }
  }
  return false;
}

int main() {
  ll n, m;
  cin >> n >> m;

  ll min_l = LLONG_MAX;
  for (ll i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
    min_l = min(min_l, min(l[i], r[i]));
  }
  for (ll i = 0; i < m; i++) {
    ll ln = l[i] - min_l;
    ll rn = r[i] - min_l;
    edge p = {ln, rn, c[i]};
    edge q = {rn, ln, -c[i]};
    es[ln].push_back(p);
    es[rn].push_back(q);
  }
  cout << (bellmanford(n) ? "No" : "Yes") << endl;
}

Compiler output:
a.cc: In function 'bool bellmanford(ll)':
a.cc:27:16: error: 'LLONG_MAX' was not declared in this scope
   27 |   fill(d, d+n, LLONG_MAX);
      |                ^~~~~~~~~
a.cc:3:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <vector>
  +++ |+#include <climits>
    3 | using namespace std;
a.cc: In function 'int main()':
a.cc:50:14: error: 'LLONG_MAX' was not declared in this scope
   50 |   ll min_l = LLONG_MAX;
      |              ^~~~~~~~~
a.cc:50:14: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
Language: C++

#include <stdio.h>
2. 
3.using namespace std;
4. 
5.const int MAX_N = 100000;
6.int par[MAX_N + 1];
7.int rnk[MAX_N + 1];
8.int dis[MAX_N + 1];
9. 
10.int root(int x)
11.{
12.	if(par[x]==x)return x;
13.	return root(par[x]);
14.}
15. 
16.int find(int x)
17.{	
18.    
19.	if(x==root(x)) return 0;
20.	return dis[x]+find(par[x]);
21.}
22. 
23.int merge(int L,int R,int D)
24.{	
25.	int x = L,y = R;
26.	L = root(L);
27.	R = root(R);
28.	int L_d = find(x);
29.	int R_d = find(y);
30.	if(L==R){
31.		if(R_d-L_d==D) return 1;
32.		else return 0;
33.	}
34.	if(rnk[L]<rnk[R])
35.	{
36.		par[L] = R;
37.		dis[L] = R_d - D - L_d;
38.	}
39.	else {
40.		par[R] = L;
41.		dis[R] = L_d + D - R_d;
42.		if(rnk[L]==rnk[R])rnk[L]++;
43.	}
44.	return 1;
45.}
46. 
47.int main()
48.{
49.	int n,m,i;
50.	scanf("%d %d",&n,&m);
51.	
52.	for(i=1;i<=n;i++)par[i]=i;
53.	
54.	for(i=0;i<m;i++)
55.	{
56.		int L,R,D;
57.		scanf("%d %d %d",&L,&R,&D);
58.		if(!merge(L,R,D)){
59.			printf("No"); return 0;
60.		}
61.		
62.	}
63.	printf("Yes");
64.	return 0;
65.}


Compiler output:
a.cc:2:1: error: expected unqualified-id before numeric constant
    2 | 2.
      | ^~
a.cc:4:1: error: expected unqualified-id before numeric constant
    4 | 4.
      | ^~
a.cc:6:1: error: expected unqualified-id before numeric constant
    6 | 6.int par[MAX_N + 1];
      | ^~~~~
a.cc:7:1: error: expected unqualified-id before numeric constant
    7 | 7.int rnk[MAX_N + 1];
      | ^~~~~
a.cc:8:1: error: expected unqualified-id before numeric constant
    8 | 8.int dis[MAX_N + 1];
      | ^~~~~
a.cc:9:1: error: expected unqualified-id before numeric constant
    9 | 9.
      | ^~
a.cc:15:1: error: expected unqualified-id before numeric constant
   15 | 15.
      | ^~~
a.cc:22:1: error: expected unqualified-id before numeric constant
   22 | 22.
      | ^~~
a.cc:46:1: error: expected unqualified-id before numeric constant
   46 | 46.
      | ^~~
Language: C++

#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);
struct edge {int to,cost;};
vector<edge> G[100000];
int d[N],p[N];
int c;
int n,m;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()&&){
    u = q.front(); q.pop();
    for (int v=0;v<G[u].size();v++){
      if((p[G[u][v].to]!=INFTY)&&(p[G[u][v].to]!=p[u]+G[u][v].cost)){
        c=1;
        break;
      }
      p[G[u][v].to]=p[u]+G[u][v].cost;
      if(d[G[u][v].to]!= INFTY)continue;
      d[G[u][v].to]=d[u]+1;
      q.push(G[u][v].to);
    }
  }
}

int main(){

cin >> n >> m;

for(int i=0;i<m;i++){
  int l,r,d;
  cin >> l >> r >> d;
  G[l-1].push_back((edge){r-1,d});
  G[r-1].push_back((edge){l-1,-d});
}
for(int i=0;i<n;i++)d[i]=INFTY;
for(int j=0;j<n;j++)p[j]=INFTY;
for(int k=0;k<n;k++){
  if(d[k]==INFTY)bfs(k);
}
if(c==1){
  cout<<"No"<<endl;
}
else{
  cout<<"Yes"<<endl;
}
return 0;
}


Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:21:21: error: expected primary-expression before ')' token
   21 |   while(!q.empty()&&){
      |                     ^
Language: C++

#include<iostream>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);
int M[N][N];
int d[N];
int m;
int p[N];
int g[N];
int c;
int n;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    g[u]=1;
    for (int v=0;v<n;v++){
      if(M[u][v]==INFTY)continue;
      if((p[v]!=INFTY)&&(p[v]!=p[u]+M[u][v])){
        c=1;
      }
      p[v]=p[u]+M[u][v];
      if(d[v]!= INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int k=0;k<n;k++){
    if(g[k]==0)bfs(k);
  }
}

int main(){
  int u,k,v;
  c=0;
  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=INFTY;
  }

  cin >>m;
  for(int i=0;i<m;i++){
    cin >>u>>k>>v;
    u--;
    k--;
    M[u][k]=v;
    M[k][u]=(-v);
  }

  for(int i=0;i<n;i++)d[i]=INFTY;
  for(int j=0;j<n;j++)p[j]=INFTY;
  bfs(0);
  if(c==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}

Compiler output:
/tmp/cc49gQmb.o: in function `bfs(int)':
a.cc:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x65): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x119): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x130): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x166): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x1d5): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc49gQmb.o
a.cc:(.text+0x1f3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);

int M[N][N];
int d[N];
int m;
int p[N];
int g[N];
int c;
int n;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    g[u]=1;
    for (int v=0;v<n;v++){
      if(M[u][v]==INFTY)continue;
      if((p[v]!=INFTY)&&(p[v]!=p[u]+M[u][v])){
        c=1;
      }
      p[v]=p[u]+M[u][v];
      if(d[v]!= INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int k=0;k<n;k++){
    if(g[k]==0)bfs(k);
  }
}

int main(){
  int u,k,v;
  c=0;
  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=INFTY;
  }

  cin >>m;
  for(int i=0;i<m;i++){
    cin >>u>>k>>v;
    u--;
    k--;
    M[u][k]=v;
    M[k][u]=(-v);
  }

  for(int i=0;i<n;i++)d[i]=INFTY;
  for(int j=0;j<n;j++)p[j]=INFTY;
  bfs(0);
  if(c==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Compiler output:
/tmp/ccsiySFc.o: in function `bfs(int)':
a.cc:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x65): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x119): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x130): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x166): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x1d5): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccsiySFc.o
a.cc:(.text+0x1f3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);

int n;
int M[N][N];
int d[N];
int m;
int p[N];
int g[N];
int c;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    g[u]=1;
    for (int v=0;v<n;v++){
      if(M[u][v]==INFTY)continue;
      if((p[v]!=INFTY)&&(p[v]!=p[u]+M[u][v])){
        c=1;
      }
      p[v]=p[u]+M[u][v];
      if(d[v]!= INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int k=0;k<n;k++){
    if(g[k]==0)bfs(k);
  }
}

int main(){
  int u,k,v;
  c=0;

  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=INFTY;
  }

  cin >>m;
  for(int i=0;i<m;i++){
    cin >>u>>k>>v;
    u--;
    k--;
    M[u][k]=v;
    M[k][u]=(-v);
  }

  for(int i=0;i<n;i++)d[i]=INFTY;
  for(int j=0;j<n;j++)p[j]=INFTY;
  bfs(0);
  if(c==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Compiler output:
/tmp/ccmE3gt7.o: in function `bfs(int)':
a.cc:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x65): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x119): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x130): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x166): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x1d5): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccmE3gt7.o
a.cc:(.text+0x1f3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);

int n, M[N][N];
int d[N];
int m;
int p[N];
int g[N];
int c;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    g[u]=1;
    for (int v=0;v<n;v++){
      if(M[u][v]==INFTY)continue;
      if((p[v]!=INFTY)&&(p[v]!=p[u]+M[u][v])){
        c=1;
      }
      p[v]=p[u]+M[u][v];
      if(d[v]!= INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int k=0;k<n;k++){
    if(g[k]==0)bfs(k);
  }
}

int main(){
  int u,k,v;
  c=0;

  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=INFTY;
  }

  cin >>m;
  for(int i=0;i<m;i++){
    cin >>u>>k>>v;
    u--;
    k--;
    M[u][k]=v;
    M[k][u]=(-v);
  }

  for(int i=0;i<n;i++)d[i]=INFTY;
  for(int j=0;j<n;j++)p[j]=INFTY;
  bfs(0);
  if(c==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Compiler output:
/tmp/ccS8a8oJ.o: in function `bfs(int)':
a.cc:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x65): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x119): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x130): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x166): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x1d5): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccS8a8oJ.o
a.cc:(.text+0x1f3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<queue>

using namespace std;
static const int N = 100000;
static const int INFTY =(1<<21);

int n, M[N][N];
int d[N];
int m;
int p[N];
int g[N];
int c;

void bfs(int s){
  queue<int> q;
  q.push(s);
  d[s]=0;
  p[s]=0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    g[u]=1;
    for (int v=0;v<n;v++){
      if(M[u][v]==INFTY)continue;
      if((p[v]!=INFTY)&&(p[v]!=p[u]+M[u][v])){
        c=1;
      }
      p[v]=p[u]+M[u][v];
      if(d[v]!= INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int k=0;k<n;k++){
    if(g[k]==0)bfs(k);
  }
}

int main(){
  int u,k,v;
  c=0;

  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=INFTY;
  }

  cin >>m;
  for(int i=0;i<m;i++){
    cin >>u>>k>>v;
    u--;
    k--;
    M[u][k]=v;
    M[k][u]=(-v);
  }

  for(int i=0;i<n;i++)d[i]=INFTY;
  for(int j=0;j<n;j++)p[j]=INFTY;
  bfs(0);
  if(c==1){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Compiler output:
/tmp/ccJEBqFX.o: in function `bfs(int)':
a.cc:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x65): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x119): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x130): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x166): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x17e): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `p' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x1d5): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccJEBqFX.o
a.cc:(.text+0x1f3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status