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

#include<bits/stdc++.h>
using namespace std;

int n,m;
int tot=0;
int f[50005];
int head[50005],vis[50005],dis[50005];
struct pp
{
	int v,w,nxt;
}e[100005];
queue <int> q;

int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

void add(int u,int v,int w)
{
	e[tot].v=v;
	e[tot].w=w;
	e[tot].nxt=head[u];
	head[u]=tot++;
}

void in()
{
	memset(head,-1,sizeof(head));
	memset(vis,0,sizeof(vis));
	for(int i=0;i<=50004;++i)
	dis[i]=1234567898765;
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read(),w=read();
		add(u,v,w);
		add(v,u,-w);
	}
}

bool spfa(int s)
{
	q.push(s);
	dis[s]=0;
	vis[s]=true;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		
		for(int i=head[u];i!=-1;i=e[i].nxt)
		{
			int p=e[i].v;
			if(dis[p]==1234567898765)
			{
				dis[p]=dis[u]+e[i].w;
				f[p]=1;
				if(!vis[p])
				{
					q.push(p);
					//vis[p]=1;
				}
			}
			else if(dis[p]!=dis[u]+e[i].w)
			return false;
		}
		vis[u]=false;
	}
	return true;
}

void work()
{
	for(int i=1;i<=n;++i)
	{
		if(!f[i])
		{
			f[i]=1;bool flag=spfa(i);
			if(!flag)
			{
				printf("No");
				return ;
			}
		}
	}
	printf("Yes");
}

int main()
{
	in();
	work();
	return 0;
 } 

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

#include<bits/stdc++.h>
using namespace std;

int n,m;
int tot=0;
int f[50005];
int head[50005],vis[50005],dis[50005];
struct pp
{
	int v,w,nxt;
}e[100005];
queue <int> q;

int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

void add(int u,int v,int w)
{
	e[tot].v=v;
	e[tot].w=w;
	e[tot].nxt=head[u];
	head[u]=tot++;
}

void in()
{
	memset(head,-1,sizeof(head));
	memset(vis,0,sizeof(vis));
	memset(dis,0x7f,sizeof(dis));
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read(),w=read();
		add(u,v,w);
		add(v,u,-w);
	}
}

bool spfa(int s)
{
	q.push(s);
	dis[s]=0;
	vis[s]=1;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=head[u];i!=-1;i=e[i].nxt)
		{
			int p=e[i].v;
			if(dis[p]==2147483647)
			{
				dis[p]=dis[u]+e[i].w;
				f[p]=1;
				if(vis[p]==0)
				{
					q.push(p);
					vis[p]=1;
				}
			}
			else if(dis[p]!=dis[u]+e[i].w)
			return false;
		}
	}
	return true;
}

void work()
{
	for(int i=1;i<=n;++i)
	{
		if(f[i]==0)
		{
			f[i]=1;bool flag=spfa(i);
			if(flag==false)
			{
				printf("No");
				return ;
			}
		}
	}
	printf("Yes");
}

int main()
{
	in();
	work();
	return 0;
 } 

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

#include<bits/stdc++.h>
using namespace std;
int n, m, ERR;
int f[100010], val[100010];
int find(int x) {
	if(f[x] == x) return x;
	int px = f[x];
	f[x] = find(f[x]);
	val[x] += val(px);
	return f[x];
}
void merge(int x, int y, int d) {
	int px = find(x);
	int py = find(y);
	f[px] = f[py];
	val[x] = -val[x] + val[y] + d;
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++) f[i] = i;
	for(int i = 1; i <= m; i ++) {
		int x, y, d;
		scanf("%d%d%d", &x, &y, &d);
		int px = find(x), py = find(y);
		if(px == py && val[x] - val[y] != d) ERR = 1;
		else if(px != py) {
			f[px] = py;
			val[px] = -val[x] + val[y] + d;
		}
	}
	if(ERR) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Compiler output:
a.cc: In function 'int find(int)':
a.cc:9:22: error: 'val' cannot be used as a function
    9 |         val[x] += val(px);
      |                   ~~~^~~~
Language: C++

#include <bits/stdc++.h>

#define up(i,j,k) for (int i = (j); i <= (k); i++)
#define down(i,j,k) for (int i = (j); i >= (k); i--)
#define DEBUG printf("Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__)

#define lb long double
#define ll long long
#define ull unsigned long long

#define mp std::make_pair
#define pb push_back

#define all(x) (x).begin(), (x).end()
#define mem(a) memset((a), 0, sizeof(a))
#define File(x)                       \
    freopen("" #x ".in", "r", stdin); \
    freopen("" #x ".out", "w", stdout);

#define int long long

inline int read() {
    int data = 0, w = 1; char ch = 0;
    while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); }
    return data * w;
}

inline void print (int v) {
    if (v < 0) { putchar('-'); v = -v; }
    if (v > 9) print(v / 10);
    putchar(v % 10 + '0');
}

const int N = 100000 + 10;

int n, m;
int f[N], d[N];

int fi (int x) { return x == f[x] ? x : (f[x] = fi(f[x], d[x] += d[f[x]])); }

signed main () {
    n = read(); m = read();
    int l, r, fl, fr, x;
    up (i, 1, n) f[i] = i;
    up (i, 1, m) {
        l = read(); r = read(); x = read();
        fl = fi(l); fr = fi(r);
        if (fl == fr && d[l] - d[r] != x) { return puts("No"), 0; }
        if (fl ^ fr) {
            f[fl] = fr;
            d[fl] = x + f[r] - f[l];
        }
    }
    puts("Yes");
    return 0;
}

Compiler output:
a.cc: In function 'long long int fi(long long int)':
a.cc:41:51: error: too many arguments to function 'long long int fi(long long int)'
   41 | int fi (int x) { return x == f[x] ? x : (f[x] = fi(f[x], d[x] += d[f[x]])); }
      |                                                 ~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:41:5: note: declared here
   41 | int fi (int x) { return x == f[x] ? x : (f[x] = fi(f[x], d[x] += d[f[x]])); }
      |     ^~
Language: C++

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

ll n = 1e5+10,m = 2e5+10;
ll INF = INT_MAX;
vector<ll> place(n,INF);
// bool ok = true;
vector<vector<Pll>> graph(n);
// template<class T>
bool dfs(int now, int pre = -1){
    bool ok = true;
    // is_move[now] = 1;
    for(auto i : graph[now]){
        int to = i.first;
        ll dis = i.second;
        if(to == pre)continue;
        if(place[to] == INF){
            place[to] = place[now] + dis;
            ok &= dfs(to, now);
        }
        else{
            if(place[to] != place[now] + dis){
                ok = false;
                break;
            }
        }
    }
    return ok;
}

int main(){
    cin >> n >> m;
    // vector<ll> l(m), r(m), d(m);
    // vector<vector<Pll>> graph(n);
    set<ll> st;
    rep(i,m){
        ll l,r,d;cin >> l >> r >> d;
        l--;r--;
        st.insert(l);
        st.insert(r);
        graph[l].emplace_back(Pll(r,d));
        graph[r].emplace_back(Pll(l,-d));
    }
    bool res = true;

    // clock_t start = clock();

    for(auto i : st){
        // if(graph[i].size() == 0)continue;
        // print(i,is_move[i],place[i]);
        if(place[i] == INF){
            place[i] = 0;
            res &= dfs(i);
        }
        if(!ok)break;
    }

    // clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // printf("time %lf[ms]\n", time);
    cout << (res ? "Yes" : "No") << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:108:13: error: 'ok' was not declared in this scope
  108 |         if(!ok)break;
      |             ^~
Language: C++

#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<vector<pair<int,int>>> g(100000);
vector<int> dist(100000,-1);
vector<bool> visited(100000,false);


bool bfs(int i, int d){
  if(visited[i] && d != dist[i]) return false;
  if(visited[i] && d == dist[i]) return true;
  
  visited[i] = true;
  dist[i] = d;
  rep(j,g[i].size()){
    if(!bfs(g[i][j].first, d + g[i][j].second)) return false;
  }
  
  return true;a
}

int main(){
  int n,m; cin >> n >> m;
  rep(i,m){
    int l,r,d; cin >> l >> r >> d;
    l--; r--;
    g[l].push_back({r,d});
    g[r].push_back({l,-1*d});
  }
  
  rep(i,n){
    if(!visited[i]){
      if(!bfs(i,0)){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Compiler output:
a.cc: In function 'bool bfs(int, int)':
a.cc:24:15: error: 'a' was not declared in this scope
   24 |   return true;a
      |               ^
Language: C++

#include <cstdio>
#include <vector>
#include <stack>
#include <utility>

bool visit[100000];
int x[100000];
using pair = std::pair<int, long long>;
std::vector<edge> edges[200000];

struct edge
{
  int to;
  long long cost;
};

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
  {
    int l, r; long long d;
    scanf("%d%d%lld", &l, &r, &d);
    --l, --r;
    edges[l].emplace_back(edge{r, d});
    edges[r].emplace_back(edge{l, -d});
  }
  std::stack<pair> stack;
  for (int i = 0; i < n; ++i)
  {
    if (visit[i]) continue;
    visit[i] = true;
    stack.emplace(std::make_pair(i, 0));
    while (stack.size() > 0)
    {
      auto p = stack.top();
      stack.pop();
      for (auto e : edges[p.first])
      {
        if (visit[e.to])
        {
          if (x[e.to] != p.second + e.cost)
          {
            puts("No");
            return 0;
          }
        }
        else
        {
          visit[e.to] = true;
          x[e.to] = p.second + e.cost;
          stack.emplace(std::make_pair(e.to, p.second + e.cost));
        }
      }
    }
  }
  puts("Yes");
  return 0;
}


Compiler output:
a.cc:9:13: error: 'edge' was not declared in this scope
    9 | std::vector<edge> edges[200000];
      |             ^~~~
a.cc:9:17: error: template argument 1 is invalid
    9 | std::vector<edge> edges[200000];
      |                 ^
a.cc:9:17: error: template argument 2 is invalid
a.cc: In function 'int main()':
a.cc:26:14: error: request for member 'emplace_back' in 'edges[l]', which is of non-class type 'int'
   26 |     edges[l].emplace_back(edge{r, d});
      |              ^~~~~~~~~~~~
a.cc:27:14: error: request for member 'emplace_back' in 'edges[r]', which is of non-class type 'int'
   27 |     edges[r].emplace_back(edge{l, -d});
      |              ^~~~~~~~~~~~
a.cc:39:34: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   39 |       for (auto e : edges[p.first])
      |                                  ^
      |                                  std::begin
In file included from /usr/include/c++/14/vector:69,
                 from a.cc:2:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:39:34: error: 'end' was not declared in this scope; did you mean 'std::end'?
   39 |       for (auto e : edges[p.first])
      |                                  ^
      |                                  std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
Language: C++

#include<iostream>
using namespace std;
const int maxn = 1e7+5;
int pre[maxn],dis[maxn];
//int find(int x){
//	while(x!=pre[x]){
//		int r = pre[x];
//		pre[x] = pre[r];
//		dis[x] += dis[r];
//		x = r;
//	}
//	return x;
//}
int find(int x){
	if(x==pre[x]){
		return x;
	}
	int r = find(pre[x]);
	dis[x] += d[pre[x]];
	return pre[x] = r;
} 
bool merge(int x,int y,int d){
	int px = find(x);
	int py = find(y);
	if(px==py){
		return d==(dis[y]-dis[x]);
	}
	pre[py] = px ;
	dis[py] = dis[x]+d-dis[y];
	return true;
}
void init(){
	for(int i=0;i<maxn;i++){
		pre[i] = i;
	}
}
int main()
{
	init(); 
	int n,m,ans=1;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y,d;
		cin>>x>>y>>d;
		if(ans){
			ans = merge(x,y,d);
		}
	}

	if(ans){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl; 
	}
	return 0;
}

Compiler output:
a.cc: In function 'int find(int)':
a.cc:19:19: error: 'd' was not declared in this scope
   19 |         dis[x] += d[pre[x]];
      |                   ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

struct edge{
  int to,cost;
}

vector<edge> G[2000010];
bool vis[100010];
int d[100010];

bool dfs(int v,int dist){
  if(vis[v]){
    if(d[v] != dist){
        return true;
    }
    else{
        return false;
    }
  }
  vis[v] = true;
  d[v] = dist;
  for(int i=0;i<(int)G[v].size();i++){
    if(dfs(G[v][i].to,d[v]+G[v][i].cost)) return true;
  }
  return false;
}

int main(){
  int n,m;cin >> n >> m;
  for(int i=0;i<m;i++){
    int l,r,d;cin >> l >> r >> d;
    l--;r--;
    G[l].push_back(r,d);
    G[r].push_back(l,-d);
  }
  for(int i=0;i<n;i++){
    if(!vis[i]&&dfs(i,0)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Compiler output:
a.cc:8:14: error: invalid declarator before 'G'
    8 | vector<edge> G[2000010];
      |              ^
a.cc: In function 'bool dfs(int, int)':
a.cc:23:22: error: 'G' was not declared in this scope
   23 |   for(int i=0;i<(int)G[v].size();i++){
      |                      ^
a.cc: In function 'int main()':
a.cc:34:5: error: 'G' was not declared in this scope
   34 |     G[l].push_back(r,d);
      |     ^
Language: Java

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class ProblemD {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if (0 == m) {
				System.out.println("Yes");
				return;
			}
			int[][] g = new int[n][n];
			// 初期化
			IntStream.range(0, n).forEach(i -> {
				Arrays.fill(g[i], Integer.MAX_VALUE);
				g[i][i] = 0;
			});
			IntStream.range(0, m).forEach(i -> {
				int l = scanner.nextInt() - 1;
				int r = scanner.nextInt() - 1;
				int d = scanner.nextInt();
				g[l][r] = d;
				g[r][l] = -d;
			});
			System.out.println(checkDfs(g) ? "Yes" : "No");
		}
	}

	private static boolean checkDfs(final int[][] g) {
		for (int i = 0; i < g.length; i++) {
			for (int j = 0; j < g.length; j++) {
				if (i != j) {
					for (int k = 0; k < g.length; k++) {
						if ((g[i][k] != Integer.MAX_VALUE) && (g[k][j] != Integer.MAX_VALUE)) {
							if (g[i][j] == Integer.MAX_VALUE) {
								g[i][j] = g[i][k] + g[k][j];
							} else {
								if (g[i][j] != (g[i][k] + g[k][j])) {
									return false;
								}
							}
						}
					}
				}
			}
		}
		return true;
	}
}


Compiler output:
Main.java:8: error: class ProblemD is public, should be declared in a file named ProblemD.java
public class ProblemD {
       ^
1 error
Language: C++

// https://atcoder.jp/contests/abc087/tasks/arc090_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int INF = 1e9;

template <typename T> struct WeightedUnionFind {
    vector<int> data;
    vector<T> ws;

    WeightedUnionFind() {}

    WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {}

    int find(int k) {
        if (data[k] < 0)
            return k;
        auto par = find(data[k]);
        ws[k] += ws[data[k]];
        return data[k] = par;
    }

    T weight(int t) {
        find(t);
        return ws[t];
    }

    bool unite(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        x = find(x), y = find(y);
        if (x == y)
            return false;
        if (data[x] > data[y]) {
            swap(x, y);
            w *= -1;
        }
        data[x] += data[y];
        data[y] = x;
        ws[y] = w;
        return true;
    }

    T diff(int x, int y) { return weight(y) - weight(x); }
};

struct edge {
    int to, cost;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    WeightedUnionFind<int> T(n);
    while (m--) {
        int l, r, d;
        cin >> l >> r >> d;
        --l;
        --r;
        if (!T.unite(l, r, d)) {
            if (T.diff(l, r) != d) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    return 0;
}

return 0;
}

Compiler output:
a.cc:76:1: error: expected unqualified-id before 'return'
   76 | return 0;
      | ^~~~~~
a.cc:77:1: error: expected declaration before '}' token
   77 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N, M; cin >> N >> M;

  vector < vector< pair<int, ll> > > graph(N); 
  for (int i = 0; i < M; i++){
    int L, R; ll D; cin >> L >> R >> D;
    L--; R--;
    graph[L].push_back(make_pair(R, D));
    graph[R].push_back(make_pair(L, -1 * D));
  }
  
  vector <ll> ans(N);
  vector <bool> visited(N);

  queue <int> que;

  for (int i = 0; i < N; i++){
    if (graph[i].size() != 0){
      que.push(i);
      visited[i] = true;
      break;
    }
  }
  

  
  bool flag = true;
  ll m = 0, M = 0;
  while (!que.empty()){
    int start = que.front(); que.pop();

    for (int i = 0; i < graph[start].size(); i++){
      int next = graph[start][i].first;
      int dist = graph[start][i].second;

      if (visited[next] == false){
        visited[next] = true;
        que.push(next);
        ans[next] = ans[start] + dist;

        if (ans[next] < m){
          m = ans[next];
        }else if(M < ans[next]){
          M = ans[next];
        }
      }else{
        if (ans[next] != ans[start] + dist){
          flag = false;
        }
      }
    }
  }

  if (flag == true && M - m > 1e9){
    flag = false;
  }
  
  

  if (flag == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  


  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:44:13: error: conflicting declaration 'll M'
   44 |   ll m = 0, M = 0;
      |             ^
a.cc:18:10: note: previous declaration as 'int M'
   18 |   int N, M; cin >> N >> M;
      |          ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

vector<pair<int,int>> G[100'010];
bool used[100'010];
int pos[100'010];

bool dfs(int now){
  int next_;
  int cost;
  bool res = true;
  for(pair<int,int> p:G[now]){
    next_ = p.first;
    cost = p.second;
    if(used[next_]){
      if(pos[next]!=pos[now]+cost){
        return false;
      }else{
        continue;
      }
    }else{
      pos[next_] = pos[now] + cost;
      used[next_] = true;
      res = res && dfs(next_);
    }
  }
  return res;
}

int main(){
  
  int n,m;
  cin>>n>>m;
  int l,r,d;
  REP(i,m){
    cin>>l>>r>>d;
    l--;r--;
    G[l].push_back(make_pair(r,d));
    G[r].push_back(make_pair(l,-d));
  }
  
  bool flag;
  flag = dfs(0);
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}


Compiler output:
a.cc: In function 'bool dfs(int)':
a.cc:101:13: error: invalid types 'int [100010][<unresolved overloaded function type>]' for array subscript
  101 |       if(pos[next]!=pos[now]+cost){
      |             ^
Language: C++

#include<iostream>
using namespace std;
const int maxn=100005;
int n,m,fa[maxn],dis[maxn];
bool ok=true;
int find(int x)
{
    if(fa[x]!=x)
    {
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++)
    {
        int l,r,d;
        scin>>l>>r>>d;
        int ll=find(l),rr=find(r);
        if(ll==rr&&dis[l]-dis[r]!=d)
            ok=false;
        if(ll!=rr)
        {
            fa[ll]=rr;
            dis[ll]=d+dis[r]-dis[l];
        }
    }
    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:24:9: error: 'scin' was not declared in this scope
   24 |         scin>>l>>r>>d;
      |         ^~~~
Language: C++

#include<iostream>
int n,m,fa[100005],dis[100005];
bool ok=true;
int find(int x)
{
    if(fa[x]!=x)
    {
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++)
    {
        int l,r,d;
        scin>>l>>r>>d;
        int ll=find(l),rr=find(r);
        if(ll==rr&&dis[l]-dis[r]!=d)
            ok=false;
        if(ll!=rr)
        {
            fa[ll]=rr;
            dis[ll]=d+dis[r]-dis[l];
        }
    }
    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   16 |     cin>>n>>m;
      |     ^~~
      |     std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:22:9: error: 'scin' was not declared in this scope
   22 |         scin>>l>>r>>d;
      |         ^~~~
a.cc:33:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   33 |         cout<<"Yes"<<endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:33:22: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   33 |         cout<<"Yes"<<endl;
      |                      ^~~~
      |                      std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:35:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   35 |         cout<<"No"<<endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:35:21: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   35 |         cout<<"No"<<endl;
      |                     ^~~~
      |                     std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
const int maxn=1000000;
struct eg{
       int dot,w;
       };
eg E[maxn];
int head[maxn],next[maxn];
int d[maxn],ind[maxn];
int id=0,n,m;
void add(int x,int y,int z)
{
     E[++id].dot=y;
     E[id].w=x;
     next[id]=head[x];
     head[x]=id;
     ind[y]++;
}
int t=0;
void topo()
{
     memset(d,0x3f,sizeof(d));
     queue<int> Q;
     for(int i=1;i<=n;i++)
         if(!ind[i])d[i]=0,Q.push(i);
     if(!Q.size())
     {
         cout<<"No"<<endl;
         exit(0);
     }
     while(Q.size())
     {
          t++;
          int x=Q.front();
          Q.pop();
          for(int i=head[x];i;i=next[i])
          {
              int y=E[i].dot;
              if(d[y]>d[x]+E[i].w)
                 d[y]=d[x]+E[i].w;
              if(--ind[y]==0)
                 Q.push(y);
          }
     }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(z>n+1)
        {
           cout<<"No"<<endl;
           return 0;
        }
        add(x,y,z); 
    }
    topo();
    if(t<n)
    {
       cout<<"No"<<endl;
       return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}   

Compiler output:
a.cc: In function 'void add(int, int, int)':
a.cc:18:6: error: reference to 'next' is ambiguous
   18 |      next[id]=head[x];
      |      ^~~~
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:11:16: note:                 'int next [1000000]'
   11 | int head[maxn],next[maxn];
      |                ^~~~
a.cc: In function 'void topo()':
a.cc:39:33: error: reference to 'next' is ambiguous
   39 |           for(int i=head[x];i;i=next[i])
      |                                 ^~~~
/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:11:16: note:                 'int next [1000000]'
   11 | int head[maxn],next[maxn];
      |                ^~~~
Language: C++

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=1000000;
struct eg{
       int dot,w;
       };
eg E[maxn];
int head[maxn],next[maxn];
int d[maxn],ind[maxn];
int id=0,n,m;
void add(int x,int y,int z)
{
     E[++id].dot=y;
     E[id].w=x;
     next[id]=head[x];
     head[x]=id;
     ind[y]++;
}
int t=0;
void topo()
{
     memset(d,0x3f,sizeof(d));
     queue<int> Q;
     for(int i=1;i<=n;i++)
         if(!ind[i])d[i]=0,Q.push(i);
     if(!Q.size())
     {
         cout<<"No"<<endl;
         exit(0);
     }
     while(Q.size())
     {
          t++;
          int x=Q.front();
          Q.pop();
          for(int i=head[x];i;i=next[i])
          {
              int y=E[i].dot;
              if(d[y]>d[x]+E[i].w)
                 d[y]=d[x]+E[i].w;
              if(--ind[y]==0)
                 Q.push(y);
          }
     }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(z>n+1)
        {
           cout<<"No"<<endl;
           return 0;
        }
        add(x,y,z); 
    }
    topo();
    if(t<n)
    {
       cout<<"No"<<endl;
       return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}   

Compiler output:
a.cc: In function 'void add(int, int, int)':
a.cc:17:6: error: reference to 'next' is ambiguous
   17 |      next[id]=head[x];
      |      ^~~~
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:10:16: note:                 'int next [1000000]'
   10 | int head[maxn],next[maxn];
      |                ^~~~
a.cc: In function 'void topo()':
a.cc:38:33: error: reference to 'next' is ambiguous
   38 |           for(int i=head[x];i;i=next[i])
      |                                 ^~~~
/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:10:16: note:                 'int next [1000000]'
   10 | int head[maxn],next[maxn];
      |                ^~~~
Language: C++

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using ll = long long;
#define int ll
#define INF 100000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
using namespace std;
using pii = pair<int,int>;

vector<bool>used;
vector<vector<pii>>edge;
vector<int>d;
map<int,int>mp;
bool judge=true;

auto TopologicalSort(int n){
    vector<int>v(n,false);
    vector<int>out(n);
    int idx = n-1;
    function<void (int)>dfs = [&](int u) -> void{
        v[u] = true;
        for(int i = 0; i < edge[u].size();i++){
            int nv = edge[u][i].first;
            if(!v[nv])dfs(nv);
        }
        out[idx--] = u;
    };
    for(int i = 0; i < v.size();i++){
        if(!v[i])dfs(i);
    }
    return out;
}

void dfs(int v,int val){
    used[v]=true;
    rep(i,edge[v].size()){
        int next=edge[v][i].first;
        int cost=mp[edge[v][i].second];
        if(d[next]==INF){
            d[next]=val+cost;
            if(!used[next])dfs(next,d[next]);
        }else if(d[next]!=cost+val){
            judge=false;
        }
    }
}
signed main(){
    int n,m; cin>>n>>m;
    
    edge = vector<vector<pii>>(n);
    used = vector<bool>(n,false);
    d    = vector<int>(n,INF);
    rep(i,m){
        int a,b,c;cin>>a>>b>>c;
        --a,--b;
        int l = min(a,b);
        int r = max(a,b);
        edge[l].push_back(make_pair(r,i));
        mp[i] = c;
    }
    auto u = TopologicalSort((int)edge.size());
    
    rep(i,u.size())if(!used[u[i]])dfs(u[i],(d[u[i]] == INF ? 0 : d[u[i]]));
    
    cout << (judge ? "Yes" : "No") << endl;
}



Compiler output:
a.cc: In function 'auto TopologicalSort(ll)':
a.cc:25:5: error: 'function' was not declared in this scope
   25 |     function<void (int)>dfs = [&](int u) -> void{
      |     ^~~~~~~~
a.cc:5:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    4 | #include<algorithm>
  +++ |+#include <functional>
    5 | using ll = long long;
a.cc:25:14: error: expected primary-expression before 'void'
   25 |     function<void (int)>dfs = [&](int u) -> void{
      |              ^~~~
a.cc:34:18: error: 'dfs' was not declared in this scope
   34 |         if(!v[i])dfs(i);
      |                  ^~~
Language: C++

// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> P;

ll INF = 1000000000000;
 
ll N, M, L[200000], R[200000], D[200000];
vector< vector<P> > G(100001);
vector<ll> num(100001);
string ans;
 
void dfs(int now, int mae){    
 
    for(int i=0;i<G[now].size();i++){
        P nextP = G[now][i];
        int nextNode = nextP.first;
        int nextCost = nextP.second;
 
        if(num[nextNode] == INF){
            num[nextNode] = num[now] + nextCost;
            dfs(nextNode, now);
        } else {
            if(num[nextNode] != num[now] + nextCost)  ans = "No";
        }
        
    }
}
 
int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++)    cin >> L[i] >> R[i] >> D[i];
 
    for(int i=0;i<M;i++){
        G[ L[i] ].push_back( P(R[i], D[i]) );
        G[ R[i] ].push_back( P(L[i], -1 * D[i]) );
    }
    
    for(int i=1;i<=N;i++)   num[i] = INF;
 
    ans = "Yes";
    for(int i=1;i<=N;i++){
        if(vis[i]){
            num[i] = 0;
            dfs(i, 0);
        }
        if(ans == "No") break;
    }
 
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:12: error: 'vis' was not declared in this scope
   46 |         if(vis[i]){
      |            ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> P;

ll INF = 1000000000000;
 
ll N, M, L[200000], R[200000], D[200000];
vector< vector<P> > G(100001);
vector<ll> num(100001);
string ans;
 
void dfs(int now, int mae){    
 
    for(int i=0;i<G[now].size();i++){
        P nextP = G[now][i];
        int nextNode = nextP.first;
        int nextCost = nextP.second;
 
        if(num[nextNode] == INF){
            num[nextNode] = num[now] + nextCost;
            dfs(nextNode, now);
        } else {
            if(num[nextNode] != num[now] + nextCost)  ans = "No";
        }
        
    }
}
 
int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++)    cin >> L[i] >> R[i] >> D[i];
 
    for(int i=0;i<M;i++){
        G[ L[i] ].push_back( P(R[i], D[i]) );
        G[ R[i] ].push_back( P(L[i], -1 * D[i]) );
    }
    
    for(int i=1;i<=N;i++)   num[i] = INF;
 
    ans = "Yes";
    for(int i=1;i<=N;i++){
        if(vis[i]){
            num[i] = 0;
            dfs(i, 0);
        }
        if(ans == "No") break;
    }
 
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:12: error: 'vis' was not declared in this scope
   44 |         if(vis[i]){
      |            ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
// #define LLINF 1e18
#define int ll
using namespace std;
const int MOD = 1e9 +7;


struct WeightedUnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;

    WeightedUnionFind(int n){
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        rep(i,n){
            par[i]=i;
            rank[i]=0;
            diff_weight[i]=0;
        }
    }

    int find(int x){
        if(par[x]==x)
        return x;
        else{
            diff_weight[x] += diff_weight[par[x]];
            return par[x] =find(par[x]);
        }
    }
    int weight(int x) {
        find(x);
        return diff_weight[x];
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    void unite(int x, int y, int w) {
        w += weight(x); w -= weight(y);
        x = find(x); y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
    }

    bool same(int x,int y){
        return find(x) ==find(y);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    WeightedUnionFind uf(n);
    rep(i,m){
        int l,r,d;
        l--;r--;
        if(uf.same(l,r)){
            if(uf.diff(l,r) !=d){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else uf.unite(l,r,d);
    }
    cout<<"Yes"<<endl;
    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

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

int main()
{
  int N,M ;
  cin>>N>>M ;
  int L[M],R[M],D[M] ;
  int i ;
  for(i=0;i<M;i++) cin>>L[i]>>R[i]>>D[i] ;
  
  long long int x[N] ;
  for(i=0;i<N;i++) x[i]=-1 ;
  x[L[0]]=0 ;
  x[R[0]]=D[0] ;
  unsigned long int Max=pow(10,9) ;]
  int j=0 ;
  while(j<2){
  for(i=1;i<M;i++){
    if(x[R[i]]!=-1&&x[L[i]]!=-1){
      if(D[i]+x[L[i]]!=x[R[i]]){
        cout<<"No"<<endl ;
        return 0 ;
      }
    }else{
      x[R[i]]=D[i]+x[L[i]] ;
      if(x[R[i]]>Max){
        cout<<"No"<<endl ;
         return 0 ;
      }
    }
  }j++ ;
  }
  cout<<"Yes"<<endl ;
 
  return 0 ;
}






Compiler output:
a.cc: In function 'int main()':
a.cc:17:36: error: expected primary-expression before ']' token
   17 |   unsigned long int Max=pow(10,9) ;]
      |                                    ^
a.cc:19:9: error: 'j' was not declared in this scope
   19 |   while(j<2){
      |         ^
Language: C++

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

int main()
{
  int N,M ;
  cin>>N>>M ;
  int L[M],R[M],D[M] ;
  int i ;
  for(i=0;i<M;i++) cin>>L[i]>>R[i]>>D[i] ;
  
  long int x[N] ;
  for(i=0;i<N;i++) x[i]=-1 ;
  x[L[0]]=0 ;
  x[R[0]]=D[0] ;
  long int Max=pow(10,9) ;
  for(i=1;i<M;i++){
    if(R[i]!=-1){
      if(D[i]+x[L[i]]!=x[R[i]]){
        cout<<"No"<<endl ;
        return 0 ;
      }
    }else{
      x[R[i]]=D[i]+x[L[i]] ;
      if(x[R[i]]>Max){
        cout<<"No"<<endl ;
         return 0 ;
      }
  }
  cout<<"Yes"<<endl ;
 
  return 0 ;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:34:2: error: expected '}' at end of input
   34 | }
      |  ^
a.cc:6:1: note: to match this '{'
    6 | {
      | ^
Language: C++

#include<iostream>
using namespace std ;

int main()
{
  int N,M ;
  cin>>N>>M ;
  int L[M],R[M],D[M] ;
  int i ;
  for(i=0;i<M;i++) cin>>L[i]>>R[i]>>D[i] ;
  
  long int x[N] ;
  for(i=0;i<N;i++) x[i]=-1 ;
  x[L[0]]=0 ;
  x[R[0]]=D[0] ;
  long int Max=pow(10,9) ;
  for(i=1;i<M;i++){
    if(R[i]!=-1){
      if(D[i]+x[L[i]]!=x[R[i]]){
        cout<<"No"<<endl ;
        return 0 ;
      }
    }else{
      x[R[i]]=D[i]+x[L[i]] ;
      if(X[R[i]]>Max){
        cout<<"No"<<endl ;
         return 0 ;
      }
  }
  cout<<"Yes"<<endl ;
 
  return 0 ;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:16: error: 'pow' was not declared in this scope
   16 |   long int Max=pow(10,9) ;
      |                ^~~
a.cc:25:10: error: 'X' was not declared in this scope
   25 |       if(X[R[i]]>Max){
      |          ^
a.cc:33:2: error: expected '}' at end of input
   33 | }
      |  ^
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

const int mod=1000000007;

struct WUnion {
  vector< ll > data;
  vector< ll > diff_weight;
 
  WUnion(ll sz) {
    data.assign(sz, -1);
    diff_weight.assign(sz,0);
  }
 
  bool unite(ll x, ll y, ll w) {
    w+=weight(x);w-=weight(y);
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    diff_weight[y]=w;
    return (true);
  }
 
  ll find(ll k) {
    if(data[k] < 0) return (k);
    else{
        ll r=find(data[k]);
        diff_weight[k]+=diff_weight[data[k]];
        return (data[k] = find(data[k]));
    }
  }
 
  ll size(ll k) {
    return (-data[find(k)]);
  }
  ll weight(ll k){
      find(k);
      return diff_weight[k];
  }
  ll diff(ll x, ll y){
      return weight(y)-weight(x);
  }
};

ll main(){
    ll n,m;
    cin>>n>>m;
    WUnion uf(n);
    bool flag=1;
    rep(i,m){
        ll l,r,d;
        cin>>l>>r>>d;
        if(!uf.unite(l,r,d)){
            if(uf.diff(l,r)!=d){
                flag=0;
                break;
            }
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
}


Compiler output:
a.cc:55:1: error: '::main' must return 'int'
   55 | ll main(){
      | ^~
Language: C++

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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf[r] - uf[l];
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:26: error: no match for 'operator[]' (operand types are 'UnionFind<int>' and 'int')
   65 |             int diff = uf[r] - uf[l];
      |                          ^
a.cc:65:34: error: no match for 'operator[]' (operand types are 'UnionFind<int>' and 'int')
   65 |             int diff = uf[r] - uf[l];
      |                                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
    vector<int> size;//各グループの要素数uf.size[uf.find(1)]みたいな感じでfind経由忘れずに
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
            size[y]+=size[x];
        }else{
            par[y]=x;
            size[x]+=size[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};

struct edge{
  int to,cost;
};

vector<edge> g[100010];
int n,m;

void dfs(int st,int en,int& sum,vector<bool > vis){
  if(st==en || vis[st] || g[st].empty()){
    return ;
  }
  vis[st]=true;
  for(auto itr:g[st]){
    sum+=itr.cost;
    dfs(itr.to,en,sum,vis);
  }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    UnionFind uf(n+1);
    rep(i,m){
      int x,y,z;
      cin>>x>>y>>z;
      if(uf.same(x,y)){
        int sum=0;
        vector<bool> vis(n+10,false)
        dfs(x,y,sum,vis);
        //cout<<sum<<'\n';
        if(sum!=z){
          cout<<"No"<<endl;
          return 0;
        }
      }else{
        uf.unite(x,y);
        g[x].push_back({y,z});
      }
    }
    cout<<"Yes"<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:9: error: expected ',' or ';' before 'dfs'
   93 |         dfs(x,y,sum,vis);
      |         ^~~