Submission #44670
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <bits/stdc++.h> using namespace std; #define FOR(i,n) for(int i=0;i<n;i++) #define why(n,x) int n;while(cin >>n,n!=x) #define iFOR(i,x,n)for(int i=x;i<n;i++) #define unless(flg) if ( !(flg) ) #define read cin<< #define echo cout<< #define fin <<'\n' #define __ <<" "<< #define bash push_back #define all(x) x.begin(),x.end() int dx[]={1,0,-1,0,1,1,-1,-1}; int dy[]={0,-1,0,1,-1,1,-1,1}; const int INF=1 << 30; bool inside( int x, int y, int w, int h){ return (x>=0 && y>=0 && x<w && y<h);} typedef long long ll; typedef pair< int , int > pii; typedef vector< int > vit; typedef map<string, int > mstit; typedef priority_queue< int > pqit; vector<pii> edge[100010]; int costs[100010]; bool used[100010]; int main(){ cin.tie(0), ios::sync_with_stdio( false ); int n,m; cin >> n >> m; for ( int i=1;i<=n;i++) costs[i] = INF; for ( int i=0;i<m;i++){ int a,b,c; cin >> a >> b >> c; edge[a].push_back(make_pair(b,c)); edge[b].push_back(make_pair(a,c)); } priority_queue< pii,vector<pii>,greater<pii> >pQue; pQue.push(make_pair(0,1)); while (!pQue.empty()){ pii now=pQue.top(); int cost=now.first; int pos=now.second; pQue.pop(); if (used[pos]) continue ; used[pos] = true ; for ( int i=0;i<edge[pos].size();i++){ int next=edge[pos][i].first; int next_cost=edge[pos][i].second; if (cost+next_cost<(costs[next])){ costs[next]=cost+next_cost; pQue.push(make_pair(costs[next],next)); } } } if (costs[n] == INF ){ cout << "NA\n" ; } else { cout << costs[n] << '\n' ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0431 - 君も始めようダイクストラ大好き厨 |
ユーザー名 | ei1821 |
投稿日時 | 2018-11-11 20:06:21 |
言語 | C++14 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 1656 Byte |
最大実行時間 | 63 ms |
最大メモリ使用量 | 7004 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
m_in1.txt | AC | 63 ms | 7004 KB |
1
|
r_in1.txt | AC | 36 ms | 3836 KB |
1
|
r_in2.txt | AC | 33 ms | 3768 KB |
1
|
r_in3.txt | AC | 36 ms | 3840 KB |
1
|
r_in4.txt | AC | 36 ms | 3644 KB |
1
|
r_in5.txt | AC | 36 ms | 4184 KB |
1
|
r_in6.txt | AC | 32 ms | 3932 KB |
1
|
r_in7.txt | AC | 24 ms | 3412 KB |
1
|
r_in8.txt | AC | 32 ms | 3636 KB |
1
|
r_in9.txt | AC | 38 ms | 4312 KB |
1
|
r_in10.txt | AC | 26 ms | 3384 KB |
1
|
r_in11.txt | AC | 29 ms | 3808 KB |
1
|
r_in12.txt | AC | 30 ms | 3656 KB |
1
|
r_in13.txt | AC | 36 ms | 3728 KB |
1
|
r_in14.txt | AC | 33 ms | 3864 KB |
1
|
r_in15.txt | AC | 26 ms | 3944 KB |
1
|
r_in16.txt | AC | 33 ms | 3608 KB |
1
|
r_in17.txt | AC | 28 ms | 3608 KB |
1
|
r_in18.txt | AC | 27 ms | 3684 KB |
1
|
r_in19.txt | AC | 26 ms | 3200 KB |
1
|
r_in20.txt | AC | 28 ms | 3388 KB |
1
|
r_in21.txt | AC | 27 ms | 3156 KB |
1
|
r_in22.txt | AC | 24 ms | 3208 KB |
1
|
r_in23.txt | AC | 30 ms | 3424 KB |
1
|
r_in24.txt | AC | 29 ms | 3460 KB |
1
|
r_in25.txt | AC | 28 ms | 3312 KB |
1
|
r_in26.txt | AC | 32 ms | 3460 KB |
1
|
r_in27.txt | AC | 29 ms | 3628 KB |
1
|
r_in28.txt | AC | 32 ms | 3616 KB |
1
|
r_in29.txt | AC | 32 ms | 3696 KB |
1
|
r_in30.txt | AC | 34 ms | 3672 KB |
1
|