stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(dis));

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}


// Faster C++ solution for the same problem (measured speedup: 1.15065243025982x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    //memset(dis,2000000000,sizeof(dis));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        if(s[i].d)s[i + m].d = - s[i].d;

        else s[i].d = 0;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define ll long long



int n,m;

int L,R,D;

vector<pair<int,int> >mp[100100];

int dis[100100];

bool vis[100100];

int flag;



void dfs(int u,int pre)

{

    if(!flag) return;

     int sz=mp[u].size();

     pair<int,int>tmp;

     for(int i=0;i<sz;++i)

     {

        tmp=mp[u][i];

        if(vis[tmp.first])

        {

            if(dis[u]+tmp.second!=dis[tmp.first])

            {

                flag=0;return;

            }

        }

        else

        {

            vis[tmp.first]=1;

            dis[tmp.first]=dis[u]+tmp.second;

            dfs(tmp.first,u);

        }

     }

}



int main(int argc, char const *argv[])

{

    /* code */

    scanf("%d %d",&n,&m);

    for(int i=1;i<=m;++i)

    {

        scanf("%d %d %d",&L,&R,&D);

        mp[R].push_back(make_pair(L,D));

        mp[L].push_back(make_pair(R,-D));

    }

    flag=1;

    for(int i=1;i<=n;++i) if(!vis[i])

    {

        vis[i]=1;

        dfs(i,-1);

    }

    if(flag) puts("Yes");else puts("No");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3555335301419864x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    //memset(dis,2000000000,sizeof(dis));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        if(s[i].d)s[i + m].d = - s[i].d;

        else s[i].d = 0;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    memset(dis,2000000000,sizeof(dis));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}


// Faster C++ solution for the same problem (measured speedup: 1.1508787806513017x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    //memset(dis,2000000000,sizeof(dis));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        if(s[i].d)s[i + m].d = - s[i].d;

        else s[i].d = 0;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    cin>>n>>m;

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        cin>>s[i].l>>s[i].r>>s[i].d;

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(dis));

            dfs(i);

        }

    }

    if(flag)cout<<"Yes";

    else cout<<"No";

}


// Faster C++ solution for the same problem (measured speedup: 1.1557637120906088x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = - s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(dis));

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}


// Faster C++ solution for the same problem (measured speedup: 1.1506484690471745x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = - s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define ll long long



int n,m;

int L,R,D;

vector<pair<int,int> >mp[100100];

int dis[100100];

bool vis[100100];

int flag;



void dfs(int u,int pre)

{

    if(!flag) return;

     int sz=mp[u].size();

     pair<int,int>tmp;

     for(int i=0;i<sz;++i)

     {

        tmp=mp[u][i];

        if(vis[tmp.first])

        {

            if(dis[u]+tmp.second!=dis[tmp.first])

            {

                flag=0;return;

            }

        }

        else

        {

            vis[tmp.first]=1;

            dis[tmp.first]=dis[u]+tmp.second;

            dfs(tmp.first,u);

        }

     }

}



int main(int argc, char const *argv[])

{

    /* code */

    scanf("%d %d",&n,&m);

    for(int i=1;i<=m;++i)

    {

        scanf("%d %d %d",&L,&R,&D);

        mp[R].push_back(make_pair(L,D));

        mp[L].push_back(make_pair(R,-D));

    }

    flag=1;

    for(int i=1;i<=n;++i) if(!vis[i])

    {

        vis[i]=1;

        dfs(i,-1);

    }

    if(flag) puts("Yes");else puts("No");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3555288636098353x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = - s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    memset(dis,2000000000,sizeof(dis));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}


// Faster C++ solution for the same problem (measured speedup: 1.1508748186594273x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = - s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    cin>>n>>m;

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        cin>>s[i].l>>s[i].r>>s[i].d;

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(dis));

            dfs(i);

        }

    }

    if(flag)cout<<"Yes";

    else cout<<"No";

}


// Faster C++ solution for the same problem (measured speedup: 1.1557991494415858x):
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d + dis[s[k].l] != dis[s[k].r])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    scanf("%d%d",&n,&m);

    memset(first,-1,sizeof(first));

    for(int i = 0;i < m;i ++)

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

    for(int i = 1;i <= n;i ++)

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}