您当前的位置: 首页 > 

钟钟终

暂无认证

  • 0浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P2648 赚钱

钟钟终 发布时间:2022-02-10 20:34:31 ,浏览量:0

https://www.luogu.com.cn/problem/P2648 这题就很棒,一直以为有毒瘤数据不让我过,实际上是自己的低级错误。 大致思路:找一条最长路径,但是因为起点的不确定,我们需要引入一个超级源点,这个源点到任何点的距离都为0. 本题还有一个重点是:点的权值转化到了边上,这个相信大家都会;但是,我们都知道这个引入的超级源点是不赚钱的,但是代码中扔给他赋值为d,因为我们相连的另一端的城市是由权值d的,但我们将边赋值为0,所以就要将另一端城市上的d转移到源点上。

#include 

using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=5e5+5;
int head[maxn],d,p,c,f,s,cnt,pp[maxn],dis[maxn];
bool vis[maxn],flag;
struct node
{
    int to,dis,nxt;
}e[maxn];
void add_edge(int from,int to,int w)
{
    e[++cnt].to=to;
    e[cnt].dis=w;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
queueq;
void spfa()
{
    dis[s]=d;
    q.push(s);
    vis[s]=1;
    pp[s]++;
    while(!q.empty())
    {
        int u=q.front();q.pop();
        vis[u]=0;
        if(++pp[u]>c)
        {
            printf("orz\n");
            flag=1;
            return;
        }
        for(int i=head[u];~i;i=e[i].nxt)
        {
            int v=e[i].to;
            if(dis[v]            
关注
打赏
1664378814
查看更多评论
0.0474s