提交时间:2024-10-22 18:38:03

运行 ID: 33807

//100 #include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define p1(x) x.first #define p2(x) x.second int n,m; vector<pii>A[2]; int d[4010]; inline bool chk(){ memset(d,0x3f,sizeof(d)); d[1]=0; bool cont=1; int ct=0; while(cont){ cont=0; for(pii e:A[0]){ int u=p1(e),v=p2(e); if(d[v]>d[u]+1){ d[v]=d[u]+1; cont=1; } } for(pii e:A[1]){ int u=p1(e),v=p2(e); if(d[v]>d[u]-1){ d[v]=d[u]-1; cont=1; } } ct++; if(ct>=2*n)return 1; } return 0; } signed main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); // freopen("genshin.in","r",stdin); // freopen("genshin.out","w",stdout); cin>>n>>m; bool a=0,b=0; int s=0; for(int i=1;i<=m;i++){ int u,v; char x; cin>>u>>v>>x; int w=0; if(x=='(')A[0].push_back({u,v}); else A[1].push_back({u,v}); } bool Aring=chk(); swap(A[0],A[1]); bool Bring=chk(); if(Aring ^Bring )cout<<"No"; else cout<<"Yes"<<endl; cout.flush(); return 0; }