結果
問題 | No.1601 With Animals into Institute |
ユーザー |
|
提出日時 | 2021-07-10 14:07:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 548 ms / 3,000 ms |
コード長 | 1,826 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 111,032 KB |
最終ジャッジ日時 | 2025-01-23 00:03:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | scanf("%d %d %d %d", &a, &b, &c, &x); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using uint = unsigned; using ull = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <typename T> struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; template <typename T> vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){ auto n = G.size(); vector<T> d(n, INF<T>); priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q; d[s] = 0; Q.emplace(0, s); while(!Q.empty()){ T cost; int i; tie(cost, i) = Q.top(); Q.pop(); if(d[i] < cost) continue; for (auto &&e : G[i]) { auto cost2 = cost + e.cost; if(d[e.to] <= cost2) continue; d[e.to] = cost2; Q.emplace(d[e.to], e.to); } } return d; } int main() { int n, m; cin >> n >> m; vector<vector<edge<ll>>> G(2*n); for (int i = 0; i < m; ++i) { int a, b, c, x; scanf("%d %d %d %d", &a, &b, &c, &x); a--; b--; if(x){ G[a].emplace_back(b+n, c); G[b].emplace_back(a+n, c); G[a+n].emplace_back(b+n, c); G[b+n].emplace_back(a+n, c); }else { G[a].emplace_back(b, c); G[b].emplace_back(a, c); G[a+n].emplace_back(b+n, c); G[b+n].emplace_back(a+n, c); } } auto d = dijkstra(n-1, G); for (int i = 0; i < n-1; ++i) { printf("%lld\n", d[i+n]); } return 0; }