Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33811 | LYLAKIOI | 【S】T3 | C++ | 通过 | 100 | 521 MS | 668 KB | 1556 | 2024-10-22 20:41:53 |
//100pts #include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,dis[4005],cnt[4005],vis[4005]; struct nd { int x,y,w; }d[8005]; vector<pi>v[4005]; bool spfa(){ up(i,1,n)dis[i]=1e9,vis[i]=cnt[i]=0;dis[1]=0; queue<int>q;q.push(1); while(!q.empty()){ int u=q.front();q.pop(); vis[u]=0,++cnt[u]; if(cnt[u]>n)return 1; for(auto it:v[u]){ int x=it.p1,w=it.p2; if(dis[x]>dis[u]+w){ dis[x]=dis[u]+w; if(!vis[x])vis[x]=1,q.push(x); } } }return 0; } void slv(){ n=read();int m=read(); up(i,1,m){ d[i].x=read(),d[i].y=read(); char ch;cin>>ch;if(ch=='(')d[i].w=1;else d[i].w=-1; } up(i,1,m)v[d[i].x].p_b(m_p(d[i].y,d[i].w)); bool ok1=spfa(); up(i,1,n)v[i].clear(); up(i,1,m)v[d[i].x].p_b(m_p(d[i].y,-d[i].w)); bool ok2=spfa(); if(ok1^ok2)printf("No\n"); else printf("Yes\n"); }int main(){ //freopen("walk.in","r",stdin); //freopen("walk.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }