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

/*input
4 3
1 2 6
3 4 5
2 3 7
*/
import java.util.Scanner;
import java.lang.*;
import java.util.Arrays;
import java.util.function.BinaryOperator;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;


public class Graph {
	private static final int N = (int)1e5 + 100;
	private static final long oo = (long) 1e18;
	public static class Pair {
		public int v;
		public long s;
		Pair(int v, long s) {
			this.v = v;
			this.s = s;
		}
	}

	private static long n, m, flag = 0;
	private static long[] a = new long[N];
	private static long[] step = new long[N];
	private static long[] res = new long[N];
	private static boolean[] visit = new boolean[N];

	public static ArrayList<ArrayList<Pair> > vi = new ArrayList< ArrayList <Pair> >();

	static void run() { System.out.print("0"); System.exit(0); }
	static void done() { System.out.print("1"); System.exit(0); }
	static boolean check(long x) {
		res[1] = x;
		for(int i = 1; i <= n; ++i) {
			if(step[i] % 2 == 0) {
				res[i] = a[i] + x;
			} else res[i] = a[i] - x;
		}
		for(int i = 1; i <= n; ++i) {
			for(Pair cur: vi.get(i))	{
				if(cur.s != (res[i] + res[cur.v])) return false;
			}
		}
		return true;
	}

	static void dfs(int u) {
		visit[u] = true;
		for(Pair cur: vi.get(u)) {
			if(!visit[cur.v]) {
				step[cur.v] = 1 - step[u];
				a[cur.v] = cur.s - a[u];
				dfs(cur.v);
			}
		}
	}

	public static void main(String[] args) {
		Scanner inp = new Scanner(System.in);

		n = inp.nextLong();
		m = inp.nextLong();
		
		for(int i = 1; i <= n + 1; ++i) {
			visit[i] = false;
			vi.add(new ArrayList<Pair>());
		}
		for(int i = 1; i <= m; ++i) {
			int u, v, s;
			u = inp.nextInt();
			v = inp.nextInt();
			s = inp.nextInt();
			vi.get(u).add(new Pair(v, s));
			vi.get(v).add(new Pair(u, s));
		} 
		step[1] = a[1] = 0;

		dfs(1);

		long minn = 1, maxn = oo;

		//for(int i = 1; i <= n; ++i) System.out.println(a[i] + " " + step[i]);

		for(int i = 1; i <= n; ++i ) {
			for(Pair cur: vi.get(i)) {
				if(1 - step[i] == step[cur.v]) {
					if(a[cur.v] != cur.s - a[i]) done();
				} else {
					long tmp = cur.s - a[i];
					if(step[i] % 2 == 0) {
						if(check((tmp - a[cur.v]) / 2)) done();
						else {
							//System.out.print(i + " ");
							//System.out.println(cur.v);
							run();
						}
					} else {
						if(check((a[cur.v] - tmp) / 2)) done();
						else {
							//System.out.print(i + " ");
							//System.out.println(cur.v);
							run();
						}	
					}
				}
			}
			if(step[i] == 0) minn = Math.max(minn, 1 - a[i]);
			else maxn = Math.min(maxn, a[i] - 1);
		}
			
		minn = Math.max(minn, 1);
		System.out.print(Math.max(maxn - minn + 1, 0L));
	}
}

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct edge { ll to, d; };
vector<vector<edge>> adj;
vector<vector<ll>> result;

void dfs(ll n=0, ll p=-1, ll mode=0) {
  for (auto x: adj[n]) {
    if (result[x.to][1-mode]!=LLINF) continue;
    result[x.to][1-mode] = x.d - result[n][mode];
    dfs(x.to,n,1-mode);
  }
}

int main() {
  int n, m; cin >> n >> m;
  adj.resize(n);
  rep(i,m) {
    ll u, v, s; cin >> u >> v >> s; u--; v--;
    adj[u].push_back({v,s});
    adj[v].push_back({u,s});
  }

  result.resize(n,vector<ll>(2,LLINF));
  result[0][0] = 1;
  dfs();
  // rep(i,n) cout << result[i][0] << " " << result[i][1] << endl;

  if (result[0][1]!=LLINF) {
    ll diff = result[0][0]-result[0][1];
    ll sum2 = result[0][0]+result[0][1];
    if (diff%2!=0||sum<=0) cout << 0 << endl;
    else {
      bool ok = true;
      rep(i,n) {
        ll diff2 = result[i][0]-result[i][1];
        ll sum2 = result[i][0]+result[i][1];
        if (diff2!=diff||sum2<=0) ok = false;
      }
      ll result = ok ? 1 : 0;
      cout << result << endl;
    }
  }
  else {
    ll ma = LLINF, mi = 1;
    bool ok = true;
    rep(i,n) {
      if (result[i][0]!=LLINF) mi = max(mi,max((ll)0,-1*result[i][0]));
      else {
        if (result[i][1]<=0) { ok = false; break; }
        ma = min(ma,result[i][1]);
      }
    }
    if (!ok) cout << 1 << endl;
    else {
      ll result = max((ll)0,ma-mi+1);
      cout << result << endl;
      // cout << mi << "~" << ma << endl;
    }
  }
  // cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:54:20: error: 'sum' was not declared in this scope; did you mean 'sum2'?
   54 |     if (diff%2!=0||sum<=0) cout << 0 << endl;
      |                    ^~~
      |                    sum2
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1e5 + 8;
const int INF = 1e17 + 239;

int used[N];
int val[N];
int h[N];
vector<pair<int, int>> g[N];

int fl = 0;
set<int> ss;

void dfs(int cur, int cs, int ch) {
	val[cur] = cs;
	h[cur] = ch;
	used[cur] = 1;
	for (auto t : g[cur]) {
		if (!used[t.first]) {
			dfs(t.first, t.second - val[cur], ch + 1);
		} else {
			if ((h[cur]) % 2 == h[t.first] % 2) {
				int rv = t.second - (val[cur] + val[t.first]);
				if (h[cur] % 2) rv *= -1;
				ss.insert(rv);
			} else {
				fl |= (val[cur] + val[t.first] != t.second);
			}
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	while (m--) {
		int u, v, s;
		cin >> u >> v >> s;
		u--;
		v--;
		s -= 2;
		g[u].push_back({v, s});
		g[v].push_back({u, s});
	}
	dfs(0, 0, 0);
	if (fl) {
		cout << 0 << endl;
		return 0;
	}
	if (!ss.empty()) {
		if ((int)ss.size() == 1) {
			for (int i = 0; i < n; i++) {
				if (h[i] % 2 == 0) val[i] += *ss.begin();
				else val[i] -= *ss.begin();
			}
			for (int i = 0; i < n; i++) {
				ok &= (val[i] >= 0);
			}
			// cout << ok << endl;
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
		return 0;
	} 
	//-mn0 
	//mn1
	int mn0 = INF;
	int mn1 = INF;
	for (int i = 0; i < n; i++) {
		if (h[i] % 2 == 0) mn0 = min(mn0, val[i]);
		else mn1 = min(mn1, val[i]);
	}
	mn0 *= -1;
	// cerr << mn0 << ' ' << mn1 << endl;
	if (mn0 <= mn1) {
		cout << mn1 - mn0 + 1 << endl;
	} else {
		cout << 0 << endl;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:85:33: error: 'ok' was not declared in this scope
   85 |                                 ok &= (val[i] >= 0);
      |                                 ^~
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
const long long INF = 1LL << 60;    // 1.15x10^18

int main() {
    int n, m; cin >> n >> m;
    Graph g(n);
    while (m--) {
        int u, v, w; cin >> u >> v >> w; u--, v--;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    vector<bool> seen(n);
    vector<long long> a(n), b(n);
    a[0] = 1, b[0] = 0;
    auto dfs = [&](auto dfs, int u) {
        seen[u] = true;
        for (auto &p: g[u]) if (!seen[p.first]) {
            a[p.first] = -a[v];
            b[p.first] = p.second - b[u];
            dfs(dfs, v);
        }
    }
    dfs(dfs, 0);
    long long lb = 1LL, r = INF, x = -1;
    for (int u = 0; u < n; u++) {
        if (a[u] ==  1) lb = max(lb, 1 - b[u]);
        if (a[u] == -1) ub = min(ub, b[u - 1]);
        for (auto &p: g[u]) {
            int v = p.first; long long w = p.second;
            long long num = a[u] + a[v];
            long long den = b[u] + b[v];
            if (num == 0) {
                if (den != w) return !(cout << 0 << endl);
            } else {
                if ((w - den) % 2) return !(cout << 0 << endl);
                long long x0 = (s - den) / num;
                if (x0 <= 0) return !(cout << 0 << endl);
                if (x == -1) x = x0;
                if (x != x0) return !(cout << 0 << endl);
            }
        }
    }
    if (x == -1) cout << max(0LL, ub - lb + 1) << endl;
    else cout << (lb <= x && x <= ub) << endl;
    return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:23:29: error: 'v' was not declared in this scope
   23 |             a[p.first] = -a[v];
      |                             ^
a.cc: In function 'int main()':
a.cc:28:5: error: expected ',' or ';' before 'dfs'
   28 |     dfs(dfs, 0);
      |     ^~~
a.cc:32:25: error: 'ub' was not declared in this scope; did you mean 'u'?
   32 |         if (a[u] == -1) ub = min(ub, b[u - 1]);
      |                         ^~
      |                         u
a.cc:41:33: error: 's' was not declared in this scope
   41 |                 long long x0 = (s - den) / num;
      |                                 ^
a.cc:48:35: error: 'ub' was not declared in this scope; did you mean 'lb'?
   48 |     if (x == -1) cout << max(0LL, ub - lb + 1) << endl;
      |                                   ^~
      |                                   lb
a.cc:49:35: error: 'ub' was not declared in this scope; did you mean 'lb'?
   49 |     else cout << (lb <= x && x <= ub) << endl;
      |                                   ^~
      |                                   lb
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define int ll
vector<P> node[100005];
ll num[100005]={0},two_j[100005]={0};
bool used[100005]={false};
void dfs(ll pos,ll k){
  two_j[pos]=k;
  k%=2; k++;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first;
    if(two_j[to]==0){
      two_j[to]=k;
      dfs(to,k);
    }
  }
}
void set_val(ll pos,ll val){
  num[pos]=val;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first,cos=node[pos][i].second;
    if(!used[to]){
      used[to]=true;
      set_val(to,cos-val);
    }
  }
}
signed main(){
  ll n,m; cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b,c; cin>>a>>b>>c;
    node[a].push_back(P(b,c));
    node[b].push_back(P(a,c));
  }
  dfs(1,1);
  for(int i=1;i<=n;i++) used[i]=false;
  used[1]=true;
  set_val(1,0);

  bool f=false;
  for(int i=1;i<=n;i++){
    for(int j=0;j<node[i].size();j++){
      ll to=node[i][j].first;
      if(two_j[i]==two_j[to]) f=true;
    }
  }
  if(f){
    while(1) node[0]++;
    for(int i=1;i<=n;i++){
      for(int j=0;j<node[i].size();j++){
        ll to=node[i][j].first,cos=node[i][j].second;
        if(num[i]+num[to]!=cos){
          ll sa=cos-num[i]-num[to];
          sa/=2;
          for(int i=1;i<=n;i++){
            num[i]+=sa;
            if(num[i]<=0){
              cout<<0<<endl;
              return 0;
            }
          }
          cout<<1<<endl;
          return 0;
        }
      }
    }
  }
  else{
    ll one_m=174417441744174417,two_m=174417441744174417;
    for(int i=1;i<=n;i++){
      if(two_j[i]==1) one_m=min(one_m,num[i]);
      else two_m=min(two_m,num[i]);
    }
    cout<<max((ll)0,(one_m+two_m-1))<<endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:21: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
   52 |     while(1) node[0]++;
      |              ~~~~~~~^~
Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

bool rec(vector<vector<pair<int,int>>>&e,vector<array<ll,2>>&v,vector<array<bool,2>>&vis,int i=0,bool f=0){
    for(auto&p:e[i]){
        ll a=p.second-v[i][f];
        if(vis[p.first][!f]){
            if(v[p.first][!f]!=a) return true;
        }
        else{
            vis[p.first][!f]=true;
            v[p.first][!f]=a;
            if(rec(e,v,vis,p.first,!f)) return true;
        }
    }
    return false;
}

class EGraph {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,m,a,b,s;
        in>>n>>m;
        vector<vector<pair<int,int>>> e(n);
        fr(i,m){
            in>>a>>b>>s;--a,--b;
            e[a].emplace_back(b,s);
            e[b].emplace_back(a,s);
        }
        vector<array<ll,2>> v(n);
        vector<array<bool,2>> vis(n);
        vis[0][0]=true;
        v[0][0]=0;
        if(rec(e,v,vis)){
            out<<0<<endl;
            return;
        }
        if(vis[0][1]){
            if(v[0][1]&1){
                out<<0<<endl;
                return;
            }
            static_assert(false,"RE");
            fr(i,n){
                ll A=v[0][1]/2;
                fr(j,n){
                    if(A+v[0][0]<=0){
                        out<<0<<endl;
                        return;
                    }
                }
                fr(j,n){
                    if(v[0][1]-A<=0){
                        out<<0<<endl;
                        return;
                    }
                }
                out<<1<<endl;
                return;

            }
        }
        ll p=LLONG_MAX,q=LLONG_MAX;
        fr(i,n){
            if(vis[i][0]) p=min(p,v[i][0]);
            else q=min(q,v[i][1]);
        }
        out<<max(0ll,p+q-1)<<endl;
    }
};

int main() {
    EGraph solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Compiler output:
a.cc: In member function 'void EGraph::solve(std::istream&, std::ostream&)':
a.cc:56:27: error: static assertion failed: RE
   56 |             static_assert(false,"RE");
      |                           ^~~~~
Language: C++

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
const int INF = (int)1e9;
vector<pii> G[MAXN];
int s1[MAXN], s2[MAXN], tmpx[MAXN];
bool visit[MAXN];
int cur_x = 0;

bool dfs(int cur, int par) {
     visit[cur] = 1;
     bool OK = true;
     for (auto i : G[cur]) {
         int to = i.first;
         if (to != par) {
            if (visit[to]) {
               int tmp_cs = s2[to] - (i.second - s2[cur]);
               int tmp_coe = (s1[cur] * -1) - s1[to];
               if (tmp_coe == 0) cur_x = 0;
               else cur_x = tmp_cs / tmp_coe;
               OK = false;
            } else {
               s1[to] = s1[cur] * -1;
               s2[to] = i.second - s2[cur];
               if (!dfs(to, cur)) OK = false;
            }
         }
     }
     //printf("cur = %d s1 = %d s2 = %d\n", cur, s1[cur], s2[cur]);
     return OK;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int x, y, c;
        scanf("%d %d %d", &x, &y, &c);
        G[x].push_back(make_pair(y, c));
        G[y].push_back(make_pair(x, c));
    }
    s1[1] = 1;
    if (!dfs(1, 1)) {
       assert(1 == 0);
       for (int i = 1; i <= n; i++) tmpx[i] = s1[i] * cur_x + s2[i];
       bool ans = (cur_x > 0 ? true : false);
       for (int i = 1; i <= n; i++) {
           for (auto j : G[i]) {
               int to = j.first;
               if (tmpx[to] + tmpx[i] != j.second) ans = false;
           }
       }
       puts(ans ? "1" : "0");
    } else {
       int up = INF, low = 1;
       for (int i = 1; i <= n; i++) {
           if (s1[i] < 0) up = min(up, s2[i] - 1);
           else low = max(low, -1 * s2[i] + 1);
       }
       if (low > up) printf("0\n");
       else printf("%d\n", up - low + 1);
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:59:8: error: 'assert' was not declared in this scope
   59 |        assert(1 == 0);
      |        ^~~~~~
a.cc:13:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   12 | #include <cmath>
  +++ |+#include <cassert>
   13 | #include <deque>
Language: C++

#include<bits/stdc++.h>

using namespace std;

#define X   first
#define Y   second

const int   N   = 1e5 + 1;
const int   inf = 1e9 + 7;

typedef pair<int,int>   ii;
typedef pair<int,ii>    pii;

vector<int> g[N];
vector<pii> E;

int n, m;
int h[N], c[N];
ii  b[N];

bool dfs(int u) {
    for(int i : g[u])   {
        int v = (E[i].Y.X == u ? E[i].Y.Y : E[i].Y.X);
        if(h[v])    {
            if(!((h[u] + h[v]) & 1))    {
                int sum = E[i].X;
                int sub = (h[u] & 1) ? c[v] - c[u] : c[u] - c[v];
                if(sum <= sub || (sum + sub) & 1)   {
                    cout << "0";
                    exit(0);
                }
                b[u] = ii((sum + sub) / 2,(sum + sub) / 2);
                return 1;
            }
            continue;
        }
        h[v] = h[u] + 1;
        if(h[v] & 1)    c[v] = c[u] - E[i].X;
        else            c[v] = c[u] + E[i].X;
        if(dfs(v))  return 1;
    }
    return 0;
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for(int i = 1 ; i <= n ; ++i)
        b[i] = ii(1,inf);

    while(m--)  {
        int x, y, s;    cin >> x >> y >> s;
        g[x].push_back(E.size());
        g[y].push_back(E.size());
        E.push_back(pii(s,ii(x,y)));
        b[i].Y = min(b[i].Y,s - 1);
    }

    h[1] = 1;   dfs(1);

    queue<int>  q;  q.push(1);
    while(q.size()) {
        int u = q.front();  q.pop();
        for(int i : g[u])   {
            int v = E[i].Y.X == u ? E[i].Y.Y : E[i].Y.X;
            ii  boun = ii(max(E[i].X - b[u].Y,b[v].X),min(E[i].X - b[u].X,b[v].Y));
            if(boun.X > boun.Y) return 0 * puts("0");
            if(boun == b[v])    continue;
            b[v] = boun;
            q.push(v);
        }
    }

    memset(c,0,sizeof c);

    for(int i = 1 ; i <= n ; ++i)
        if(b[i].Y < inf)   {
            q.push(i);
            c[i] = b[i].X;
            break;
        }

    while(q.size()) {
        int u = q.front();  q.pop();
        for(int i : g[u])   {
            int v = E[i].Y.X == u ? E[i].Y.Y : E[i].Y.X;
            if(!c[v])   {
                c[v] = E[i].X - c[u];
                q.push(v);  continue;
            }
            if(c[v] + c[u] != E[i].X)
                return 0 * puts("0");
        }
    }

    for(int i = 1 ; i <= n ; ++i)
        if(b[i].Y < inf)
            return cout << b[i].Y - b[i].X + 1,0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:11: error: 'i' was not declared in this scope
   59 |         b[i].Y = min(b[i].Y,s - 1);
      |           ^
Language: Java

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 0x3f3f3f3f
using namespace std;
int n,m;
int first[Max * 2],next[Max * 2],u[Max * 2],v[Max * 2],s[Max * 2],vis[2][Max],num[Max];
int flag,l,r = inf;
void dfs(int from,int tag,int va) {
    if(flag)return;
    int k = first[from];
    while(k != -1) {
        if(flag)return;
        int vtag = (tag == 1);
        int to = v[k];
        int lva = s[k] - va;
        if(vis[vtag][to] != inf) {
            if(vis[vtag][to] == lva) {
                k = next[k];
                continue;
            }
            else {
                flag = 1;
                return;
            }
        }
        vis[vtag][to] = lva;
        if(vtag)r = min(r,lva);
        else l = max(l,-lva);///
        dfs(to,-tag,lva);
        k = next[k];
    }
}
int main() {
    scanf("%d%d",&n,&m);
    memset(first,-1,sizeof(first));
    memset(vis,inf,sizeof(vis));
    for(int i = 0;i < m;i ++) {
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
        num[u[i]] ++;
        num[v[i]] ++;
        u[i + m] = v[i];
        v[i + m] = u[i];
        s[i + m] = s[i];
        next[i] = first[u[i]];
        first[u[i]] = i;
        next[i + m] = first[u[i + m]];
        first[u[i + m]] = i + m;
    }
    dfs(1,1,0);
    if(flag)printf("0");
    else
    {
        printf("%d",r - l - 1);
    }
    return 0;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include<iostream>
^
Main.java:2: error: illegal character: '#'
#include<cstdio>
^
Main.java:3: error: illegal character: '#'
#include<cstdlib>
^
Main.java:4: error: illegal character: '#'
#include<cstring>
^
Main.java:5: error: illegal character: '#'
#include<algorithm>
^
Main.java:6: error: illegal character: '#'
#define Max 100001
^
Main.java:7: error: illegal character: '#'
#define inf 0x3f3f3f3f
^
Main.java:9: error: class, interface, enum, or record expected
int n,m;
^
Main.java:10: error: class, interface, enum, or record expected
int first[Max * 2],next[Max * 2],u[Max * 2],v[Max * 2],s[Max * 2],vis[2][Max],num[Max];
^
Main.java:11: error: class, interface, enum, or record expected
int flag,l,r = inf;
^
Main.java:12: error: unnamed classes are a preview feature and are disabled by default.
void dfs(int from,int tag,int va) {
^
  (use --enable-preview to enable unnamed classes)
Main.java:38: error: illegal start of expression
    scanf("%d%d",&n,&m);
                 ^
Main.java:38: error: illegal start of expression
    scanf("%d%d",&n,&m);
                    ^
Main.java:42: error: illegal start of expression
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
                       ^
Main.java:42: error: illegal start of expression
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
                             ^
Main.java:42: error: illegal start of expression
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
                                   ^
16 errors
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
typedef long long ll;

ll N,M;
struct edge {
  ll to,c;
  edge(){}
  edge(ll to,ll c):to(to),c(c){}
};

vector<edge> G[100001];
bool F[100001][2];
ll S[100001][2];

bool dfs(ll v, ll f){
  F[v][f] = true;
  for(edge e : G[v]) {
    if( F[e.to][1-f] ) {
      if (S[e.to][1-f] != e.c - S[v][f]) return false;
    } else {
      S[e.to][1-f] = e.c - S[v][f];
      if( !dfs(e.to, 1-f) ) return false;
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  for(ll i=0;i<M;i++){
    ll a,b,c;
     cin >> a >> b >> c; --a; --b;
    G[a].emplace_back( b,c);
    G[b].emplace_back( a,c);
  }

  if( !dfs(0,0) ) {
    cout << 0 << endl;
    return;
  }

  ll mini1 = LLONG_MAX, mini2 = LLONG_MAX;
  ll cnt = 0;
  for(ll i=0;i<N;i++){
    if( F[i][0] ) {
      mini1 = min( mini1, S[i][0] );
      cnt++;
    }
    if( F[i][1] ) {
      mini2 = min( mini2, S[i][1] );
      cnt++;
    }
  }


  assert( cnt == 2 * N || cnt == N );
  if( cnt == 2 * N ) {
    cout << 1 << endl;
  } else {
    if( mini1 > mini2 )
      swap(mini1,mini2);
    mini1--;
    mini2 += mini1;
    cout << max(0LL,mini2) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
   46 |     return;
      |     ^~~~~~
a.cc:49:14: error: 'LLONG_MAX' was not declared in this scope
   49 |   ll mini1 = LLONG_MAX, mini2 = LLONG_MAX;
      |              ^~~~~~~~~
a.cc:8:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include<vector>
  +++ |+#include <climits>
    8 | using namespace std;
a.cc:57:7: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   57 |       mini2 = min( mini2, S[i][1] );
      |       ^~~~~
      |       mini1
a.cc:67:17: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   67 |     if( mini1 > mini2 )
      |                 ^~~~~
      |                 mini1
a.cc:70:5: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   70 |     mini2 += mini1;
      |     ^~~~~
      |     mini1
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;

ll N,M;
struct edge {
  ll to,c;
  edge(){}
  edge(ll to,ll c):to(to),c(c){}
};

vector<edge> G[100001];
bool F[100001][2];
ll S[100001][2];

bool dfs(ll v, ll f){
  F[v][f] = true;
  for(edge e : G[v]) {
    if( F[e.to][1-f] ) {
      if (S[e.to][1-f] != e.c - S[v][f]) return false;
    } else {
      S[e.to][1-f] = e.c - S[v][f];
      if( !dfs(e.to, 1-f) ) return false;
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  for(ll i=0;i<M;i++){
    ll a,b,c;
     cin >> a >> b >> c; --a; --b;
    G[a].emplace_back( b,c);
    G[b].emplace_back( a,c);
  }

  if( !dfs(0,0) ) {
    cout << 0 << endl;
  }

  ll mini1 = LLONG_MAX, mini2 = LLONG_MAX;
  ll cnt = 0;
  for(ll i=0;i<N;i++){
    if( F[i][0] ) {
      mini1 = min( mini1, S[i][0] );
      cnt++;
    }
    if( F[i][1] ) {
      mini2 = min( mini2, S[i][1] );
      cnt++;
    }
  }


  assert( cnt == 2 * N || cnt == N );
  if( cnt == 2 * N ) {
    cout << 1 << endl;
  } else {
    if( mini1 > mini2 )
      swap(mini1,mini2);
    mini1--;
    mini2 += mini1;
    cout << max(0LL,mini2) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:14: error: 'LLONG_MAX' was not declared in this scope
   47 |   ll mini1 = LLONG_MAX, mini2 = LLONG_MAX;
      |              ^~~~~~~~~
a.cc:7:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    6 | #include<vector>
  +++ |+#include <climits>
    7 | using namespace std;
a.cc:55:7: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   55 |       mini2 = min( mini2, S[i][1] );
      |       ^~~~~
      |       mini1
a.cc:61:3: error: 'assert' was not declared in this scope
   61 |   assert( cnt == 2 * N || cnt == N );
      |   ^~~~~~
a.cc:7:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    6 | #include<vector>
  +++ |+#include <cassert>
    7 | using namespace std;
a.cc:65:17: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   65 |     if( mini1 > mini2 )
      |                 ^~~~~
      |                 mini1
a.cc:68:5: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   68 |     mini2 += mini1;
      |     ^~~~~
      |     mini1
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;

ll N,M;
struct edge {
  ll to,c;
  edge(){}
  edge(ll to,ll c):to(to),c(c){}
};
vector<edge> G[100001];
bool F[100001][2];
ll S[100001][2];

bool dfs(ll v, ll f){
  F[v][f] = true;
  for(edge e : G[v]) {
    if( F[e.to][1-f] ) {
      if (S[e.to][1-f] != e.c - S[v][f]) return false;
    } else {
      S[e.to][1-f] = e.c - S[v][f];
      if( !dfs(e.to, 1-f) ) return false;
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  for(ll i=0;i<M;i++){
    ll a,b,c;
     cin >> a >> b >> c; --a; --b;
    G[a].emplace_back( b,c);
    G[b].emplace_back( a,c);
  }

  if( !dfs(0,0) ) {
    cout << 0 << endl;
  }

  ll mini1 = INT_MAX, mini2 = INT_MAX;
  ll cnt = 0;
  for(ll i=0;i<N;i++){
    if( F[i][0] ) {
      mini1 = min( mini1, S[i][0] );
      cnt++;
    }
    if( F[i][1] ) {
      mini2 = min( mini2, S[i][1] );
      cnt++;
    }
  }
  

  if( cnt == 2 * N ) {
    cout << 1 << endl;
  } else {
    if( mini1 > mini2 )
      swap(mini1,mini2);
    mini1--;
    mini2 += mini1;
    cout << max(0LL,mini2) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:14: error: 'INT_MAX' was not declared in this scope
   46 |   ll mini1 = INT_MAX, mini2 = INT_MAX;
      |              ^~~~~~~
a.cc:7:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    6 | #include<vector>
  +++ |+#include <climits>
    7 | using namespace std;
a.cc:54:7: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   54 |       mini2 = min( mini2, S[i][1] );
      |       ^~~~~
      |       mini1
a.cc:63:17: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   63 |     if( mini1 > mini2 )
      |                 ^~~~~
      |                 mini1
a.cc:66:5: error: 'mini2' was not declared in this scope; did you mean 'mini1'?
   66 |     mini2 += mini1;
      |     ^~~~~
      |     mini1
Language: C++

#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

long long int bfs(vector< vector< pair<int, long long int> > > &graph, vector<long long int> &cons, int root) {
	vector<bool>visited(graph.size(), false);
	queue<int> q; q.push(root);
	visited[root] = true;
	cons[root] = 0;
	int n = graph.size() / 2;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = 0; i < graph[u].size(); ++i) {
			int v = graph[u][i].first;
			long long int w = graph[u][i].second;
			if (u < n) {
				if (cons[v] == LLONG_MAX) {
					cons[v] = cons[u] + w;
				} else {
					if (cons[v] != cons[u] + w) {
						return 0;
					}
				}
			} else {
				if (cons[v] == LLONG_MIN) {
					cons[v] = cons[u] - w;
				} else {
					if (cons[v] != cons[u] - w) {
						return 0;
					}
				}
			}
			if (!visited[v]) {
				q.push(v);
				visited[v] = true;
			}
		}
	}

	long long int solve = LLONG_MAX;
	for (int i = 0; i < n; ++i) {
		if (cons[i] != LLONG_MIN && cons[i + n] != LLONG_MAX) {
			long long int sum = cons[i] + cons[i + n];
			if (sum % 2 == 1) {
				return 0;
			} else {
				if (solve == LLONG_MAX) {
					solve = sum;
				} else {
					if (sum != solve) {
						return 0;
					}
				}
			}
		}
	}
	if (solve != LLONG_MAX) {
		return 1;
	} else {
		return 2;
	}
}
 
int main(void) {
	int n, m;
	cin >> n >> m;
 
	vector< vector< pair<int, long long int> > > graph(2 * n);
 
	int u, v
	long long int s;
	for (int i = 0; i < m; ++i) {
		cin >> u >> v >> s;
		--u; --v;
		graph[u].push_back(make_pair(v + n, s));
		graph[v + n].push_back(make_pair(u, s));
		graph[v].push_back(make_pair(u + n, s));
		graph[u + n].push_back(make_pair(v, s));
	}

	vector<long long int> cons(2 * n);
	for (int i = 0; i < n; ++i) {
		cons[i] = LLONG_MIN;
		cons[i + n] = LLONG_MAX;
	}
	long long int num = bfs(graph, cons, 0);

	if (num == 2LL) {
		long long int lb = 0, ub = LLONG_MAX;
		for (int i = 0; i < n; ++i) {
			// cout << cons[i] << " " << cons[i + n] << endl;
			lb = max(lb, cons[i]);
			ub = min(ub, cons[i + n]);
		}
		cout << max(0LL, ub - lb - 1) << endl;
	} else {
		cout << num << endl;
	}
	return 0;
}





Compiler output:
a.cc: In function 'int main()':
a.cc:76:9: error: expected initializer before 'long'
   76 |         long long int s;
      |         ^~~~
a.cc:78:29: error: 'v' was not declared in this scope
   78 |                 cin >> u >> v >> s;
      |                             ^
a.cc:78:34: error: 's' was not declared in this scope
   78 |                 cin >> u >> v >> s;
      |                                  ^
Language: C++

#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <map>

#define ll int64_t
using namespace std;
const long MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void dfs(int from,int node, int value, bool isOdd);


vector< pair< ll, ll > > Graph[100001]; //G[ノード数]:{pair<辺の距離, 行き先の頂点>}
vector< vector < pair< ll, bool > > > v(100001); //各ノードにおける結果

bool isFalse = false;
bool isodd=false;

vector<bool> oddval(100001, false);//２つでセット：奇数距離ノードと偶数距離ノードが同一のときの判定に利用
vector<ll> oddvalue(100001, 0);
vector<bool> isusedNode(100001,false);




int main()
{
  int N, M, S, T;
  cin >> N >> M;
  long u1, v1, s;

  for (int i = 0; i < M; i++) {//アーク数
    cin >> u1 >> v1 >> s;
    Graph[u1 - 1].push_back(make_pair(s, v1 - 1)); //グラフのノードu1-1にコストs,行き先v1-1のパスを追加する
    Graph[v1 - 1].push_back(make_pair(s, u1 - 1)); //グラフのノードv1-1にコストs,行き先u1-1のパスを追加する
  }

  ll UB = INF;
  ll LB = 0;


  dfs(0,0, 0, false);

  for (int i = 0; i < v.size(); i++) {
    for (int  j = 0; j < v[i].size(); j++) {
      if (v[i][j].second == true) { //偶数距離
        if (UB > v[i][j].first)UB = v[i][j].first;
      } else { //奇数距離
        if (LB < v[i][j].first)LB = v[i][j].first;
      }
       // cout << v[i][j].first << endl;
      //cout << "   value:"<< v[i][j].first<< "  isOdd:" << v[i][j].second<< endl;

    }
  }

  if (isFalse == true) {//ループがあり実行不可のとき  //  //ここの境界条件ミスってる???　一件だけ無駄にisFalseしてる
    cout << "0" <<endl;
  }else if(isodd==true){//ループがあり、なおかつ実行可能なとき  
    cout << "1" <<endl;
  }else{
    cout << max<ll>(0, (UB - 1)  - (LB + 1) + 1 ) << endl;
  }

  // cout << UB << ":U:L:" << LB << endl;


  return 0;
}


void dfs(int from,int node, int value, bool isOdd) { //一個目がノードで２個めが値
  //cout << "node:" << node << "   value:"<< value<< "  isOdd:" << isOdd<< endl;

  // for (int i = 0; i < Graph[node].size(); i++) {
  //   cout << Graph[node][i].second << " -";
  // } cout << endl;
  if (isFalse ==true) return;
  if (v[node].size() > 0 ) {//既に到着しているとき
    for (int i = 0; i < v[node].size(); i++) {
      if (v[node][i].second == isOdd ) { //距離一致するとき
        if (v[node][i].first != value)isFalse = true;
      } else { //距離一致しないとき
        isodd=true;
        if (oddval[node]==false) {//2つの一致のとき
          oddval[node] = true;
          oddvalue[node] = (value - v[node][i].first ) / 2;
        } else {//3つ目以降は必ず偶奇一致する組があり一致判定されるからこれいらない.
          if (oddvalue[node] != (value - v[node][i].first ) / 2)//isFalse = true;
        }
      }
    }
    return ;
  }

  v[node].push_back(make_pair(value, isOdd));
  for (int i = 0; i < Graph[node].size(); i++) {
    ll tn = Graph[node][i].second;
    ll ecost = Graph[node][i].first;
    if (tn==from)continue;
    if (isOdd)dfs(node,tn, value - ecost, !isOdd);
    if (!isOdd)dfs(node,tn, value + ecost, !isOdd);
  }

}



Compiler output:
a.cc: In function 'void dfs(int, int, int, bool)':
a.cc:95:9: error: expected primary-expression before '}' token
   95 |         }
      |         ^
Language: C++

#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <map>

#define ll int64_t
using namespace std;
const long MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void dfs(int from,int node, int value, bool isOdd);


vector< pair< ll, ll > > Graph[100001]; //G[ノード数]:{pair<辺の距離, 行き先の頂点>}
vector< vector < pair< ll, bool > > > v(100001); //各ノードにおける結果

bool isFalse = false;
bool isodd=false;

vector<bool> oddval(100001, false);//２つでセット：奇数距離ノードと偶数距離ノードが同一のときの判定に利用
vector<ll> oddvalue(100001, 0);
vector<bool> isusedNode(100001,false);




int main()
{
  int N, M, S, T;
  cin >> N >> M;
  long u1, v1, s;

  for (int i = 0; i < M; i++) {//アーク数
    cin >> u1 >> v1 >> s;
    Graph[u1 - 1].push_back(make_pair(s, v1 - 1)); //グラフのノードu1-1にコストs,行き先v1-1のパスを追加する
    Graph[v1 - 1].push_back(make_pair(s, u1 - 1)); //グラフのノードv1-1にコストs,行き先u1-1のパスを追加する
  }

  ll UB = INF;
  ll LB = 0;


  dfs(0,0, 0, false);

  for (int i = 0; i < v.size(); i++) {
    for (int  j = 0; j < v[i].size(); j++) {
      if (v[i][j].second == true) { //偶数距離
        if (UB > v[i][j].first)UB = v[i][j].first;
      } else { //奇数距離
        if (LB < v[i][j].first)LB = v[i][j].first;
      }
       // cout << v[i][j].first << endl;
      //cout << "   value:"<< v[i][j].first<< "  isOdd:" << v[i][j].second<< endl;

    }
  }

  if (isFalse == true) {//ループがあり実行不可のとき  //  //ここの境界条件ミスってる???　一件だけ無駄にisFalseしてる
    cout << "0" <<endl;
  }else if(isodd==true){//ループがあり、なおかつ実行可能なとき  
    cout << "1" <<endl;
  }else{
    cout << max<ll>(0, (UB - 1)  - (LB + 1) + 1 ) << endl;
  }

  // cout << UB << ":U:L:" << LB << endl;


  return 0;
}


void dfs(int from,int node, int value, bool isOdd) { //一個目がノードで２個めが値
  //cout << "node:" << node << "   value:"<< value<< "  isOdd:" << isOdd<< endl;

  // for (int i = 0; i < Graph[node].size(); i++) {
  //   cout << Graph[node][i].second << " -";
  // } cout << endl;
  if (isFalse ==true) return;
  if (v[node].size() > 0 ) {//既に到着しているとき
    for (int i = 0; i < v[node].size(); i++) {
      if (v[node][i].second == isOdd ) { //距離一致するとき
        if (v[node][i].first != value)isFalse = true;
      } else { //距離一致しないとき
        isodd=true;
        if (oddval[node]==false) {//2つの一致のとき
          oddval[node] = true;
          oddvalue[node] = (value - v[node][i].first ) / 2;
        } else {
          if (oddvalue[node] != (value - v[node][i].first ) / 2)//isFalse = true;
        }
      }
    }
    return ;
  }

  v[node].push_back(make_pair(value, isOdd));
  for (int i = 0; i < Graph[node].size(); i++) {
    ll tn = Graph[node][i].second;
    ll ecost = Graph[node][i].first;
    if (tn==from)continue;
    if (isOdd)dfs(node,tn, value - ecost, !isOdd);
    if (!isOdd)dfs(node,tn, value + ecost, !isOdd);
  }

}



Compiler output:
a.cc: In function 'void dfs(int, int, int, bool)':
a.cc:95:9: error: expected primary-expression before '}' token
   95 |         }
      |         ^
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

inline ll read(){
	ll Hashimoto=0,Kanna=1;
	char I_Love=getchar();
	while(I_Love<'0'||I_Love>'9'){
		if(I_Love=='-')Kanna=-1;
		I_Love=getchar();
	}
	while(I_Love>='0'&&I_Love<='9'){
		Hashimoto=Hashimoto*10+I_Love-'0';
		I_Love=getchar();
	}
	return Hashimoto*Kanna;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e15
#define mod (inf+7)

int n,m;
vpli g[111111];
ll s[111111][2];
bool v[111111][2];

void bfs(){
	queue<pii>q;
	q.push({0,1});
	v[0][1]=1;
	dp[0][1]=0;
	while(!q.empty()){
		int u=q.front().first;
		int sym=q.front().second;
		q.pop();
		FOR(i,0,g[u].size()){
			ll val=g[u][i].first-s[u][sym];
			int to=g[u][i].second;
			if(v[to][1-sym]){
				if(s[to][1-sym]!=val){
					Tone(0);
					exit(0);
				}
			}
			else{
				s[to][1-sym]=val;
				v[to][1-sym]=1;
				q.push({to,1-sym});
			}
			if(v[to][sym]){
				ll check=s[to][0]-s[to][1];
				if(check<=0){
					Tone(0);
					exit(0);
				}
				if(check%2!=0){
					Tone(0);
					exit(0);
				}
			}
		}
	}
	ll mn=linf,mx=1;
	ll val=linf;
	FOR(i,0,n){
		if(v[i][0]&&v[i][1]){
			if(val==linf){
				val=s[i][0]-s[i][1];
				val/=2;
			}
			else {
				if(val!=(s[i][0]-s[i][1])/2){
					Tone(0);
					exit(0);
				}
			}
		}
		if(v[i][0]){
			if(s[i][0]<2){
				Tone(0);
				exit(0);
			}
			mn=min(mn,s[i][0]-1);
		}
		if(v[i][1]){
			if(s[i][1]<=0)mx=max(mx,1-s[i][1]);
		}
	}
	if(val!=linf)Tone(1)
	else if(mx>mn)Tone(0)
	else Tone(mn-mx+1)
}

int I_Love_Hashimoto_Kanna() {
  fastio;
  n=read();m=read();
  FOR(i,0,m){
  	int a,b;
		ll s;
  	a=read()-1;
  	b=read()-1;
  	s=read();
  	g[a].push_back({s,b});
  	g[b].push_back({s,a});
	}
	bfs();
  
  return 0;
}


Compiler output:
a.cc: In function 'void bfs()':
a.cc:71:9: error: 'dp' was not declared in this scope
   71 |         dp[0][1]=0;
      |         ^~
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <iostream>
#define REP(i,a,b)for (int i=a;i<=b;++i)
#define PER(i,a,b)for (int i=a;i>=b;--i)
#define RVC(i,S)for (int i=0;i<S.size();++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> VI;

const int N=100005;
int n,m,fa[N][2],mx[N],dir[N],tok[N],dep[N];
int sz,eu[N],ev[N],es[N],onc[N];
VI ed[N],si[N];

void addedge(int u,int v,int s){
	ed[u].pb(v);
	si[u].pb(s);
	mx[u]=min(mx[u],s-1);
}

void dfs(int x,int f){
	RVC(i,ed[x])if(ed[x][i]!=f){
		tok[ed[x][i]]=si[x][i]-tok[x];
		dir[ed[x][i]]=-dir[x];
		dfs(ed[x][i],x);
	}
}

void invalid(){
	puts("0");
	exit(0);
}

void tree_case(){
	dir[1]=1;
	tok[1]=1;
	dfs(1,0);
	//REP(i,1,n)debug("%d, %d\n",tok[i],dir[i]);
	int not_positive=0;
	REP(i,1,n)if(tok[i]<=0){
		not_positive=1;
		break;
	}
	if(not_positive){
		int d=0,mn=0;
		REP(i,1,n)if(tok[i]<=0){
			mn=min(mn,tok[i]);
			if(d==0)d=dir[i];
			if(d!=dir[i])invalid();
		}
		REP(i,1,n){
			tok[i]+=d*mn;
			if(tok[i]<=0)invalid();
		}
		int ans=0x3f3f3f3f;
		REP(i,1,n)if(dir[i]==d)
			ans=min(ans,mx[i]-tok[i]);
		printf("%d\n",ans);
	} else{
		int dt=0x3f3f3f3f;
		int ans=dt;
		REP(i,1,n)if(dir[i]==1)
			dt=min(dt,mx[i]-tok[i]);
		REP(i,1,n)tok[i]+=dt;
		REP(i,1,n)if(dir[i]==1)
			ans=min(ans,tok[i]);
		printf("%d\n",ans);
	}
}

void addequ(int x){
	++sz;
	eu[sz]=x; ev[sz]=fa[x][0]; es[sz]=ed[fa[x][0]][fa[x][1]];
	onc[fa[x][0]]=1;
}

void gao(int u,int v,int ke){
	int x=u,y=v;
	++sz;
	eu[sz]=u; ev[sz]=v; es[sz]=ke;
	onc[u]=onc[v]=1;
	while(dep[x]>dep[y]){
		addequ(x);
		x=fa[x][0];
	}
	swap(x,y);
	while(dep[x]>dep[y]){
		addequ(x);
		x=fa[x][0];
	}
	while(x!=y){
		addequ(x);
		addequ(y);
		x=fa[x][0];
		y=fa[y][0];
	}

}

void find_cycle(int x,int f){
	tok[x]=1;
	dep[x]=dep[f]+1;
	RVC(i,ed[x]){
		int y=ed[x][i];
		fa[y][0]=x;
		fa[y][1]=i;
		if(y!=f&&tok[y]){
			gao(x,y,si[x][i]);
		}else find_cycle(y,x);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	memset(mx,0x3f,sizeof mx);
	REP(i,1,m){
		int u,v,s;
		scanf("%d%d%d",&u,&v,&s);
		addedge(u,v,s);
		addedge(v,u,s);
	}
	if(m==n-1)tree_case();
	else find_cycle(1,0);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:131:9: error: 'memset' was not declared in this scope
  131 |         memset(mx,0x3f,sizeof mx);
      |         ^~~~~~
a.cc:12:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   11 | #include <iostream>
  +++ |+#include <cstring>
   12 | #define REP(i,a,b)for (int i=a;i<=b;++i)
Language: C

#include <bits/stdc++.h>
#define inf 1e10
using namespace std;
​
//辺。つながっている頂点と辺の重み
struct edge {
  long long req;
  long long v;
};
//入力等々
long long n, m, u, p, s, maxn = inf, minn = inf, uniquen = -1;
bool nothing = 0;
//メモ。元と同じ値を取っていたらアウトなのでnothingを1に。偶奇違うパターンの時は答えが一意に決まる。
long long memo[2][100005] = {0};
//辺のデータリスト
vector<edge> data[100005];
//再帰。偶奇、現在の地点、一個前の頂点、一個前の合計値
void solve(bool eo, long long now, long long bfreq, long long bfv);
​
int main() {
  long long i, j;
  edge dummy;
  cin >> n >> m;
  for(j = 0; j < 2; ++j)
    for(i = 1; i <= n; ++i) memo[j][i] = inf;
  for(i = 0; i < m; ++i) {
    cin >> u >> p >> s;
    dummy.req = u;
    dummy.v = s;
    data[p].push_back(dummy);
    dummy.req = p;
    data[u].push_back(dummy);
  }
  // cout << endl;
  solve(1, 1, -1, 0);
  // cout << maxn << " " << minn << endl;
  if(nothing || (maxn == inf && minn == inf) || (maxn - minn - 1 < 0)) {
    maxn = 1;
    minn = 0;
  }
  else if(uniquen >= 0) {
    maxn = 2;
    minn = 0;
  }
  if(minn<0)minn=0;
  // cout << nothing;
  cout << maxn - minn -1 << endl;
  return 0;
}
​
void solve(bool eo, long long now, long long bfreq, long long bfv) {
  if(nothing) return;
  long long i, nextv;
  //今いる頂点につながっているすべての辺を通り別の頂点に行く。
  for(i = 0; i < data[now].size(); ++i) {
    //一個前の頂点に戻るか？
    if(data[now][i].req == bfreq) continue;
    //次の頂点の条件の計算
    nextv = bfv;
    if(eo)
      nextv += data[now][i].v;
    else
      nextv -= data[now][i].v;
    //ある頂点で条件が重複しありえないパターンになっていないか？辺の重みがあり得ない値になっていないか？
    if((memo[eo][data[now][i].req] != inf && memo[eo][data[now][i].req] != nextv) ||
       data[now][i].v > 2 * n) {
      // cout << memo[eo][data[now][i].req] << " " << now << i;
      nothing = 1;
      return;
    }
    //すでに通ってたら中断して次の辺へ
    else if(memo[eo][data[now][i].req] == nextv)
      continue;
    memo[eo][data[now][i].req] = nextv;
    //頂点に偶奇両方のデータが存在するとき、その和の半分が唯一の答えとなる。
    if(memo[!eo][data[now][i].req] != inf) {
      long long test = memo[eo][data[now][i].req] + memo[!eo][data[now][i].req];
      if(test < 0 || test % 2 != 0 || (uniquen != -1 && uniquen != test / 2)) {
        nothing = 1;
        // cout << test << " " << uniquen <<endl;
        return;
      }
      uniquen = test/2;
    }
    //minn,maxnの更新。できるだけ条件を厳しくする。
    if (eo && maxn > nextv)maxn = nextv;
      // cout << "max" << nextv << " " << now << " " << i << endl;
    if (!eo && minn > nextv)minn = nextv;
    // cout << eo << " " << now << " " << data[now][i].req << " " << nextv <<
    // endl;
    solve(!eo, data[now][i].req, now, nextv);
  }
}

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