WA了第一个点是怎么肥市
  • 板块P2648 赚钱
  • 楼主Agil12_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/26 10:40
  • 上次更新2024/7/26 11:39:45
查看原帖
WA了第一个点是怎么肥市
1139221
Agil12_楼主2024/7/26 10:40

rt

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define x first
#define y second
using namespace std;
const int N=1e5+10,INF=0x3f3f3f3f;
typedef pair<int,int>P;
int d1,p,c,f,s;//s是起点
int d[N],cnt[N];
bool st[N];
vector<P>g[N];
bool spfa(int s)
{
	memset(d,0x3f,sizeof d);
	queue<P>q;
	d[s]=-d1;//注意求最长路,初始点赋值是个负的
	q.push({s,-d1});
	st[s]=true;
	while(q.size())
	{
		auto t=q.front();
		q.pop();
		int id=t.x;
		st[id]=false;
		for(auto &w:g[id])
		{
			if(d[w.x]>d[id]+w.y)
			{
				d[w.x]=d[id]+w.y;
				cnt[w.x]=cnt[id]+1;
				if(cnt[w.x]>=c)return false;
				if(!st[w.x])
				{
					st[w.x]=true;
					q.push({w.x,d[w.x]});
				}
			}
		}
	}
	return true;
}
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>d1>>p>>c>>f;
	while(p--)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back({b,0-d1});
	}
	while(f--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		g[a].push_back({b,c-d1});
	}
	for(int i=1;i<=c;i++)
	{
		g[0].push_back({i,0});//粗心,前面的处理中点权已经用过了,这里不能再用了,还有是记得
		//用虚拟源点
	}
	bool f=spfa(0);
	if(!f)cout<<"orz";
	else
	{
		int ans=1e9;
		for(int i=1;i<=c;i++)ans=min(ans,d[i]);
		cout<<-ans;
	}
	return 0;
}
2024/7/26 10:40
加载中...