QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560176#8673. 最短路径Hridaya0 3862ms222080kbC++146.1kb2024-09-12 14:00:562024-09-12 14:00:56

Judging History

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

  • [2024-09-12 14:00:56]
  • 评测
  • 测评结果:0
  • 用时:3862ms
  • 内存:222080kb
  • [2024-09-12 14:00:56]
  • 提交

answer

// Writer: Hridaya   Time:2024.9.12   By:NFLS
/********************************************/
// #pragma GCC optimize(3,"Ofast","inline")
// #include <iostream>       // cin, cout, cerr, getline
#include <bits/stdc++.h>
// #include <utility>        // pair, make_pair, swap, move
// #include <ctime>          // clock, time, difftime, tm, localtime
// #include <unordered_map>  // unordered_map, unordered_multimap
// #include <unordered_set>  // unordered_set, unordered_multiset
// #include <algorithm>      // sort, find, reverse, binary_search, max_element, min_element
// #include <ios>            // ios_base, ios_base::failure, ios::sync_with_stdio
// #include <vector>         // vector, vector::push_back, vector::size, vector::at
// #include <bitset>         // bitset, bitset::set, bitset::reset
// #include <cstring>        // memset, memcpy, strcmp, strlen
// #include <map>            // map, multimap, map::insert
// #include <set>            // set, multiset, set::insert
// #include <queue>          // queue, priority_queue
// #include <stack>          // stack, stack::push, stack::pop
// #include <deque>          // deque, deque::push_back, deque::pop_front
// #include <list>           // list, list::push_back, list::remove
// #include <cmath>          // sqrt, pow, sin, cos, log
// #include <cstddef>        // size_t, ptrdiff_t
// #include <cstdll>        // ll8_t, ll16_t, ll32_t, ll64_t, ull8_t, ull16_t, ull32_t, ull64_t
// #include <climits>        // INT_MAX, CHAR_MIN
// #include <iterator>       // iterator, advance, next, prev
// #include <chrono>         // chrono::steady_clock, chrono::system_clock, chrono::duration
// #include <fstream>        // ifstream, ofstream, fstream
using namespace std;
typedef long long ll;
#define foru(i,x,y) for (register ll i(x); i <= y; ++i)
#define ford(i,x,y) for (register ll i(x); i >= y; --i)
#define Linf 9223372036854775807
#define Iinf 2147483647
#define Sinf 32767
namespace IO {
	char ch ('~');
	template<typename Type>
	inline Type read() {
		Type x(0);
		bool m(0);
		while (!isdigit(ch)) {
			m |= (ch == '-');
			ch = getchar(); }
		while (isdigit(ch)) {
			x = (x << 1) + (x << 3) + (ch ^ 48);
			ch = getchar(); }
		return m ? (~x + 1) : x; }
	template<typename Type>
	inline void write(Type x) {
		if (x < 0) putchar('-'), x = (~x + 1);
		if (x > 9) write(x / 10);
		putchar(x % 10 ^ 48); }
	template<typename Type>
	inline void writes(Type x, char c) {
		write(x), putchar(c); }
#define read() read<ll>()
#define Jianghu_bloke \
	freopen("QwQ.in", "r", stdin); freopen("QwQ.out", "w", stdout);
} using namespace IO;
#define pb emplace_back
#define fi first
#define se second
const ll N (2e5 + 10);
struct edge {
	ll u, v;
	ll w; };
std::vector<edge> generate_edges(ll n, ll m, unsigned seed) {
	std::mt19937 gen(seed);
	std::vector<edge> edges(m);
	unsigned max = -1u / n * n;
	auto sample = [&]() {
		unsigned x;
		do {
			x = gen(); }
		while (x >= max);
		return x % n + 1; };
	for (auto&e : edges) {
		e.u = sample();
		e.v = sample();
		e.w = gen(); }
	return edges; }
ll n, m, q;
ll seed;
vector<pair<ll, ll>>e[N], re[N];
ll dis[N];
ll lst[N];
std :: vector<ll> road[N];
ll lstw[N];
inline void dijkstra(ll pos) {
	priority_queue<pair<ll, ll>>pq;
	pq.push({0, pos });
	foru(i, 1, n) dis[i] = 1e18;
	vector<ll> vis(n + 1);
	dis[pos] = 0;
	while (!pq.empty()) {
		auto u = pq.top().se; pq.pop();
		if (vis[u])continue;
		if (lst[u]) road[u] = road[lst[u]], road[u].pb(u);
		vis[u] = 1;
		for (auto&E : e[u]) {
			ll to (E.fi);
			if (dis[to] > dis[u] + E.se) {
				dis[to] = dis[u] + E.se;
				pq.push({-dis[to], to });
				lstw[to] = E.se;
				lst[to] = u; } } } }
ll dis1[N], dis2[N];
ll vis[N], que[N], all, seg1[N], seg2[N], use[N];
mt19937_64 rnd;
inline ll rad(ll l, ll r) {
	return rnd() % (r - l + 1) + l; }
const ll xN = 1 << 18;
inline void upd1(ll x) {
	seg1[x + xN] = x;
	for (ll u = (x + xN) >> 1; u; u >>= 1) {
		if (dis1[x] > dis1[seg1[u]]) break;
		seg1[u] = x; } }
inline void del1(ll x) {
	seg1[x + xN] = 0;
	for (ll u = (x + xN) >> 1; u; u >>= 1)
		seg1[u] = dis1[seg1[u * 2]] < dis1[seg1[u * 2 + 1]] ? seg1[u * 2] : seg1[u * 2 + 1]; }
inline void upd2(ll x) {
	seg2[x + xN] = x;
	for (ll u = (x + xN) >> 1; u; u >>= 1) {
		if (dis2[x] > dis2[seg2[u]]) break;
		seg2[u] = x; } }
inline void del2(ll x) {
	seg2[x + xN] = 0;
	for (ll u = (x + xN) >> 1; u; u >>= 1)
		seg2[u] = dis2[seg2[u * 2]] < dis2[seg2[u * 2 + 1]] ? seg2[u * 2] : seg2[u * 2 + 1]; }
ll ban1[N], ban2[N];
const ll M = 1 << 18;
namespace Hridaya {
	inline void solve() {
		ll x (read()), y(read());
		if (x == y) return puts("0"), void();
		all = 2, que[1] = x, que[2] = y, vis[x] = vis[y] = 1;
		dis1[x] = 0, dis2[y] = 0;
		upd1(x), upd2(y);
		ll ans (Linf);
		while (1) {
			if (ans == 1e17 && (dis1[seg1[1]] > 1e17 || dis2[seg2[1]] > 1e17)) break;
			if (min(dis1[seg1[1]], dis2[seg2[1]]) * 2 >= ans) break;
			if (dis1[seg1[1]] < dis2[seg2[1]]) {
				ll u = seg1[1];
				del1(u);
				for (auto&E : e[u]) {
					ll to = E.fi;
					if (dis1[to] > dis1[u] + E.se) {
						dis1[to] = dis1[u] + E.se;
						if (!vis[to]) vis[to] = 1, que[++all] = to;
						else ans = min(ans, dis1[to] + dis2[to]);
						if (dis1[to] * 2 < ans) upd1(to); } } }
			else {
				ll u = seg2[1];
				del2(u);
				for (auto&E : re[u]) {
					ll to = E.fi;
					if (dis2[to] > dis2[u] + E.se) {
						dis2[to] = dis2[u] + E.se;
						if (!vis[to]) vis[to] = 1, que[++all] = to;
						else ans = min(ans, dis1[to] + dis2[to]);
						if (dis2[to] * 2 < ans) upd2(to); } } } }
		foru(i, 1, all) dis1[que[i]] = dis2[que[i]] = 1e18, vis[que[i]] = 0;
		writes(ans > 1e17 ? ans : -1, '\n'); }
	signed main() {
		n = read(), m = read(), q = read(), seed = read<ll>();
		auto E = generate_edges(n, m, seed);
		sort(E.begin(), E.end(), [&] (edge a, edge b) {
			return a.w < b.w; });
		for (auto&ed : E) if (ed.u != ed.v) e[ed.u].pb(ed.v, ed.w), re[ed.v].pb(ed.u, ed.w);
		foru(i, 0, n) dis1[i] = dis2[i] = 1e18;
		while (q--) solve();
		return 0; }
//	Main Space
}
signed main() {
//	Jianghu_bloke
	Hridaya :: main();
//	Coding Completed!
	return 0; }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 29068kb

input:

4 8 5 1112792816
2 3
4 3
4 3
3 2
1 4

output:

-1
-1
-1
-1
-1

result:

wrong answer 1st lines differ - expected: '3419197189', found: '-1'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 3862ms
memory: 222080kb

input:

3000 3000000 10000 37461678
2873 1368
1757 2000
1262 1822
2484 1778
2055 2096
2545 366
2923 2028
1469 1874
691 631
1173 2967
894 2020
1207 881
373 236
1913 1923
1351 16
1066 2032
471 1561
1047 2043
457 145
2728 1752
2521 1199
1568 904
2515 543
1472 2161
748 2744
748 1908
912 172
2340 2494
977 267
10...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 1st lines differ - expected: '36084543', found: '-1'

Subtask #3:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

200000 200000 10000 1824322211
104482 112162
130667 13436
36792 142259
51832 97549
15358 180076
128251 92635
45296 195115
62109 38014
22014 86754
79735 103777
94797 96086
196760 5955
45622 59618
12995 62585
55686 156402
23085 68138
170749 148553
97603 160274
112975 22651
116322 190720
84774 57075
23...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

input:

200000 500000 10000 3113327438
68816 31422
174349 125983
18111 188786
84806 87249
142007 180723
95611 116398
104758 196349
77547 89859
120350 77199
110906 10209
177461 194861
115505 105566
27493 166237
15676 158290
86204 116010
159979 125659
132461 61989
194289 157721
18830 82910
166696 98162
125208...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

200000 500000 10000 1843053063
3409 108359
168924 184622
13119 119837
109492 38050
97152 51201
49047 12472
183998 191613
193074 177289
194248 104409
15509 88499
61967 143398
4532 56790
196650 158711
63655 70744
140178 107299
63530 87330
127334 159237
7134 184418
125289 28604
176966 179527
181695 128...

output:


result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #24:

score: 0
Time Limit Exceeded

input:

100000 3000000 10000 3892765041
14843 34156
43390 49542
38564 95501
26194 87126
18638 53346
69414 47011
95472 58303
44370 77172
75652 90555
94386 31888
47911 9905
70599 97061
52764 24896
31445 15589
82314 43852
97155 93412
11834 45082
75614 42459
67802 32024
82389 4968
32860 62514
97630 28012
14839 ...

output:


result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #33:

score: 0
Time Limit Exceeded

input:

200000 3000000 10000 3910662331
161257 40967
50546 86049
199665 199302
177403 36274
158790 143151
193304 78511
28032 149723
96394 37099
2157 76024
195400 34830
41933 147591
191613 96468
194837 67293
57992 63117
24749 6694
117818 87323
46130 53470
174812 24950
149173 124886
119910 54123
2297 124533
5...

output:


result: