結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー |
|
提出日時 | 2023-01-26 17:56:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,579 bytes |
コンパイル時間 | 2,345 ms |
コンパイル使用メモリ | 199,048 KB |
最終ジャッジ日時 | 2025-02-10 07:02:39 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 TLE * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back using vi = vector <int>; using ll = long long; using pii = pair <int, int>; const ll mod = 998244353; //~ const ll mod = 1e9 + 7; ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a; for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; } const int N = 1e5 + 11; const int M = N * 8; struct edge { int u, v, f; ll c; }e[M]; int ecnt = 0; int fe[N], ne[M]; void add(int u, int v, int f, ll c) { e[ecnt] = {u, v, f, c}; ne[ecnt] = fe[u]; fe[u] = ecnt ++; e[ecnt] = {v, u, 0, -c}; ne[ecnt] = fe[v]; fe[v] = ecnt ++; } ll dis[N]; bool inq[N]; const ll inf = 1e15; int p[N]; int main() { ios :: sync_with_stdio(false); int n, m; cin >> n >> m; memset(fe, -1, sizeof fe); memset(ne, -1, sizeof ne); for(int i = 1; i <= m; i ++) { int u, v; ll c, d; cin >> u >> v >> c >> d; add(u, v, 1, c); add(v, u, 1, c); add(u, v, 1, d); add(v, u, 1, d); } ll ans = 0; for(int t : {0, 1}) { fill(dis, dis + n + 1, inf); dis[1] = 0; inq[1] = 1; queue <int> q; q.push(1); while(!q.empty()) { int x = q.front(); q.pop(); inq[x] = 0; for(int i = fe[x]; i != -1; i = ne[i]) if(e[i].f) { if(dis[x] + e[i].c < dis[e[i].v]) { dis[e[i].v] = dis[x] + e[i].c; p[e[i].v] = i; if(!inq[e[i].v]) { q.push(e[i].v); inq[e[i].v] = 1; } } } } p[1] = -1; for(int i = p[n]; i != -1; i = p[e[i].u]) { e[i].f -= 1; e[i ^ 1].f += 1; } ans += dis[n]; } cout << ans << '\n'; }