QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#172622#7048. Delivery Routeneko_nyaa#TL 43ms7044kbC++231.5kb2023-09-09 19:59:272023-09-09 19:59:27

Judging History

你现在查看的是最新测评结果

  • [2023-09-09 19:59:27]
  • 评测
  • 测评结果:TL
  • 用时:43ms
  • 内存:7044kb
  • [2023-09-09 19:59:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e18;
const int MAXN = 25001;

int n, x, y, s;
vector<pair<int, int>> adj1[MAXN], adj2[MAXN];

vector<int> dist;
vector<int> djs;
vector<int> toResolve;

void dijkstra() {
	priority_queue<pair<int, int>> pq;
	for (int i: djs) {
		pq.push({-dist[i], i});
	}
	djs.clear();

	while (pq.size()) {
		auto [ds, u] = pq.top(); pq.pop();
		if (dist[u] != -ds) continue;

		toResolve.push_back(u);
		for (auto [v, w]: adj1[u]) {
			if (dist[v] > dist[u] + w) {
				dist[v] = dist[u] + w;
				pq.push({-dist[v], v});
			}
		}
	}
}

void resolve() {
	set<int> djss;
	for (int u: toResolve) {
		for (auto [v, w]: adj2[u]) {
			if (dist[v] > dist[u] + w) {
				dist[v] = dist[u] + w;
				djss.insert(v);
			}
		}
	}
	for (int i: djss) djs.push_back(i);
	toResolve.clear();
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> x >> y >> s;
	for (int i = 0; i < x; i++) {
		int a, b, c; cin >> a >> b >> c;
		adj1[a].emplace_back(b, c);
		adj1[b].emplace_back(a, c);
	}
	for (int i = 0; i < y; i++) {
		int a, b, c; cin >> a >> b >> c;
		adj2[a].emplace_back(b, c);
	}

	dist.resize(MAXN, INF);
	dist[s] = 0; djs.push_back(s);

	while (1) {
		dijkstra();
		if (toResolve.size()) resolve();
		else break;
	}

	for (int i = 1; i <= n; i++) {
		if (dist[i] == INF) {
			cout << "NO PATH\n";
		} else {
			cout << dist[i] << '\n';
		}
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 4748kb

input:

6 3 3 4
1 2 5
3 4 5
5 6 10
3 5 -100
4 6 -100
1 3 -10

output:

NO PATH
NO PATH
5
0
-95
-100

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 4792kb

input:

100 500 500 4
13 20 329
41 10 63
100 90 297
15 79 163
24 67 747
29 68 443
73 98 565
10 41 921
79 62 973
31 85 270
25 29 672
34 43 391
30 92 604
58 82 90
28 16 460
53 63 350
91 98 260
70 22 232
5 36 335
37 32 339
4 48 940
85 1 233
95 78 323
62 79 688
49 57 576
10 54 103
33 78 541
88 22 171
4 48 408
2...

output:

-3619
-3536
NO PATH
0
NO PATH
-7205
-6588
-2243
-2898
-691
-6755
-710
-4236
-3929
-941
-4827
-4796
NO PATH
-6827
-4246
-4759
-1991
-5025
-1522
-6643
-6453
-3084
-4740
-6448
-5552
-3800
-2700
-7006
-3915
-433
NO PATH
-2767
NO PATH
158
-2524
-628
-7166
-3859
-2838
-2168
-7106
-2726
112
-3844
544
-3860...

result:

ok 100 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 4748kb

input:

50 100 50 24
26 39 94
44 42 47
15 39 28
10 25 37
28 12 3
36 22 34
9 36 74
28 12 35
25 22 63
48 7 86
29 37 69
9 10 4
36 9 31
28 34 54
6 1 89
33 25 17
36 10 47
5 35 9
7 14 65
44 50 96
31 1 35
37 29 4
28 34 27
35 18 74
34 8 37
13 17 2
19 48 47
20 43 98
26 16 91
13 29 63
20 43 48
5 35 54
39 15 69
10 33 ...

output:

NO PATH
-3
NO PATH
NO PATH
-126
NO PATH
-2
-98
-66
-62
-38
-144
51
15
NO PATH
NO PATH
49
-43
-5
NO PATH
67
-79
NO PATH
0
-64
NO PATH
-57
-141
114
-73
NO PATH
27
-81
-114
-117
-45
118
NO PATH
NO PATH
-85
NO PATH
-94
NO PATH
-47
-35
NO PATH
-91
-15
-57
-52

result:

ok 50 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 4948kb

input:

300 2000 1000 208
251 61 2246
22 3 3153
81 124 1726
77 280 4372
14 169 592
186 46 4946
146 128 4639
148 296 2647
283 120 4786
197 139 435
59 89 4916
231 38 506
182 56 623
283 225 3941
298 117 3457
141 24 1734
18 10 1102
86 45 813
261 271 2541
19 263 3219
250 260 3725
131 298 110
285 237 331
292 184 ...

output:

-41459
-14899
-27143
-9932
-10727
-18844
-27091
-10217
-7973
1635
-5432
-29336
-10123
-10958
-6204
-18534
-38070
1002
-2183
1288
-27814
-27410
-38724
-33495
-39524
-26651
-7308
-13916
-29867
-37448
-13090
-28028
-10532
-7565
7438
-18717
-37908
-34214
-1458
-7125
-43190
-7876
-39417
-10082
-25107
-63...

result:

ok 300 lines

Test #5:

score: 0
Accepted
time: 43ms
memory: 7044kb

input:

5000 30000 30000 617
2616 3637 3037
1979 3188 582
3728 2476 2258
27 928 3410
4874 2914 1786
2307 916 4445
2888 299 1338
4271 9 328
3334 3112 2859
622 3874 2702
2754 1859 9598
2143 4393 2760
3714 4390 9070
205 1820 9332
2148 2583 2933
3483 4113 8894
1181 4261 7130
4053 1552 4229
4895 3533 2174
4893 1...

output:

-67443
-313642
-198812
NO PATH
-216061
NO PATH
-354020
-167160
NO PATH
NO PATH
NO PATH
-123407
-136971
-153815
-163001
-310206
-266785
NO PATH
-11515
NO PATH
NO PATH
NO PATH
NO PATH
-313978
-137141
-177928
NO PATH
-117014
-255677
-301218
-50350
-24831
-234306
NO PATH
-116670
-159417
NO PATH
-94986
-...

result:

ok 5000 lines

Test #6:

score: 0
Accepted
time: 19ms
memory: 6752kb

input:

2500 25000 15000 1749
1794 1219 7486
2500 487 9275
288 417 4197
588 2409 3850
2037 2028 414
2045 1288 9326
1926 2297 1441
1226 1936 1740
2410 2164 6243
27 1765 2837
217 1152 8208
1856 1256 3484
2443 1506 7334
1979 397 8827
376 678 8152
2301 2161 672
830 1576 6517
1248 2065 4590
1708 362 1039
231 649...

output:

-239558
-295742
-151871
-235692
-118055
-91058
-176020
-122338
NO PATH
-152392
-159368
-206987
-52416
-18945
-248020
NO PATH
-308703
-163929
-269618
-280507
NO PATH
-332401
-256172
-59263
-5461
-39362
-64505
-194785
-57959
-203148
-159121
-265319
-27698
NO PATH
-123225
-218853
-92677
-256479
NO PATH...

result:

ok 2500 lines

Test #7:

score: 0
Accepted
time: 2ms
memory: 4996kb

input:

20 30 10 10
3 20 4
20 3 6
8 1 0
2 4 10
16 8 7
6 16 2
19 11 6
20 3 1
18 16 10
8 12 5
10 12 1
4 7 7
1 16 10
14 3 6
1 8 5
10 8 1
9 4 2
18 1 8
10 18 8
11 19 9
14 15 5
14 20 4
7 9 10
10 16 3
13 3 0
10 12 7
11 19 10
12 10 5
3 20 3
20 13 10
9 19 2
12 15 -7
14 9 -1
16 5 -4
3 5 5
16 4 -7
16 15 -8
8 3 -2
17 6...

output:

1
6
-1
-4
-1
5
3
1
-2
0
6
1
-1
-1
-6
3
NO PATH
8
0
0

result:

ok 20 lines

Test #8:

score: -100
Time Limit Exceeded

input:

25000 1 50000 24312
24312 24433 8144
17265 22370 -4283
10464 19237 2138
11021 7812 5792
4199 954 5726
16276 5915 7598
6844 15815 3315
18963 4081 -1786
5533 13800 -4801
8530 2328 7922
16812 4440 -7840
3784 13623 1986
15402 17569 699
14562 22034 3476
22451 14926 6985
8086 22571 -9299
18380 1806 -2447
...

output:


result: