关于我的已死算法
查看原帖
关于我的已死算法
214649
Real_Create楼主2020/11/20 20:13

他死了

#include<bits/stdc++.h>
using namespace std;
int cs[2005],n,zdl[2005];
vector<int>a[2005],bq[2005];
queue<int>q;
bool v[2005];
bool dead()
{
	while(q.size())
	{
		q.pop();
	}
	q.push(1);
	zdl[1]=0;
	cs[1]=1;
	while(q.size())
	{
		for(int i=0;i<a[q.front()].size();i++)
		{
			if(zdl[a[q.front()][i]]<zdl[q.front()]+bq[q.front()][i])
			{
				zdl[a[q.front()][i]]=zdl[q.front()]+bq[q.front()][i];
				if(!v[a[q.front()][i]])
				{
					v[a[q.front()][i]]=1;
					cs[a[q.front()][i]]++;
					if(cs[a[q.front()][i]]>=n)
					{
						return 1;
					}
					q.push(a[q.front()][i]);
				}
			}
		}
		v[q.front()]=0;
		q.pop();
	}
	return 0;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int t;
		cin>>n>>t;
		for(int i=1;i<=n;i++)
		{
			cs[i]=0;
			v[i]=0;
			zdl[i]=0x3f3f3f3f;
			a[i].clear();
			bq[i].clear();
		}
		while(t--)
		{
			int x,y,qwq;
			cin>>x>>y>>qwq;
			if(qwq>=0)
			{
				a[x].push_back(y);
				bq[x].push_back(qwq);
				a[y].push_back(x);
				bq[y].push_back(qwq);
			}else
			{
				a[x].push_back(y);
				bq[x].push_back(qwq);
			}
		}
		if(dead())
		{
			cout<<"YES"<<endl;
		}else
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}


2020/11/20 20:13
加载中...