比赛 |
欢乐水题赛 |
评测结果 |
AWEEEEEEEE |
题目名称 |
KZ菌的星际旅行 |
最终得分 |
10 |
用户昵称 |
wolf. |
运行时间 |
0.588 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2015-04-24 15:42:33 |
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk=" ";
ofstream nnew("KZstartravelillu.in",ios::app);
ifstream fin("KZstartravelillu.in");
#define fout cout
#define Endl endl
#else
ifstream fin("KZstartravelillu.in");
ofstream fout("KZstartravelillu.out");
#endif
class node{
public:
int from,to;
int len;
node(){
}
node(int a,int b,int c){
from=a;
to=b;
len=c;
}
};
vector<vector<int> > index;
vector<node> TT;
int core(int n){
queue<int> Q;
Q.push(1);
vector<bool> flag;
vector<int> dis;
dis.resize(index.size(),999999999);
flag.resize(index.size(),0);
dis[1]=0;
while(!Q.empty()){
int it=Q.front();
Q.pop();
flag[it]=0;
for(int i=0;i!=index[it].size();++i){
node& pp=TT[index[it][i]];
if(dis[pp.to]>dis[pp.from]+pp.len){
dis[pp.to]=dis[pp.from]+pp.len;
if(flag[pp.to]){
continue;
}
flag[pp.to]=1;
Q.push(pp.to);
}
}
}
return dis[n];
}
int main(){
int n,m;
fin>>n>>m;
index.resize(n+5);
for(int i=0;i!=m;++i){
int a,b,c;
fin>>a>>b>>c;
index[a].push_back(TT.size());
TT.push_back(node(a,b,c));
index[b].push_back(TT.size());
TT.push_back(node(b,a,c));
}
fout<<core(n)<<endl;
//-------------------------*/
#if defined wolf
cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
#endif
return 0;
}
//Designed by wolf
//Fri Apr 24 2015