結果

問題 No.1301 Strange Graph Shortest Path
ユーザー rabimearabimea
提出日時 2023-01-26 17:56:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,579 bytes
コンパイル時間 2,923 ms
コンパイル使用メモリ 202,676 KB
実行使用メモリ 34,624 KB
最終ジャッジ日時 2023-09-09 17:59:01
合計ジャッジ時間 14,903 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
34,624 KB
testcase_01 AC 3 ms
8,440 KB
testcase_02 AC 140 ms
25,560 KB
testcase_03 AC 120 ms
23,376 KB
testcase_04 AC 139 ms
26,784 KB
testcase_05 AC 132 ms
25,504 KB
testcase_06 AC 136 ms
25,336 KB
testcase_07 AC 133 ms
25,468 KB
testcase_08 AC 133 ms
23,684 KB
testcase_09 AC 130 ms
24,428 KB
testcase_10 AC 117 ms
23,544 KB
testcase_11 AC 124 ms
25,888 KB
testcase_12 AC 129 ms
25,888 KB
testcase_13 AC 143 ms
26,000 KB
testcase_14 AC 103 ms
24,364 KB
testcase_15 AC 109 ms
24,388 KB
testcase_16 AC 128 ms
26,996 KB
testcase_17 AC 134 ms
26,216 KB
testcase_18 AC 118 ms
24,472 KB
testcase_19 AC 126 ms
25,320 KB
testcase_20 AC 117 ms
25,164 KB
testcase_21 AC 131 ms
25,856 KB
testcase_22 AC 101 ms
25,740 KB
testcase_23 AC 134 ms
25,916 KB
testcase_24 AC 104 ms
25,236 KB
testcase_25 AC 127 ms
26,644 KB
testcase_26 AC 113 ms
25,264 KB
testcase_27 AC 112 ms
25,640 KB
testcase_28 AC 120 ms
25,012 KB
testcase_29 AC 120 ms
26,724 KB
testcase_30 AC 128 ms
26,492 KB
testcase_31 AC 123 ms
26,472 KB
testcase_32 AC 3 ms
7,024 KB
testcase_33 AC 60 ms
26,348 KB
testcase_34 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0