博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gym 101196D Lost in Translation(BFS)
阅读量:4204 次
发布时间:2019-05-26

本文共 1096 字,大约阅读时间需要 3 分钟。

Problem D Lost in Translation

题意:

         给出一个图,从顶点开始(English),寻找 到每个点优先满足路径最短时的最小花费。

思路:

         所谓路径最短优先,其实就是 bfs 逐层搜索。若同层中有指向同一节点但花费不同的边,取最小即可。每搜完一层统计一遍 ans,给搜到的点打上 vis 标记即可。

代码:

const int maxn = 4505;int n,m;struct node{    int v,c,w;    node() {}    node(int _v,int _c,int _w)    {        v = _v;        c = _c;        w = _w;    }    bool operator < (const node &b)const    {        if(c==b.c)            return w>b.w;        return c>b.c;    }};vector
G[maxn];map
maple;priority_queue
q;string a[105];int vis[maxn];int bfs(){ memset(vis,0,sizeof(vis)); q.push(node(0,0,0)); int res = 0; while(!q.empty()) { node now = q.top(); q.pop(); if(vis[now.v]) continue; vis[now.v] = 1; res += now.w; for(int i=0;i
>a[i]; maple[a[i]] = i; } for(int i=0;i
>l>>r>>c; G[maple[l]].push_back(node(maple[r],1,c)); G[maple[r]].push_back(node(maple[l],1,c)); } int ans=bfs(); if(ans==-1) puts("Impossible"); else printf("%d\n",ans); return 0;}

转载地址:http://rpali.baihongyu.com/

你可能感兴趣的文章
java反射详解
查看>>
JPA 注解
查看>>
JQuery 简介
查看>>
Java创建对象的方法
查看>>
Extjs自定义组件
查看>>
TreeGrid 异步加载节点
查看>>
Struts2 标签库讲解
查看>>
Google Web工具包 GWT
查看>>
材料与工程学科相关软件
查看>>
MPI的人怎么用仪器
查看>>
windows 下AdNDP 安装使用
查看>>
Project 2013项目管理教程(1):项目管理概述及预备
查看>>
ssh客户端后台运行
查看>>
哥去求职,才说了一句话考官就让我出去
查看>>
【React Native】把现代web科技带给移动开发者(一)
查看>>
【GoLang】Web工作方式
查看>>
Launch Sublime Text 3 from the command line
查看>>
【数据库之mysql】mysql的安装(一)
查看>>
【数据库之mysql】 mysql 入门教程(二)
查看>>
【HTML5/CSS/JS】A list of Font Awesome icons and their CSS content values(一)
查看>>