UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206985#3702. 第 k 长边one_zero_four_zero1007890ms21700kbC++111.7kb2024-07-26 18:29:522024-07-26 20:23:38

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

struct edge{
	int v, w, nxt;
};

int n, m, k, pos = 1;
int l, r, ans = 0;
int u[1000006], v[1000006], w[1000006];
int head[300005];
edge E[2000006];
int dis[300005];

void addedge(int u, int v, int w){
	// cout << u << " " << v << " " << w << "[]\n";
	E[++ pos] = {v, w, head[u]};
	head[u] = pos;
}

void dijkstra(int s){
	memset(dis, 0x3f, sizeof(dis));
	queue<int> q0, q1;
	q0.push(s);
	dis[s] = 0;
	while (q0.size() || q1.size()){
		int u;
		if (q0.size()){
			u = q0.front();
			q0.pop();
		}else{
			u = q1.front();
			q1.pop();
		}
		// cout << u << "           " << dis[u] << "\n";
		for (int i = head[u]; i; i = E[i].nxt){
			int v = E[i].v, w = E[i].w;
			if (dis[v] <= dis[u] + w) continue;
			dis[v] = min(dis[v], dis[u] + w);
			// cout << v << " " << dis[v] << "\n";
			if (w == 0) q0.push(v);
			else q1.push(v);
		}
	}
}

bool solve(int x){ // (>= x)num <= k
	// cout << x << ";;;\n";
	pos = 1;
	memset(head, 0, sizeof(head));
	for (int i = 0; i < m; i ++){
		addedge(u[i], v[i], (w[i] > x));
		addedge(v[i], u[i], (w[i] > x));
	}
	dijkstra(1);
	if (dis[n] < k) return 1;
	return 0;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("../data.in","r",stdin);
    freopen("../data.out","w",stdout);
#endif

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < m; i ++){
		scanf("%d %d %d", &u[i], &v[i], &w[i]);
		r = max(r, w[i]);
	}
	// cout << l << " " << r << "\n";
	while (l <= r){
		int mid = (l + r) >> 1;
		if (solve(mid)){
			ans = mid;
			r = mid - 1;
		}else{
			l = mid + 1;
		}
	}
	printf("%d\n", ans);

    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 287ms
memory: 10764kb

input:

100000 200000 1
66332 85108 35698
3888 79234 75540
43380 55729 412144
70852 37196 256473
50240 83227...

output:

445428

result:

ok "445428"

Test #2:

score: 5
Accepted
time: 258ms
memory: 10764kb

input:

100000 200000 1
76361 36908 63886
56791 45674 212482
27085 35684 448957
86126 28772 70006
49753 5684...

output:

486166

result:

ok "486166"

Test #3:

score: 5
Accepted
time: 261ms
memory: 10792kb

input:

100000 200000 1
87585 94931 267762
88805 66240 167136
36548 81198 38228
14004 56943 471433
86882 746...

output:

492887

result:

ok "492887"

Test #4:

score: 5
Accepted
time: 369ms
memory: 10764kb

input:

100000 200000 1
2998 26035 279980
76809 38839 64822
75970 88409 381888
45463 95663 186716
98377 7497...

output:

463373

result:

ok "463373"

Test #5:

score: 5
Accepted
time: 114ms
memory: 10696kb

input:

100000 200000 70
97806 53614 1
75296 32201 1
82031 19131 1
52058 41592 1
42403 79220 1
11603 21762 1...

output:

1

result:

ok "1"

Test #6:

score: 5
Accepted
time: 108ms
memory: 10700kb

input:

100000 200000 140
87420 31217 1
39250 87608 1
83749 61430 1
20448 27699 1
97226 38931 1
13334 3690 1...

output:

1

result:

ok "1"

Test #7:

score: 5
Accepted
time: 111ms
memory: 10692kb

input:

100000 200000 210
33278 74385 1
13620 93434 1
33535 61158 1
16307 43741 1
99750 16939 1
98725 39413 ...

output:

1

result:

ok "1"

Test #8:

score: 5
Accepted
time: 91ms
memory: 10696kb

input:

100000 200000 280
89005 20140 1
19278 71310 1
23637 87161 1
81129 30437 1
2302 84054 1
53310 80940 1...

output:

0

result:

ok "0"

Test #9:

score: 5
Accepted
time: 203ms
memory: 7232kb

input:

50000 100000 63
45498 2888 349737
24050 21882 228959
6889 36868 482050
38665 15996 167370
44458 4832...

output:

0

result:

ok "0"

Test #10:

score: 5
Accepted
time: 179ms
memory: 7244kb

input:

50000 100000 77
6310 10228 266055
48816 47660 354374
31859 11403 354923
20966 36238 340819
38836 251...

output:

148567

result:

ok "148567"

Test #11:

score: 5
Accepted
time: 138ms
memory: 7236kb

input:

50000 100000 13
17690 41876 460912
37559 14078 143186
8004 42028 429963
9603 38308 415499
17501 1578...

output:

444893

result:

ok "444893"

Test #12:

score: 5
Accepted
time: 138ms
memory: 7236kb

input:

50000 100000 24
29215 15038 382777
13419 46211 341730
41841 7895 430035
42870 46464 3962
26373 23444...

output:

86717

result:

ok "86717"

Test #13:

score: 5
Accepted
time: 126ms
memory: 8888kb

input:

50000 100000 62
1584 24702 476570
35179 22159 309620
31315 12615 92074
21999 27821 172466
32221 4215...

output:

0

result:

ok "0"

Test #14:

score: 5
Accepted
time: 128ms
memory: 7240kb

input:

50000 100000 94
46833 32792 20248
20352 17139 256201
14719 19544 479866
15250 37595 296241
7920 1213...

output:

0

result:

ok "0"

Test #15:

score: 5
Accepted
time: 64ms
memory: 5360kb

input:

50000 49999 25000
23959 4002 42712
38315 4823 21915
33814 37514 63898
34124 25290 19703
17362 13295 ...

output:

50260

result:

ok "50260"

Test #16:

score: 5
Accepted
time: 55ms
memory: 5356kb

input:

50000 49999 50000
28809 19135 35553
10787 46022 95925
11967 41522 98364
47296 31859 17008
39692 3488...

output:

0

result:

ok "0"

Test #17:

score: 5
Accepted
time: 1195ms
memory: 21700kb

input:

300000 500000 57
248882 137472 164097
244787 185937 99341
40735 278288 201081
289810 78443 206698
25...

output:

331007

result:

ok "331007"

Test #18:

score: 5
Accepted
time: 1570ms
memory: 21652kb

input:

300000 500000 68
160126 174330 199922
263067 262654 3340
232608 156376 256015
50480 127962 89532
249...

output:

183138

result:

ok "183138"

Test #19:

score: 5
Accepted
time: 1882ms
memory: 21696kb

input:

300000 500000 34
201526 88879 246119
229908 3956 311605
244466 66580 374145
65656 262873 220441
2104...

output:

351125

result:

ok "351125"

Test #20:

score: 5
Accepted
time: 613ms
memory: 14148kb

input:

299999 300000 38
268237 61775 186591
57805 205010 234316
211587 38410 14580
219074 182750 431026
133...

output:

499942

result:

ok "499942"