火烧赤壁。。。
查看原帖
火烧赤壁。。。
169594
Heart_Of_Iron_4楼主2025/1/22 16:50
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace IO{
	char ibuf[(1<<20)+1],*iS,*iT;
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
	inline long long read(){
		char ch=gh();
		long long x=0;
		bool t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
}
using namespace IO;
struct xy
{
	int x,y,z;
}te,te1;
bool operator <(xy x,xy y)
{
	return x.y<y.y;
}
vector<xy> g[7010];
vector<int> c[7010];
priority_queue<xy> q;
int dis[7010],w[7010],t1,t2,t3,n,m,f[7010];
bool b[7010],u[7010];
signed main()
{
	memset(dis,0x3f3f3f3f,sizeof dis);
	memset(u,0,sizeof u);
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		t1=read();
		t2=read();
		t3=read();
		g[t1].push_back({t1,t2,t3});
	}
	for(int i=1;i<=n;++i)
	{
		t1=read();
		w[i]=t1;
		for(int j=1;j<=t1;++j)
		{
			t2=read();
			c[t2].push_back(i);
		}
	}
	te={1,0,0};
	dis[1]=0;
	q.push(te);
	while(!q.empty())
	{
		te=q.top();
		//printf("%lld %lld %lld\n",te.x,te.y,u[te.x]);
		q.pop();
		if(u[te.x]==1)continue;
		u[te.x]=1;
		for(auto i:g[te.x])
		{
			if(te.y+i.z<dis[i.y])
			{
				te1.x=i.y;
				te1.y=te.y+i.z;
				//printf("1:%lld %lld\n",te1.x,te1.y);
				dis[te1.x]=te1.y;
				if(w[te1.x]==0)q.push(te1);
				//delete and push must put out of this 'for'.
				//because: if 1--1->2,2 protect 3,1--1->3
				//then when at 2,dis[3]=inf,then push {3,inf}.crash.
				//but if push out this 'for',then dis[3]=1
			}
		}
		if(!b[te.x])
		{
			b[te.x]=1;
			for(auto j:c[te.x])
			{
				w[j]--;
				if(w[j]==0)
				{
					if(dis[j]<te.y)dis[j]=te.y;
					q.push({j,dis[j],0});
				}
			}
		}
	}
	printf("%lld",dis[n]);
	return 0;
}
2025/1/22 16:50
加载中...