結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2020-11-27 22:24:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,680 bytes |
| コンパイル時間 | 3,203 ms |
| コンパイル使用メモリ | 208,768 KB |
| 最終ジャッジ日時 | 2025-01-16 07:47:16 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:96:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
96 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:101:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
101 | scanf("%d%d%lld%lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;
template <typename T>
struct edge {
int from, to, id;
T cost[2];
edge(int f, int t, T c, T d, int i = 0) : from(f), to(t), id(i) {
cost[0] = c;
cost[1] = d;
}
};
template <typename T>
struct Graph {
vector<vector<edge<T>>> G;
int n;
Graph(int n_) : n(n_) { G.resize(n); }
void add_edge(int f, int t, T c, T d, int i = 0) {
G[f].emplace_back(f, t, c, d, i);
}
};
int used[MAX];
template <typename T>
pair<vector<T>, vector<pii>> dijkstra(Graph<T> &gr, int s) {
using state = pair<T, int>;
priority_queue<state, vector<state>, greater<state>> que;
vector<T> d(gr.n, numeric_limits<T>::max());
vector<pii> pe(gr.n);
d[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
state p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first) continue;
for (edge<T> &e : gr.G[v]) {
if (d[e.to] > d[v] + e.cost[used[e.id]]) {
d[e.to] = d[v] + e.cost[used[e.id]];
pe[e.to] = {e.id, v};
que.emplace(d[e.to], e.to);
}
}
}
return {d, pe};
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
Graph<lint> gr(n);
rep(i, m) {
int a, b;
lint c, d;
scanf("%d%d%lld%lld", &a, &b, &c, &d);
--a;
--b;
gr.add_edge(a, b, c, d, i);
gr.add_edge(b, a, c, d, i);
}
auto [d, pe] = dijkstra(gr, 0);
int v = n - 1;
while (v != 0) {
used[pe[v].fi] = 1;
v = pe[v].se;
}
auto [d2, pe2] = dijkstra(gr, n - 1);
printf("%lld\n", d[n - 1] + d2[0]);
}
Ricky_pon