Language: C++

#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
// this is a comment
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;       //input members
int main()    //main body
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");          //output
   else     printf("No\n");
}
#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
// this is a comment
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;       //input members
int main()    //main body
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");          //output
   else     printf("No\n");
}
//parshant

Compiler output:
a.cc:55:11: error: redefinition of 'const int maxn'
   55 | const int maxn=1e5+10;
      |           ^~~~
a.cc:10:11: note: 'const int maxn' previously defined here
   10 | const int maxn=1e5+10;
      |           ^~~~
a.cc:56:5: error: redefinition of 'int pre [100010]'
   56 | int pre[maxn];
      |     ^~~
a.cc:11:5: note: 'int pre [100010]' previously declared here
   11 | int pre[maxn];
      |     ^~~
a.cc:57:5: error: redefinition of 'int dis [100010]'
   57 | int dis[maxn];
      |     ^~~
a.cc:12:5: note: 'int dis [100010]' previously declared here
   12 | int dis[maxn];
      |     ^~~
a.cc:58:5: error: redefinition of 'int findset(int)'
   58 | int findset(int x)
      |     ^~~~~~~
a.cc:13:5: note: 'int findset(int)' previously defined here
   13 | int findset(int x)
      |     ^~~~~~~
a.cc:65:6: error: redefinition of 'bool unionset(int, int, int)'
   65 | bool unionset(int x,int y,int w)
      |      ^~~~~~~~
a.cc:20:6: note: 'bool unionset(int, int, int)' previously defined here
   20 | bool unionset(int x,int y,int w)
      |      ^~~~~~~~
a.cc:74:5: error: redefinition of 'int n'
   74 | int n,m;       //input members
      |     ^
a.cc:29:5: note: 'int n' previously declared here
   29 | int n,m;       //input members
      |     ^
a.cc:74:7: error: redefinition of 'int m'
   74 | int n,m;       //input members
      |       ^
a.cc:29:7: note: 'int m' previously declared here
   29 | int n,m;       //input members
      |       ^
a.cc:75:5: error: redefinition of 'int main()'
   75 | int main()    //main body
      |     ^~~~
a.cc:30:5: note: 'int main()' previously defined here
   30 | int main()    //main body
      |     ^~~~