记录编号 |
160241 |
评测结果 |
AAAAAAAAAA |
题目名称 |
KZ菌的星际旅行 |
最终得分 |
100 |
用户昵称 |
wolf. |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.094 s |
提交时间 |
2015-04-24 19:40:59 |
内存使用 |
0.31 MiB |
显示代码纯文本
#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;
queue<int> Q;
int core(int n){
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;
//cout<<it<<endl;
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(100000);
for(int i=0;i!=m;++i){
int a,b,c;
fin>>a>>b>>c;
//cout<<a<<" "<<b<<" "<<c<<endl;
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)*2<<endl;
//-------------------------*/
#if defined wolf
cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
#endif
return 0;
}
//Designed by wolf
//Fri Apr 24 2015