Gym 100269D Dwarf Tower(最短路)
来源:互联网 发布:婚礼幻灯片制作软件 编辑:程序博客网 时间:2024/06/08 06:17
思路:给你m个交换条件就是相当于m条路,然后求一发最短路就可以了
#include<bits/stdc++.h>using namespace std;const int maxn = 10000+500;int d[maxn];struct Node{int x,y;Node(){};Node(int xx,int yy):x(xx),y(yy){};};vector<Node>e[maxn];int inq[maxn];int main(){freopen("dwarf.in","r",stdin);freopen("dwarf.out","w",stdout);int n,m;scanf("%d%d",&n,&m);for(int i = 1;i<=n;i++)scanf("%d",&d[i]);for(int i = 1;i<=m;i++){int a,u,v;scanf("%d%d%d",&a,&u,&v); e[u].push_back(Node(v,a));e[v].push_back(Node(u,a));}queue<int>q; for(int i =1;i<=n;i++){q.push(i);inq[i]=1;}while(!q.empty()){int now = q.front();q.pop();inq[now]=0;for(int i = 0;i<e[now].size();i++){Node temp = e[now][i];if(d[temp.y]>d[temp.x]+d[now]){d[temp.y]=d[temp.x]+d[now];if(!inq[temp.y])q.push(temp.y);inq[temp.y]=1;}}}printf("%d\n",d[1]);}
Problem D. Dwarf Tower
Input file: dwarf.in
Output file: dwarf.out
Time limit: 2 seconds
Memory limit: 256 megabytes
Little Vasya is playing a new game named “Dwarf Tower”. In this game there are n different items,
which you can put on your dwarf character. Items are numbered from 1 to n. Vasya wants to get the
item with number 1.
There are two ways to obtain an item:
• You can buy an item. The i-th item costs ci money.
• You can craft an item. This game supports only m types of crafting. To craft an item, you give
two particular different items and get another one as a result.
Help Vasya to spend the least amount of money to get the item number 1.
Input
The first line of input contains two integers n and m (1 ≤ n ≤ 10 000; 0 ≤ m ≤ 100 000) — the number
of different items and the number of crafting types.
The second line contains n integers ci — values of the items (0 ≤ ci ≤ 109
).
The following m lines describe crafting types, each line contains three distinct integers ai
, xi
, yi — ai
is
the item that can be crafted from items xi and yi (1 ≤ ai
, xi
, yi ≤ n; ai ̸= xi
; xi ̸= yi
; yi ̸= ai).
Output
The output should contain a single integer — the least amount of money to spend.
Examples
dwarf.in dwarf.out
5 3
5 0 1 2 5
5 2 3
4 2 3
1 4 5
2
3 1
2 2 1
1 2 3
2
- Gym 100269D Dwarf Tower(最短路)
- HOJ 12847 Dwarf Tower (最短路)
- NEERC 2013 Dwarf Tower (最短路)
- Gym - 100625D Destination Unknown 最短路
- Dwarf tower
- dwarf tower
- dwarf tower
- dwarf tower
- acm HNU Dwarf Tower
- D-最短路(poj1860)
- Gym 100733H Designation in the Mafia(最短路)
- CF 96D Volleyball(最短路套最短路)
- Gym 101194D Ice Cream Tower (双指针扫描)
- Gym - 100625J Jailbreak 最短路+搜索
- Codeforces gym 101149 L 最短路
- 湖大训练赛4 Dwarf Tower
- 2016山东ACM热身赛 Dwarf Tower
- HDU 5886 - Tower Defence(最短路+最小割)
- Thinking in Java 第16章 数组
- android 作业1相对布局(拼图)
- Java中的IO流系统详解
- [Cloud Computing]Mechanisms: Multi-Device Broker
- 前端开发人员必须了解的七大技能图谱(http://geek.csdn.net/news/detail/88239)
- Gym 100269D Dwarf Tower(最短路)
- Queue<T> 需要注意的多线程冲突问题
- CheckBox判断是否勾选
- 组合/聚合复用原则详解--七大面向对象设计原则(7)
- java笔记
- java集合类深入分析之TreeMap/TreeSet篇
- volatile限定符
- 杭电ACM 1425 hash函数运用
- 小马哥 高仿三星w2015主板信息W1201-GW-NB82KK-150812刷机主板图