結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
dsaito11
|
| 提出日時 | 2019-08-06 17:47:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,989 bytes |
| コンパイル時間 | 1,033 ms |
| コンパイル使用メモリ | 93,936 KB |
| 実行使用メモリ | 16,880 KB |
| 最終ジャッジ日時 | 2024-07-18 14:12:55 |
| 合計ジャッジ時間 | 6,798 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 17 |
ソースコード
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
typedef pair<int, int> P;
typedef struct edge{
int to;
int cost;
} edge;
vector<edge> graph[100010];
long long int d[2][100010];
void dijkstra(int s){
typedef pair<int, P> T; //pair<頂点までの距離, チケット残り, 頂点>
priority_queue<T, vector<T>, greater<T> > que;
for(int i = 0; i < 100010; i++){
d[0][i] = INF;
d[1][i] = INF;
}
d[1][s] = 0;
d[0][s] = 0;
que.push(T(0, P(1, s)));
que.push(T(0, P(0, s)));
while(!que.empty()){
T t = que.top();
que.pop();
long long int dist = t.first;
int state = t.second.first;
int v = t.second.second;
if(dist > d[state][v]) continue;
for(int i = 0; i < graph[v].size(); i++){
edge e = graph[v][i];
if(d[state][e.to] > dist + e.cost){
d[state][e.to] = dist + e.cost;
que.push(T(d[state][e.to], P(state, e.to)));
}
}
if(state == 1){
for(int i = 0; i < graph[v].size(); i++){
edge e = graph[v][i];
if(d[0][e.to] > dist + 0){
d[0][e.to] = dist + 0;
que.push(T(d[0][e.to], P(0, e.to)));
}
}
}
}
}
int main() {
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int s, t;
long long int c;
cin >> s >> t >> c;
s--;
t--;
edge e;
e.to = t; e.cost = c; graph[s].push_back(e);
e.to = s; e.cost = c; graph[t].push_back(e);
}
dijkstra(0);
for(int i = 0; i < n; i++){
cout << d[0][i] + d[1][i] << endl;
}
}
dsaito11