結果
| 問題 |
No.416 旅行会社
|
| ユーザー |
ant2357
|
| 提出日時 | 2018-02-23 00:03:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 536 ms / 4,000 ms |
| コード長 | 1,140 bytes |
| コンパイル時間 | 2,346 ms |
| コンパイル使用メモリ | 211,316 KB |
| 最終ジャッジ日時 | 2025-01-05 08:26:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<map<int, int>> g(n);
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
a--; b--;
g[a][b] = g[b][a] = INF;
}
for (int i = 0; i < q; i++) {
int c, d;
cin >> c >> d;
c--; d--;
g[c][d] = g[d][c] = i + 1;
}
priority_queue<pair<int, int>> pq;
vector<int> ans(n);
ans[0] = INF;
pq.emplace(INF, 0);
vector<bool> used(n);
while (!pq.empty()) {
int c = pq.top().first;
int i = pq.top().second;
pq.pop();
if (used[i]) {
continue;
}
used[i] = true;
for (auto p : g[i]) {
int j = p.first;
int cc = p.second;
if (ans[j] < min(ans[i], cc)) {
ans[j] = min(ans[i], cc);
pq.emplace(ans[j], j);
}
}
}
for (int i = 1; i < n; i++) {
cout << (ans[i] == INF ? -1 : ans[i]) << endl;
}
return 0;
}
ant2357