QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671837#2879. Kaleidoscopic RouteIllusionaryDominance#WA 63ms11288kbC++202.3kb2024-10-24 14:39:162024-10-24 14:39:17

Judging History

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

  • [2024-10-24 14:39:17]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:11288kb
  • [2024-10-24 14:39:16]
  • 提交

answer

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

const int N = 1e5 + 10;
const int M = 2e5 + 10;

struct edge{int from, to, c;}eg[M << 1];
int front[N], num;
void add(int x, int y, int c){eg[++ num] = (edge){front[x], y, c}; front[x] = num;}


int dis[N][2], maxs[N][2], mins[N][2];
int n, m;

void init(){for (int i = 1; i <= n; ++ i) dis[i][0] = dis[i][1] = 1e9;}

int ans;
deque<int>v;

void bfs(int s, int t){
	queue<int>q;
	
	init(); for (int i = 1; i <= n; ++ i) maxs[i][0] = -1, maxs[i][1] = 0;
	dis[s][0] = 0, q.push(s);
	while(!q.empty()){
		int o = q.front();
		q.pop();
		for (int i = front[o]; i; i = eg[i].from){
			int to = eg[i].to;
			if(dis[o][0] + 1 == dis[to][0] && maxs[to][0] < max(maxs[o][0], eg[i].c)) maxs[to][0] = max(maxs[o][0], eg[i].c), maxs[to][1] = o;
			if(dis[o][0] + 1 < dis[to][0]){
				dis[to][0] = dis[o][0] + 1;
				maxs[to][0] = max(maxs[o][0], eg[i].c), maxs[to][1] = o;
				q.push(to);
			}
		}
	}
	
	for (int i = 1; i <= n; ++ i) mins[i][0] = 1e9, mins[i][1] = 0;
	dis[t][1] = 0, q.push(t);
	while(!q.empty()){
		int o = q.front();
		q.pop();
		for (int i = front[o]; i; i = eg[i].from){
			int to = eg[i].to;
			if(dis[o][1] + 1 == dis[to][1] && mins[to][0] < min(mins[o][0], eg[i].c)) mins[to][0] = min(mins[o][0], eg[i].c), mins[to][1] = o;
			if(dis[o][1] + 1 < dis[to][1]){
				dis[to][1] = dis[o][1] + 1;
				mins[to][0] = min(mins[o][0], eg[i].c), mins[to][1] = o;
				q.push(to);
			}
		}
	}
	
	for (int i = 2; i < n; ++ i){
		if(dis[i][0] + dis[i][1] == dis[t][0] && ans < maxs[i][0] - mins[i][0]){
			ans = maxs[i][0] - mins[i][0];
			v.clear();
			v.push_back(i);
			for (int o = maxs[i][1]; o; o = maxs[o][1]) v.push_front(o);
			for (int o = mins[i][1]; o; o = mins[o][1]) v.push_back(o);
		}
	}
}

void solve(){
	num = 0;
	for (int i = 1; i <= n; ++ i) front[i] = 0;
	cin >> n >> m;
	ans = -1;
	for (int i = 1; i <= m; ++ i){
		int x, y, c; cin >> x >> y >> c;
		add(x, y, c); add(y, x, c);
		if(min(x, y) == 1 && max(x, y) == n) ans = 0, v.push_back(1), v.push_back(n);
	}
	
	bfs(1, n); bfs(n, 1);
	if(v[0] != 1) reverse(v.begin(), v.end());
	cout << v.size() - 1 << "\n";
	for (int o:v) cout << o << " ";
	cout << "\n";
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1;
	while(T --) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5808kb

input:

6 8
1 5 2
5 2 5
3 5 4
1 3 10
3 4 6
4 5 7
4 6 8
2 6 1

output:

3
1 5 4 6 

result:

ok 3 6

Test #2:

score: 0
Accepted
time: 1ms
memory: 7852kb

input:

10 20
1 9 34
6 3 80
7 3 15
5 4 73
4 1 42
8 6 92
2 10 25
4 3 8
9 3 79
3 1 11
9 2 74
10 1 83
3 2 6
10 3 38
10 4 48
1 5 38
6 2 43
4 2 55
8 7 90
3 5 4

output:

1
1 10 

result:

ok 1 0

Test #3:

score: 0
Accepted
time: 1ms
memory: 7692kb

input:

24 65
22 11 519
2 4 585
8 17 647
1 11 464
13 4 596
12 10 733
24 21 106
1 14 345
23 5 430
2 3 137
16 7 891
16 4 807
14 3 465
4 22 532
16 9 346
21 8 859
18 15 631
9 5 914
19 17 729
1 2 546
5 15 43
2 12 349
19 9 642
13 3 441
20 15 359
21 11 645
9 14 992
4 23 9
23 9 34
24 16 117
16 18 349
10 22 285
22 5...

output:

2
1 11 24 

result:

ok 2 208

Test #4:

score: 0
Accepted
time: 1ms
memory: 7692kb

input:

53 123
43 38 999
7 24 718
6 33 393
16 15 734
21 39 604
27 15 828
45 31 747
23 4 538
14 41 224
38 9 756
12 36 574
12 13 624
7 34 649
17 53 309
38 33 825
1 36 273
38 21 81
36 11 680
14 8 649
12 24 346
21 49 921
1 47 612
11 39 648
41 35 271
15 24 36
29 3 980
29 28 295
15 21 236
27 8 853
22 6 532
3 14 9...

output:

2
1 52 53 

result:

ok 2 482

Test #5:

score: 0
Accepted
time: 1ms
memory: 5816kb

input:

2 1
2 1 33

output:

1
1 2 

result:

ok 1 0

Test #6:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

123 1032
49 28 6306
70 79 6579
24 47 3306
102 114 7381
78 34 4078
31 92 2591
114 65 7836
92 59 7583
110 51 4384
84 99 439
78 48 77
23 77 6225
96 69 2939
55 112 45
48 29 4735
27 18 4242
117 97 395
71 64 2979
102 36 9531
20 86 7795
11 5 3142
114 107 1188
62 106 6321
6 71 2974
102 96 4240
82 13 7488
95...

output:

2
1 93 123 

result:

ok 2 5258

Test #7:

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

input:

1342 23134
757 512 65447
281 782 35017
179 633 86323
707 635 20673
1225 962 76138
986 59 62123
29 482 39870
90 265 65928
572 1028 18186
810 568 89715
469 998 95978
583 641 63660
261 208 37031
775 1131 33707
161 702 33733
1340 726 67611
548 583 9224
1100 208 82846
227 486 60094
1070 565 49959
1285 11...

output:

3
1 669 616 1342 

result:

ok 3 93825

Test #8:

score: 0
Accepted
time: 22ms
memory: 7788kb

input:

5313 87123
3239 37 964433
3078 247 435023
1830 493 489819
4478 1661 914186
750 2703 353434
3853 1072 285309
2117 1377 641750
1254 4366 734040
2222 2191 362794
3461 2267 359296
2514 913 627160
878 1006 709645
1767 3791 250153
4845 4041 339269
3270 2061 26968
2421 660 798388
262 1399 974636
5120 4171 ...

output:

3
1 3463 3294 5313 

result:

ok 3 878139

Test #9:

score: 0
Accepted
time: 52ms
memory: 10000kb

input:

12313 173254
4620 6513 380927
4465 6551 243296
615 9825 794381
338 11211 368032
4571 9567 634707
3731 7430 87826
8106 7718 998064
4146 7848 922789
3966 1263 331881
9179 646 948846
11893 5020 883102
5612 10513 898068
3451 3435 451139
9640 1947 1353
12271 9668 283149
9742 5631 884826
6837 2449 309976
...

output:

3
1 1402 3350 12313 

result:

ok 3 497061

Test #10:

score: -100
Wrong Answer
time: 63ms
memory: 11288kb

input:

23532 200000
21979 22532 52608855
17378 1428 55313979
12897 6506 2960978
21412 2936 26201355
1327 21400 71454522
6940 9953 7548221
15846 15164 69193724
22756 8774 49306072
10793 7975 94773768
15722 221 88298496
274 22685 29319966
21564 10196 30589888
2895 9073 93905131
8310 22526 13817682
1565 2616 ...

output:

4
1 11388 16361 18380 23532 

result:

wrong answer jury has better answer