湖大训练赛4 Dwarf Tower
来源:互联网 发布:软件开发岗位说明书 编辑:程序博客网 时间:2024/05/01 10:01
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.
Sample Input
5 35 0 1 2 55 2 34 2 31 4 53 12 2 11 2 3Sample Output
22
刚开始比赛一直很顺,这题开始用暴力T了一发,准备用DFS继续撸一发,队友过来说是树形Dp,思想跟我差不多,好吧,然后嘴贱的顺便丢了一句:如果不是树形DP,接下来不会卡题4个小时吧?(当时对于这种神预测,我表示有种不祥的预感)。果然很快的月神就WR了。我然后修改了一下加入了回朔,不出所料T了。然后一直在想这种思路怎么了,哪里有bug。其实就是不能这样。然后一边开启群嘲模式。ORz...后来我又用了各种优美的姿势暴力破解,最小生成树,拓扑。。。结果都是T。无奈还被大一新生给压下来了。据说不用任何算法。呵呵。临近比赛结束实在忍不住好奇去求教了一下。看到她们居然是用按第一个数排序从小到大,然后按第一个数从大到小更新值。居然AC了。显然这是有问题,我随便出了一组数据给他们。然后无言以对。我也就无语了,这样的煞笔代码也能AC.我当然是针对这代码,没有指人,不要见怪。整场4个小时我们就一直纠结这题。姿势优美却A不了C。煞笔代码却能AC,这种情况碰到几次了,还有一次是在上一次的bestcoder。太伤了。深深感受的这游戏满满的恶意。后来,也就是晚上。月神提出了一个想法,构图的方法跟我类似,不过更新点的时候是用迪杰斯特拉的思想,我提出了几点建议,但是我还是T怕了,反正闲着也是蛋疼,就顺手敲了一下,提交。红色的AC!!!oh...my god!终于在月神的光环下,以正确的姿势AC了。人生无憾了。可以滚去睡觉了。代码就只贴AC的算了。。。心太伤。。。
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>using namespace std;#define LL __int64struct node{int x,y;node(LL a,LL b):x(a),y(b){}};LL a[100010];int vis[100010];vector <node>v[10010];int n,m,i,j,k,x,y;queue<int>q;int main(){scanf("%d%d",&n,&m);for (i=1;i<=n;i++){scanf("%I64d",&a[i]);vis[i]=0;}if (m==0){printf("%I64d\n",a[1]);return 0;}for (i=1;i<=m;i++){scanf("%d%d%d",&k,&x,&y);v[x].push_back(node(y,k));v[y].push_back(node(x,k));if (!vis[x]){vis[x]=1;q.push(x);}if (!vis[y]){vis[y]=1;q.push(y);}}while (!q.empty()){k=q.front();vis[k]=0;q.pop();int l=v[k].size();for (i=0;i<l;i++){if (a[k]+a[v[k][i].x]<a[v[k][i].y]){a[v[k][i].y]=a[k]+a[v[k][i].x];if (!vis[v[k][i].y]){q.push(v[k][i].y);vis[v[k][i].y]=1;}}}}printf("%I64d\n",a[1]);return 0;}
- 湖大训练赛4 Dwarf Tower
- Dwarf tower
- dwarf tower
- dwarf tower
- dwarf tower
- acm HNU Dwarf Tower
- HOJ 12847 Dwarf Tower (最短路)
- NEERC 2013 Dwarf Tower (最短路)
- 2016山东ACM热身赛 Dwarf Tower
- Gym 100269D Dwarf Tower(最短路)
- 2516 2014年中山市选拔赛 dwarf tower
- dwarf
- dwarf
- DWARF
- 湖大训练赛1 Shipuratt
- 湖大训练赛1 Restore Calculation
- 湖大训练赛2 Modified LCS
- 湖大训练赛8 Bad Signal
- 这两年的工作总结(序)
- 地方很多规划法规很反感会更好
- CSS特殊样式(透明、旋转、阴影)
- 详解Android中那些酷炫返回方式的实现
- ImportError: No module named MySQLdb解决办法
- 湖大训练赛4 Dwarf Tower
- 数字图像处理 CImage类的使用与封装(jpg png gif tif bmp等格式图像的加载、数据读写、保存等功能)
- Spring笔记---最小化Spring配置
- android调试的几个命令
- Java中的StringBuffer
- 7.27_java学习_map应用
- CMake 手册详解(1-2)
- cocos2d-x 场景切换
- 传递、返回复杂类型的对象(axis服务端/axis客户端)