Language: C++



#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

typedef long long ll;
int N, M;
vector<pair<int, int>> E[201010];
vector<pair<int, int>> EE[201010];
int vis[201010], col[201010];
//---------------------------------------------------------------------------------------------------
#define no "No"
#define yes "Yes"

#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)

string solve() {
	rep(i, 0, N) if (!vis[i]) {
		col[i] = 0;
		vis[i] = 1;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int q = que.front(); que.pop();

			fore(p, E[q]) {
				if (vis[p.first]) {
					if (col[q] + p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] + p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}

			fore(p, EE[q]) {
				if (vis[p.first]) {
					if (col[q] - p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] - p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}
		}
	}

	return yes;
}
//---------------------------------------------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		E[a].push_back({ b, c });
		EE[b].push_back({ a, c });
	}
	cout << solve() << endl;

	return 0;
}

Compiler output:
a.cc:22:1: error: 'vector' does not name a type
   22 | vector<pair<int, int>> E[201010];
      | ^~~~~~
a.cc:23:1: error: 'vector' does not name a type
   23 | vector<pair<int, int>> EE[201010];
      | ^~~~~~
a.cc:32:1: error: 'string' does not name a type; did you mean 'stdin'?
   32 | string solve() {
      | ^~~~~~
      | stdin
a.cc: In function 'int main()':
a.cc:69:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   69 |         cin >> N >> M;
      |         ^~~
      |         std::cin
In file included from a.cc:3:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:74:17: error: 'E' was not declared in this scope
   74 |                 E[a].push_back({ b, c });
      |                 ^
a.cc:75:17: error: 'EE' was not declared in this scope
   75 |                 EE[b].push_back({ a, c });
      |                 ^~
a.cc:77:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   77 |         cout << solve() << 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:77:17: error: 'solve' was not declared in this scope
   77 |         cout << solve() << endl;
      |                 ^~~~~
a.cc:77:28: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   77 |         cout << solve() << 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)
      |     ^~~~