Language: C++

#include<iostream>
#include<algorithm>
#include<vector>

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

int n, m;
vector<vector<P>> edge;
P status[100000];//頂点0から探索をするとして
//(a, b): a=0ならp+b a=1ならb-pの形と定義

bool iscorrect(P a, P b, int cost) {
	if (a.first == a.second)return false;
	if (cost == a.second + b.second)return true;
	return false;
}

int onlyans = 0;

int onlyans_solve(int nowpos, P a) {
	int ret = -1;
	if (status[nowpos].first == status[a.first].first &&
		status[nowpos].first == 0 &&
		a.second - status[nowpos].second - status[a.first].second >= 2 &&
		(a.second - status[nowpos].second - status[a.first].second) % 2 == 0) {
		ret = (a.second - status[nowpos].second - status[a.first].second) / 2;
	}
	else {
		if (status[nowpos].first == status[a.first].first &&
			-a.second + status[nowpos].second + status[a.first].second >= 2 &&
			(-a.second + status[nowpos].second + status[a.first].second) % 2 == 0) {
			ret = (status[nowpos].second + status[a.second].second - a.second) / 2;
		}
	}
	return ret;
}

bool dfs(int nowpos) {

	for (int i = 0; i < edge[nowpos].size(); i++) {
		P next = edge[nowpos][i];
		//未更新頂点
		if (status[next.first].first == -1 && status[next.first].second == -1) {
			status[next.first].first = !status[nowpos].first;
			if (next.second - status[nowpos].second <= 0)return false;
			status[next.first].second = next.second - status[nowpos].second;
			if (!dfs(next.first)) return false;
		}
		
		//更新済み頂点
		else if (!iscorrect(status[nowpos], status[next.first], next.second)) {
			if (onlyans == 0) {
				if (onlyans_solve(nowpos, next) != -1)onlyans = onlyans_solve(nowpos, next);
				else return false;
			}
			else {
				if (onlyans != onlyans_solve(nowpos, next)) {
					return false;
				}
			}
		}
	}
	return true;
}

int main() {
	cin >> n >> m;
	edge.resize(n);
	for (int i = 0; i < m; i++) {
		int u, v, s;
		cin >> u >> v >> s;
		u--, v--;
		edge[u].push_back(P(v, s));
		edge[v].push_back(P(u, s));
	}
	for (int i = 0; i < n; i++) {
		status[i] = make_pair(-1, -1);
	}
	status[0] = make_pair(0, 0);
	if (!dfs(0)) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 1500000000;
	for (int i = 0; i < n; i++) {
		if (status[i].first == 1) {
			ans = min(ans, status[i].second);
		}
	}
	ans--;
	if (onlyans != 0) {
		if (ans >= onlyans)cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	if (ans > 0)cout << ans << endl;
	else cout << 0 << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:34: error: no matching function for call to 'min(int&, long long int&)'
   89 |                         ans = min(ans, status[i].second);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:89:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   89 |                         ans = min(ans, status[i].second);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:89:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   89 |                         ans = min(ans, status[i].second);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~