Language: C++

#include <string>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef string key_t;

char b1[99],b2[99];
void main2(int n){
	map<key_t,vector<pair<key_t,long long>>>m;
	for(;n;n--){
		int d;
		scanf(" 1 %s = 10^%d %s",b1,&d,b2);
		string s1=b1,s2=b2;
		m[s1].emplace_back(s2,d);
		m[s2].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		auto s=m.begin()->first;
		vector<pair<key_t,long long> >st={{s,0}};
		map<key_t,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			memo[cur]=d;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return;
				}
			}
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}
int main(){int n;for(;~scanf("%d",&n)&&n;)main2(n);}

Compiler output:
a.cc:7:16: error: conflicting declaration 'typedef std::string key_t'
    7 | typedef string key_t;
      |                ^~~~~
In file included from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/sys/types.h:121:17: note: previous declaration as 'typedef __key_t key_t'
  121 | typedef __key_t key_t;
      |                 ^~~~~
a.cc: In function 'void main2(int)':
a.cc:16:18: error: no match for 'operator[]' (operand types are 'std::map<int, std::vector<std::pair<int, long long int> > >' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   16 |                 m[s1].emplace_back(s2,d);
      |                  ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = std::vector<std::pair<int, long long int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::vector<std::pair<int, long long int> > > >; mapped_type = std::vector<std::pair<int, long long int> >; key_type = int]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'const std::map<int, std::vector<std::pair<int, long long int> > >::key_type&' {aka 'const int&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = std::vector<std::pair<int, long long int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::vector<std::pair<int, long long int> > > >; mapped_type = std::vector<std::pair<int, long long int> >; key_type = int]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::map<int, std::vector<std::pair<int, long long int> > >::key_type&&' {aka 'int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:17:18: error: no match for 'operator[]' (operand types are 'std::map<int, std::vector<std::pair<int, long long int> > >' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   17 |                 m[s2].emplace_back(s1,-d);
      |                  ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = std::vector<std::pair<int, long long int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::vector<std::pair<int, long long int> > > >; mapped_type = std::vector<std::pair<int, long long int> >; key_type = int]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'const std::map<int, std::vector<std::pair<int, long long int> > >::key_type&' {aka 'const int&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = std::vector<std::pair<int, long long int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::vector<std::pair<int, long long int> > > >; mapped_type = std::vector<std::pair<int, long long int> >; key_type = int]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::map<int, std::vector<std::pair<int, long long int> > >::key_type&&' {aka 'int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~