結果

問題 No.614 壊れたキャンパス
ユーザー zimpha
提出日時 2017-12-14 00:18:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,376 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 79,996 KB
最終ジャッジ日時 2025-01-05 05:17:11
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   scanf("%d%d%d%d%d", &n, &m, &k, &s, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |     scanf("%d%d%d", &a[i], &b[i], &c[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using int64 = long long;
using pii = std::pair<int64, int>;
const int N = 2e5 + 10;
std::map<int, int> id[N];
std::vector<int> use[N];
int n, m, k, s, t, sz;
int main() {
scanf("%d%d%d%d%d", &n, &m, &k, &s, &t);
std::vector<int> a(m), b(m), c(m);
id[0][s] = 0;
id[n - 1][t] = 1;
sz = 2;
for (int i = 0; i < m; ++i) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
--a[i];
if (!id[a[i]].count(b[i])) id[a[i]][b[i]] = sz++;
if (!id[a[i] + 1].count(c[i])) id[a[i] + 1][c[i]] = sz++;
}
std::vector<std::vector<pii>> edges(sz);
for (int i = 0; i < m; ++i) {
int u = id[a[i]][b[i]];
int v = id[a[i] + 1][c[i]];
edges[u].emplace_back(v, 0);
}
for (int i = 0; i < n; ++i) {
int u = -1, d = -1;
for (auto &&e: id[i]) {
if (u != -1) {
int v = e.second;
d = e.first - d;
edges[u].emplace_back(v, d);
edges[v].emplace_back(u, d);
}
std::tie(d, u) = e;
}
}
std::vector<int64> dis(sz, -1);
std::priority_queue<pii, std::vector<pii>, std::greater<pii>> pq;
pq.emplace(0, 0);
dis[0] = 0;
while (!pq.empty()) {
auto now = pq.top();
pq.pop();
int u = now.second;
if (dis[u] < now.first) continue;
for (auto &&e: edges[u]) {
int v = e.first, w = e.second;
if (dis[v] == -1 || dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
pq.emplace(dis[v], v);
}
}
}
printf("%lld\n", dis[1]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1