您当前的位置: 首页 > 

钟钟终

暂无认证

  • 3浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P1529 [USACO2.4]回家 Bessie Come Home

钟钟终 发布时间:2022-02-01 22:59:00 ,浏览量:3

https://www.luogu.com.cn/problem/P1529 小坑:要是无向图直接闭眼双向存边,不用多想

#include 

using namespace std;
typedef long long ll;
const int maxn=1e4+5;
const int inf=0x7fffffff;
struct node
{
    int to,dis,nxt;
}e[maxn];
int n,head[maxn],val,cnt,minn,s;
ll dist[maxn];
bool vis[maxn];
char c1,c2;
void add_edge(int from,int to,int dis)
{
    e[++cnt].to=to;
    e[cnt].dis=dis;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
void dijkstra()
{
    dist[s]=0;
    while(!vis[s])
    {
        vis[s]=1;minn=inf;
        for(int i=head[s];i!=-1;i=e[i].nxt)
        {
            int y=e[i].to;
            if(dist[y]>dist[s]+e[i].dis&&!vis[y])
            {
                dist[y]=dist[s]+e[i].dis;
            }
        }
        for(int i=1;idist[i]&&!vis[i])
            {
                minn=dist[i];
                s=i;
            }
        }
    }
}
int main()
{
    scanf("%d",&n);
    head[0]=-1;
    for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0976s