简单小绿题球条啊↑啊↓啊↑啊↓啊↑啊↓啊↑啊
查看原帖
简单小绿题球条啊↑啊↓啊↑啊↓啊↑啊↓啊↑啊
750476
Hf_Poem楼主2024/4/19 15:27

蒟蒻分层图已经调哭死了(重伤倒地

所以这玩意为什么会每次都输出−0x3f-0x3f呢(沉思

#include<bits/stdc++.h>
using namespace std;
struct Edge
{
	int to,pre,v;
} edge[2000005];
int n,m,u,v,opt,ji,ans[300005],vis[300005],last[300005];
priority_queue<pair<int, int>,vector<pair<int, int> >,less<pair<int, int> > > q;
int f(int x,int y)
{
	return x+y*n;
}
void add(int x,int y,int val)
{
	edge[++ji].pre=last[x],last[x]=ji;
	edge[ji].to=y,edge[ji].v=val;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>v;
		add(f(i,0),f(i,1),-v);
		add(f(i,1),f(i,2),v);
	}
	for(int i=1;i<=n;i++)
	{
		cin>>u>>v>>opt;
		add(f(u,0),f(v,0),0),add(f(u,1),f(v,1),0),add(f(u,2),f(v,2),0);
		if(opt==2) add(f(v,0),f(u,0),0),add(f(v,1),f(u,1),0),add(f(v,2),f(u,2),0);
	}
	memset(ans,-0x3f3f3f3f,sizeof(ans));
    ans[1]=0;
    q.push(make_pair(ans[1],1));
    while(!q.size())
    {
        int now=q.top().second;
        q.pop();
        if (vis[now]==0)
        {
            vis[now]=1;
            for (int i=last[now];i;i=edge[i].pre)
            {
                int to=edge[i].to;
                if (ans[now]+edge[i].v>ans[to])
                {
                    ans[to]=ans[now]+edge[i].v;
                    q.push(make_pair(ans[to],to));
                    vis[now]=0;
                }
            }
        }
    }
    cout<<ans[f(n,2)];
	return 0;
}
2024/4/19 15:27
加载中...