結果
| 問題 |
No.416 旅行会社
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-08-26 23:53:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,428 bytes |
| コンパイル時間 | 2,989 ms |
| コンパイル使用メモリ | 103,972 KB |
| 実行使用メモリ | 31,040 KB |
| 最終ジャッジ日時 | 2024-11-08 16:37:07 |
| 合計ジャッジ時間 | 7,289 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 8 |
ソースコード
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long W;
const W INF = 1 << 25;
struct edge {
int to;
W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;
void dijkstra(int s, const Graph& G, vector<W>& d) {
priority_queue<P> que;
fill(d.begin(), d.end(), -1);
d[s] = INF;
que.push(P(INF, s));
while(!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if(d[v] > p.first) continue;
for(int i = 0; i < G[v].size(); i++) {
edge e = G[v][i];
if(d[e.to] < min(d[v], e.cost)) {
d[e.to] = min(d[v], e.cost);
que.push(P(d[e.to], e.to));
}
}
}
}
const int MAX = 100010;
int N, M, Q;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
map<P, int> m;
cin >> N >> M >> Q;
for(int i = 0; i < M; i++) {
int A, B;
cin >> A >> B;
m[P(A, B)] = INF;
}
for(int i = 1; i <= Q; i++) {
int A, B;
cin >> A >> B;
m[P(A, B)] = i;
}
Graph G(N);
for(auto val : m) {
int A = val.first.first, B = val.first.second;
int T = val.second;
G[A - 1].push_back(edge{ B - 1, T });
G[B - 1].push_back(edge{ A - 1, T });
}
vector<W> d(N);
dijkstra(0, G, d);
for(int i = 1; i < N; i++) {
if(d[i] == INF) {
cout << -1 << endl;
}
else {
cout << d[i] << endl;
}
}
}
femto