P3946 全WA了,但是题目讨论区已经一年多没人回复了,求助灌水区大佬
  • 板块灌水区
  • 楼主Security_Guard
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/3/19 20:27
  • 上次更新2023/11/5 01:52:46
查看原帖
P3946 全WA了,但是题目讨论区已经一年多没人回复了,求助灌水区大佬
435312
Security_Guard楼主2021/3/19 20:27
#include<iostream>
#include<cstdio>
#include<queue>
#define maxn 200001
#define maxm 500005
using namespace std;
int n,m,s,t,g,p;
int cnt;
bool flag[maxn];
int hi[maxn],mi[maxm],li[maxn];
int fir[maxm],d[maxn],vis[maxn];
struct bal{
	int next=-1;
	int to;
	int w;
};
bal e[maxm];
queue <int> q;
void add(int x,int y,int z){
	e[++cnt].next=fir[x];
	e[cnt].to=y;
	e[cnt].w=z;
	fir[x]=cnt;
}
inline int re()
{
   int x=0,f=1;char ch=getchar();
   while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
   while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
   return x*f;
}
void spfa()
{
   for(int i=1;i<=n;i++)d[i]=(1<<30);
   queue<int>q;
   q.push(s);
   d[s]=0;
   vis[s]=1;
   while(!q.empty())
   {
       int u=q.front();
       q.pop();
       vis[u]=0;
       for(int i=fir[u];i!=-1;i=e[i].next)
       {
           int v=e[i].to;
           if(!flag[v]&&d[v]>d[u]+e[i].w)
           {
               if(hi[v]+(d[u]+e[i].w)*p<=li[v]||v==t)
               {
                   d[v]==d[u]+e[i].w;
                   if(!vis[v])
                   {
                       vis[v]=1;
                       q.push(v);
                   }
               }
           }
       }
   }
}
int main()
{
	n=re();m=re();s=re();
	t=re();g=re();p=re();
	for(int i=1;i<=n;i++){
		hi[i]=re();li[i]=re();
		if(hi[i]==li[i])
		flag[i]=1;
	}
	for(int i=1;i<=m;i++){
		int a,b,c;
		a=re();b=re(); c=re();
		add(a,b,c);add(b,a,c);
	}
	spfa();
	if(d[t]>g) 
	cout<<"wtnap wa kotori no oyatsu desu!";
	else cout<<d[t]<<endl;
	return 0;
}
2021/3/19 20:27
加载中...