QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345230#3411. Absurdistan RoadsPetroTarnavskyi#AC ✓652ms66448kbC++201.9kb2024-03-06 16:54:182024-03-06 16:54:19

Judging History

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

  • [2024-03-06 16:54:19]
  • 评测
  • 测评结果:AC
  • 用时:652ms
  • 内存:66448kb
  • [2024-03-06 16:54:18]
  • 提交

answer

#include <bits/stdc++.h> 

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

struct DSU
{
	int n;
	VI p, sz;
	void init(int _n)
	{
		n = _n;
		p.resize(n);
		iota(ALL(p), 0);
		sz.assign(n, 1);
	}
	int find(int v)
	{
		if(v == p[v])
			return v;
		return p[v] = find(p[v]);
	}
	bool unite(int u, int v)
	{
		u = find(u);
		v = find(v);
		if(u == v)
			return false;
		if(sz[u] > sz[v])
			swap(u, v);
		p[u] = v;
		sz[v] += sz[u];
		return true;
	}
};

const int N = 1 << 11;
int d[N][N];
vector<PII> g[N];

int dist[N];

void dfs(int v, int p, int di)
{
	dist[v] = di;
	for(auto [to, w] : g[v])
	{
		if(to != p)
			dfs(to, v, di + w);
	}
}



void solve(int n)
{
	vector<tuple<int, int, int>> vals(n * n);
	FOR(i, 0, n)
	{
		FOR(j, 0, n)
		{
			cin >> d[i][j];
			vals[i * n + j] = {d[i][j], i, j};
		}
	}
	sort(ALL(vals));
	DSU D;
	D.init(n);
	for(auto [dis, i, j] : vals)
	{
		if(i == j)
			continue;
		if(!D.unite(i, j))
			continue;
		cout << i + 1 << " " << j + 1 << " " << dis << "\n";
		
		g[i].PB({j, dis});
		g[j].PB({i, dis});
	}
	PII edge = {-1, -1};	
	
	FOR(i, 0, n)
	{
		dfs(i, -1, 0);
		
		
		FOR(j, 0, n)
		{
			if(dist[j] != d[i][j])
			{
				if(edge.F == -1 || d[edge.F][edge.S] > d[i][j])
					edge = {i, j};
			}
		}
	}
	if(edge == MP(-1, -1))
		edge = MP(0, 1);
	
	cout << edge.F + 1 << " " << edge.S + 1 << " " << d[edge.F][edge.S] << "\n";
	cout << "\n";
	FOR(i, 0, n)
		g[i].clear();
}



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	while(cin >> n)
		solve(n);
	
	return 0;
}

詳細信息

Test #1:

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

input:

40
0 49907 81666 63518 54444 18148 77129 45370 9074 86203 77129 36296 58981 13611 86203 58981 4537 90740 40833 27222 36296 4537 45370 22685 68055 72592 68055 63518 72592 81666 22685 31759 54444 40833 18148 9074 31759 13611 27222 49907
49907 0 49907 68055 77129 31759 27222 4537 40833 36296 54444 1361...

output:

1 17 4537
1 22 4537
2 8 4537
2 33 4537
3 11 4537
3 15 4537
4 16 4537
4 25 4537
5 16 4537
5 40 4537
6 24 4537
6 38 4537
7 26 4537
7 30 4537
8 19 4537
9 22 4537
9 38 4537
10 18 4537
10 30 4537
11 29 4537
12 19 4537
12 32 4537
13 28 4537
13 33 4537
14 35 4537
14 36 4537
15 18 4537
17 36 4537
20 24 4537...

result:

ok  (2 test cases)

Test #2:

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

input:

52
0 59280 17784 77064 5928 53352 50388 74100 11856 41496 35568 71136 35568 29640 17784 11856 68172 44460 14820 8892 23712 38532 2964 23712 65208 68172 8892 56316 53352 44460 14820 59280 20748 2964 38532 62244 32604 62244 50388 5928 29640 32604 47424 71136 56316 20748 26676 74100 65208 47424 41496 2...

output:

1 23 2964
1 34 2964
2 36 2964
2 45 2964
3 31 2964
3 33 2964
4 8 2964
4 48 2964
5 23 2964
5 27 2964
6 28 2964
6 39 2964
7 29 2964
7 43 2964
8 44 2964
9 27 2964
9 31 2964
10 18 2964
10 35 2964
11 22 2964
11 42 2964
12 17 2964
12 48 2964
13 35 2964
13 37 2964
14 37 2964
14 47 2964
15 19 2964
15 46 2964...

result:

ok  (2 test cases)

Test #3:

score: 0
Accepted
time: 158ms
memory: 24524kb

input:

1000
0 66192 23640 41961 42158 1576 7486 88256 9259 75845 19109 73284 17139 31717 55554 91999 76042 65404 44128 43734 5122 46295 90226 82346 43537 32899 94757 63434 30535 34081 69147 47871 68556 71708 85104 10638 85104 2561 13396 54963 33096 79194 20685 59494 9653 68556 81755 70329 55948 33490 29944...

output:

1 778 197
1 975 197
2 80 197
2 610 197
3 602 197
3 754 197
4 734 197
4 972 197
5 342 197
5 443 197
6 107 197
6 523 197
7 493 197
7 508 197
8 717 197
8 723 197
9 209 197
9 278 197
10 100 197
10 364 197
11 293 197
11 693 197
12 172 197
12 216 197
13 542 197
13 719 197
14 705 197
14 709 197
15 583 197
...

result:

ok  (2 test cases)

Test #4:

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

input:

38
0 266 3861 3872 3772 3029 3553 2995 1398 2545 1492 3162 3086 4487 2132 2404 3920 3195 789 1510 2992 2151 1307 2249 1563 3060 2735 2816 1530 3409 2937 2794 1672 2555 1506 2197 2504 3413
266 0 3595 3606 3506 2763 3287 2729 1132 2279 1226 2896 2820 4221 1866 2138 3654 2929 523 1244 2726 1885 1041 19...

output:

20 35 4
11 35 14
6 8 34
4 17 48
12 13 76
9 23 91
25 33 109
7 30 144
21 32 198
16 36 207
23 25 256
6 21 264
1 2 266
32 37 290
36 37 307
16 27 331
10 36 348
34 36 358
8 38 418
19 23 518
2 19 523
26 37 556
15 29 602
28 36 619
29 36 667
27 30 674
13 16 682
11 19 703
5 14 715
31 36 740
19 29 741
11 24 75...

result:

ok  (2 test cases)

Test #5:

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

input:

69
0 4049 1022 2517 1231 2109 2893 2496 1765 3168 3864 3313 3516 2676 2754 808 2651 3149 2659 3060 1987 2037 3201 3527 1930 1972 2623 528 2134 3043 11 3336 1409 944 2089 2479 3046 3065 2096 4042 1791 3561 1981 2266 1683 360 1203 2652 1420 3738 2753 2875 2214 2376 1017 749 2550 4010 1380 2339 2882 44...

output:

1 31 11
8 36 17
17 27 28
4 57 33
29 35 45
10 38 103
16 34 136
6 26 137
7 30 150
7 37 153
9 67 159
9 68 172
47 49 217
28 56 221
8 66 229
6 54 267
16 28 280
43 45 298
14 54 300
48 60 313
1 46 360
40 62 369
14 38 389
47 68 390
21 68 394
16 47 395
9 63 400
39 45 413
5 16 423
12 61 431
23 66 476
28 55 48...

result:

ok  (2 test cases)

Test #6:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

25
0 1101 1690 2531 318 1647 3012 971 3083 2177 324 1532 2035 2192 3395 2028 2810 2655 1867 1993 971 1947 3143 1542 1286
1101 0 589 1430 783 1845 3465 2072 3536 1076 777 431 934 1091 2294 927 3263 1554 2320 892 1424 846 3596 441 1739
1690 589 0 2019 1372 1256 4054 1932 4125 487 1366 158 345 818 2883...

output:

5 11 6
12 24 10
7 9 71
3 12 158
7 17 202
3 22 257
1 5 318
17 23 333
3 13 345
2 12 431
16 24 486
3 10 487
4 20 538
11 21 647
12 14 660
6 8 676
6 10 769
2 11 777
4 15 864
2 20 892
19 21 896
17 19 943
11 25 962
3 18 965
1 8 971


result:

ok  (2 test cases)

Test #7:

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

input:

124
0 4462 3546 3371 2525 5235 3310 813 2112 4905 5254 4858 5396 3164 2919 4484 5276 4634 4997 3926 3968 3114 4295 5242 2588 4112 4641 4146 2779 2721 2938 2719 1787 353 3978 5554 5267 512 2779 4186 3582 4763 534 2302 5309 5848 5296 4997 4430 6653 5866 5160 2962 2779 6459 2192 5060 1001 5403 3609 897...

output:

63 123 16
16 100 25
52 96 34
58 69 38
32 80 72
92 114 79
95 111 83
10 48 92
93 114 108
71 119 111
20 123 125
4 90 128
18 116 152
25 72 156
29 31 159
34 38 159
2 78 160
25 83 171
79 90 178
25 54 191
54 120 194
27 62 197
33 105 199
15 32 200
2 64 215
36 77 225
81 103 229
12 97 230
19 42 234
9 94 247
7...

result:

ok  (2 test cases)

Test #8:

score: 0
Accepted
time: 84ms
memory: 16812kb

input:

772
0 3011 2894 4076 2303 6229 5036 4112 3449 3874 4177 3356 5208 3557 4936 5614 3542 4244 5895 3384 3395 3302 4779 3441 5345 3760 4006 6749 5198 4507 4188 3467 5255 3252 5676 2966 4660 3518 5276 2462 4642 3241 5274 3444 5773 5335 4935 55 4338 4078 6215 4149 4958 3649 4368 3344 3698 4246 3532 4330 3...

output:

157 644 2
336 529 3
428 658 6
572 760 7
85 653 9
729 745 9
48 437 10
159 454 11
230 547 11
150 492 14
20 484 15
203 482 15
308 535 15
246 482 18
12 726 19
109 261 22
623 726 23
486 555 25
492 718 29
39 667 32
174 340 33
476 561 33
139 268 34
507 754 34
25 68 36
40 497 37
291 642 37
271 278 38
177 38...

result:

ok  (2 test cases)

Test #9:

score: 0
Accepted
time: 49ms
memory: 11988kb

input:

582
0 6337 5590 2675 5213 6644 4945 5834 4605 7377 6048 5391 4430 6319 2178 5671 6173 3333 4376 5827 4223 6447 6835 7867 5335 5754 4423 5140 6799 3198 6305 5178 7485 3951 5209 5832 5801 4582 2976 981 4289 5012 5565 5610 6120 5157 5691 235 6105 5603 5834 4303 5827 6482 4866 3769 6241 4819 5282 3821 6...

output:

96 240 2
36 53 5
520 534 6
292 490 8
157 426 10
8 260 11
205 552 11
46 249 12
67 207 15
111 149 15
415 503 20
314 490 22
441 572 25
364 381 26
175 517 29
42 297 33
148 216 36
347 368 37
213 246 39
148 578 40
1 564 41
468 520 41
76 330 44
270 536 46
371 415 46
192 220 47
40 561 49
357 478 49
245 429 ...

result:

ok  (2 test cases)

Test #10:

score: 0
Accepted
time: 152ms
memory: 23320kb

input:

1000
0 4072 5115 5025 5178 2522 4834 6901 4428 3825 3467 2250 8597 3930 4790 5139 5278 3772 3402 4324 6507 3740 7629 2028 3205 5162 3514 5889 4577 7536 8248 5848 3385 3707 6674 3383 4961 6605 4776 1450 5886 4122 4145 3932 3065 6851 4933 3523 4067 3702 5176 6235 4922 4371 7160 5307 7248 3892 3514 331...

output:

150 870 2
396 428 2
266 665 3
348 428 6
76 984 8
290 516 9
951 979 9
138 752 10
267 320 11
359 675 13
519 644 15
49 470 16
686 849 17
116 890 19
532 604 21
206 776 22
345 860 22
607 996 22
212 549 23
44 188 25
522 941 26
614 751 27
197 310 29
584 828 29
674 739 30
423 841 33
729 942 35
621 873 36
77...

result:

ok  (2 test cases)

Test #11:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

10
0 9 22 6 4 16 3 25 5 15
9 0 13 15 5 25 12 21 14 6
22 13 0 27 18 17 25 8 27 7
6 15 27 0 10 10 3 19 1 21
4 5 18 10 0 20 7 26 9 11
16 25 17 10 20 0 13 9 11 24
3 12 25 3 7 13 0 22 2 18
25 21 8 19 26 9 22 0 20 15
5 14 27 1 9 11 2 20 0 20
15 6 7 21 11 24 18 15 20 0

output:

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


result:

ok  (2 test cases)

Test #12:

score: 0
Accepted
time: 151ms
memory: 24012kb

input:

1000
0 148280 23845 42825 120235 168300 105336 177755 192879 6754 182858 219414 121233 165830 182790 115564 174983 239445 171441 141476 131274 91260 121800 156933 64350 6135 160160 184905 48633 170771 184730 178695 87675 140085 167558 14900 115758 171108 105567 84560 27495 99499 182435 34317 3633 17...

output:

247 308 1
247 675 2
183 675 3
183 899 4
535 899 5
271 535 6
271 482 7
482 908 8
329 908 9
251 329 10
251 651 11
360 651 12
152 360 13
152 481 14
145 481 15
145 197 16
197 263 17
263 315 18
315 682 19
398 682 20
28 398 21
28 114 22
114 695 23
695 718 24
498 718 25
498 552 26
552 601 27
31 601 28
31 3...

result:

ok  (2 test cases)

Test #13:

score: 0
Accepted
time: 152ms
memory: 23484kb

input:

1000
0 116886 39429 92377 161499 97320 27389 244635 31164 224601 210940 120273 54075 63502 573 207102 100864 180430 225330 32398 14190 111127 80523 137604 36750 33615 202498 158880 181356 192225 139545 164109 5301 35502 14523 7761 17964 212361 158005 11594 852 23919 39045 180025 11109 28996 37851 44...

output:

272 396 1
386 396 2
386 843 3
546 843 4
546 567 5
567 748 6
508 748 7
508 930 8
501 930 9
501 712 10
372 712 11
365 372 12
365 405 13
181 405 14
181 991 15
719 991 16
71 719 17
71 745 18
296 745 19
296 360 20
360 822 21
665 822 22
576 665 23
576 869 24
869 929 25
751 929 26
542 751 27
542 603 28
603...

result:

ok  (2 test cases)

Test #14:

score: 0
Accepted
time: 652ms
memory: 66448kb

input:

2000
0 69762 108675 255878 382773 451882 454196 284582 131806 92208 321975 152344 317438 309375 362251 381063 419688 191823 304383 310128 382458 452462 199125 42112 375875 381006 206873 390358 266625 150407 113082 324348 443109 440672 10398 302022 275517 417484 278702 366093 391803 24038 380664 4941...

output:

567 682 1
682 1947 1
567 919 2
1197 1947 2
819 919 3
1197 1930 3
819 1873 4
1787 1930 4
417 1873 5
1787 1804 5
417 836 6
1620 1804 6
159 1620 7
836 1121 7
43 159 8
1018 1121 8
43 1248 9
231 1018 9
89 1248 10
231 1017 10
89 837 11
662 1017 11
662 971 12
837 1589 12
971 1207 13
1589 1593 13
494 1207 1...

result:

ok  (2 test cases)

Test #15:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

2
0 5
5 0
3
0 3 8
3 0 5
8 5 0
3
0 3 7
3 0 5
7 5 0
3
0 1 1
1 0 1
1 1 0
4
0 1 2 3
1 0 1 2
2 1 0 1
3 2 1 0
4
0 5 10 1000000
5 0 15 1000000
10 15 0 999990
1000000 1000000 999990 0

output:

1 2 5
1 2 5

1 2 3
2 3 5
1 2 3

1 2 3
2 3 5
1 3 7

1 2 1
1 3 1
2 3 1

1 2 1
2 3 1
3 4 1
1 2 1

1 2 5
1 3 10
3 4 999990
2 4 1000000


result:

ok  (7 test cases)

Test #16:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

4
0 1 2 1
1 0 2 1
2 2 0 1
1 1 1 0
4
0 1 1 1
1 0 2 2
1 2 0 2
1 2 2 0
3
0 4 1
4 0 3
1 3 0

output:

1 2 1
1 4 1
3 4 1
2 4 1

1 2 1
1 3 1
1 4 1
1 2 1

1 3 1
2 3 3
1 2 4


result:

ok  (4 test cases)