UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213263#3848. 赏花one_zero_four_zero1001152ms16796kbC++112.1kb2024-11-10 10:12:032024-11-10 13:04:53

answer

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

struct edge{
	int u, v, c;
};

int N, M, DIS, ans = 0;
edge Edge[200005];
vector<edge> E[100005];
int dis[100005];
bool vis[100005];
int minn[100005];
int remdis[2][100005], remminn[2][100005];

void dijkstra(int st){
	memset(vis, 0, sizeof(vis));
	memset(dis, 0x3f, sizeof(dis));
	memset(minn, 0x3f, sizeof(minn));
	dis[st] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
	q.push({0, st});
	while (!q.empty()){
		int u = q.top().second;
		q.pop();
		if (vis[u]) continue;
		// cout << u << " " << dis[u] << " " << minn[u] << ";;\n";
		vis[u] = 1;
		for (auto && i : E[u]){
			int v = i.v, c = i.c;
			if (dis[u] + 1 > dis[v]) continue;
			if (dis[u] + 1 == dis[v]){
				minn[v] = min(minn[v], min(minn[u], c));
			}else{
				minn[v] = min(minn[u], c);
			}
			dis[v] = dis[u] + 1;
			q.push({dis[v], v});
		}
	}
}

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

	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i ++){
		scanf("%d %d %d", &Edge[i].u, &Edge[i].v, &Edge[i].c);
		E[Edge[i].u].push_back({Edge[i].u, Edge[i].v, Edge[i].c});
		E[Edge[i].v].push_back({Edge[i].v, Edge[i].u, Edge[i].c});
	}
	dijkstra(1);
	DIS = dis[N];
	printf("%d ", DIS);
	for (int i = 1; i <= N; i ++) remdis[0][i] = dis[i];
	for (int i = 1; i <= N; i ++) remminn[0][i] = minn[i];
	dijkstra(N);
	for (int i = 1; i <= N; i ++) remdis[1][i] = dis[i];
	for (int i = 1; i <= N; i ++) remminn[1][i] = minn[i];
	for (int i = 0; i < M; i ++){
		int u = Edge[i].u, v = Edge[i].v, c = Edge[i].c; //  c -> maxn
		// cout << u << " " << v << " " << c << ";;\n";
		if (remdis[0][u] + 1 + remdis[1][v] == DIS){
			int pathminn = min(remminn[0][u], remminn[1][v]);
			ans = max(ans, c - pathminn);
		}
		swap(u, v);
		if (remdis[0][u] + 1 + remdis[1][v] == DIS){
			int pathminn = min(remminn[0][u], remminn[1][v]);
			ans = max(ans, c - pathminn);
		}
	}
	printf("%d\n", ans);
	

	return 0;
}

详细

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

Test #1:

score: 5
Accepted
time: 0ms
memory: 4480kb

input:

10 11
2 1 574741106
3 2 59539233
4 2 862308429
5 3 524117306
6 1 868028535
7 5 325211682
8 6 7671330...

output:

1 0

result:

ok 2 number(s): "1 0"

Test #2:

score: 5
Accepted
time: 0ms
memory: 4484kb

input:

10 15
2 1 75174859
3 1 44022787
4 3 344902330
5 3 385468404
6 3 55284058
7 4 571259734
8 1 290025036...

output:

2 668969195

result:

ok 2 number(s): "2 668969195"

Test #3:

score: 5
Accepted
time: 0ms
memory: 4488kb

input:

10 11
2 1 17549310
3 1 137754066
4 1 315298597
5 2 894276460
6 1 70207474
7 4 641548147
8 7 83616706...

output:

3 876727150

result:

ok 2 number(s): "3 876727150"

Test #4:

score: 5
Accepted
time: 0ms
memory: 4484kb

input:

10 10
2 1 717426908
3 2 251753655
4 1 471051853
5 1 263423188
6 4 86597516
7 3 838519464
8 7 4993360...

output:

4 586765809

result:

ok 2 number(s): "4 586765809"

Test #5:

score: 5
Accepted
time: 0ms
memory: 4616kb

input:

1000 1976
2 1 156495505
3 1 232064065
4 2 687004650
5 1 927793228
6 1 355172463
7 2 41211061
8 4 284...

output:

65 996764255

result:

ok 2 number(s): "65 996764255"

Test #6:

score: 5
Accepted
time: 0ms
memory: 4608kb

input:

1000 1820
2 1 274442369
3 2 611018866
4 1 498854229
5 1 149160657
6 5 190596092
7 2 437183772
8 4 95...

output:

69 981586226

result:

ok 2 number(s): "69 981586226"

Test #7:

score: 5
Accepted
time: 2ms
memory: 4612kb

input:

1000 1914
2 1 682705093
3 1 401282935
4 1 471215565
5 1 147979493
6 4 524785272
7 6 450150508
8 6 30...

output:

66 996028581

result:

ok 2 number(s): "66 996028581"

Test #8:

score: 5
Accepted
time: 40ms
memory: 9148kb

input:

1000 100000
2 1 147282019
3 2 90908989
4 2 901212460
5 3 806859980
6 1 127357593
7 4 672430224
8 5 8...

output:

6 999937283

result:

ok 2 number(s): "6 999937283"

Test #9:

score: 5
Accepted
time: 38ms
memory: 9172kb

input:

1000 100000
2 1 862440900
3 1 274038631
4 2 451052457
5 2 726912459
6 2 286441136
7 4 207963194
8 2 ...

output:

6 999526061

result:

ok 2 number(s): "6 999526061"

Test #10:

score: 5
Accepted
time: 40ms
memory: 9180kb

input:

1000 100000
2 1 157424796
3 1 49817162
4 3 627538165
5 1 997527956
6 2 64365399
7 4 252244052
8 2 59...

output:

6 999946758

result:

ok 2 number(s): "6 999946758"

Test #11:

score: 5
Accepted
time: 92ms
memory: 16412kb

input:

100000 192142
2 1 23
3 1 45
4 2 1
5 3 49
6 2 11
7 1 19
8 5 9
9 5 18
10 3 3
11 4 49
12 3 22
13 1 15
1...

output:

6522 91

result:

ok 2 number(s): "6522 91"

Test #12:

score: 5
Accepted
time: 95ms
memory: 16740kb

input:

100000 197288
2 1 40
3 1 39
4 3 5
5 4 11
6 2 41
7 2 21
8 7 14
9 1 1
10 3 50
11 7 8
12 3 5
13 2 39
14...

output:

6488 99

result:

ok 2 number(s): "6488 99"

Test #13:

score: 5
Accepted
time: 94ms
memory: 16068kb

input:

100000 185947
2 1 47
3 2 24
4 2 48
5 1 14
6 1 16
7 2 47
8 5 45
9 3 20
10 5 30
11 3 8
12 2 5
13 10 48...

output:

6618 96

result:

ok 2 number(s): "6618 96"

Test #14:

score: 5
Accepted
time: 106ms
memory: 16796kb

input:

100000 198555
2 1 18
3 2 12
4 3 1
5 2 43
6 5 22
7 3 33
8 5 46
9 6 6
10 3 15
11 7 50
12 8 16
13 2 6
1...

output:

6472 86

result:

ok 2 number(s): "6472 86"

Test #15:

score: 5
Accepted
time: 104ms
memory: 15764kb

input:

100000 180838
2 1 621329386
3 2 648567834
4 3 892090214
5 3 518337384
6 4 447299965
7 5 789310908
8 ...

output:

6653 999727059

result:

ok 2 number(s): "6653 999727059"

Test #16:

score: 5
Accepted
time: 136ms
memory: 16776kb

input:

100000 198243
2 1 640266132
3 2 535523966
4 2 964334629
5 4 30144932
6 2 370167988
7 6 408070807
8 2...

output:

6488 999955028

result:

ok 2 number(s): "6488 999955028"

Test #17:

score: 5
Accepted
time: 106ms
memory: 16264kb

input:

100000 189081
2 1 761134421
3 1 560510240
4 2 10391619
5 1 212903081
6 4 328951976
7 4 117851203
8 7...

output:

6566 999934943

result:

ok 2 number(s): "6566 999934943"

Test #18:

score: 5
Accepted
time: 109ms
memory: 15856kb

input:

100000 182605
2 1 540097606
3 2 131508099
4 2 806008577
5 1 572768389
6 3 677414662
7 6 166795991
8 ...

output:

6651 999916931

result:

ok 2 number(s): "6651 999916931"

Test #19:

score: 5
Accepted
time: 98ms
memory: 16496kb

input:

100000 193540
2 1 715451778
3 2 31499974
4 2 547284294
5 4 564502651
6 3 873424178
7 5 151484960
8 4...

output:

6545 999948348

result:

ok 2 number(s): "6545 999948348"

Test #20:

score: 5
Accepted
time: 92ms
memory: 16044kb

input:

100000 185722
2 1 324871956
3 1 830540294
4 3 706966347
5 1 662569628
6 4 500783123
7 2 310955607
8 ...

output:

6625 999932056

result:

ok 2 number(s): "6625 999932056"

Extra Test:

score: 0
Extra Test Passed