QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359495 | #6560. Broken Minimum Spanning Tree | LaStataleBlue# | WA | 4ms | 4012kb | C++23 | 1.9kb | 2024-03-20 18:35:14 | 2024-03-20 18:35:14 |
Judging History
answer
#pragma ide diagnostic ignored "misc-no-recursion"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double db;
#define TESTCASE 0
static constexpr int MOD = 998'244'353;
static constexpr int INF = 1.1e9;
static constexpr int MAX_N = 4000;
static constexpr db EPS = 1e-9;
static vector<tuple<int, int, int>> graph[MAX_N];
static bool taken[MAX_N];
static pair<int, int> dfs(int u, int p, int z) {
for (auto [v, w, i]: graph[u]) {
if (v == p || !taken[i]) continue;
if (v == z) return {i, w};
auto [ri, rw] = dfs(v, u, z);
if (ri != -1) return rw > w ? pair(ri, rw) : pair(i, w);
}
return {-1, -1};
}
static void solve([[maybe_unused]] int tc) {
ll N, M;
cin >> N >> M;
vector<tuple<int, int, int, int>> edges(M);
int c = 0;
for (auto &[u, v, w, i]: edges) {
i = c++;
cin >> u >> v >> w;
graph[u].emplace_back(v, w, i);
graph[v].emplace_back(u, w, i);
taken[i] = i < N - 1;
}
sort(edges.begin(), edges.end(), [&](const auto &a, const auto &b) {
return get<2>(a) < get<2>(b);
});
vector<pair<int, int>> moves;
for (auto [u, v, w, i]: edges) {
if (taken[i]) continue;
auto [ri, rw] = dfs(u, v, v);
if (ri != -1 && rw > w) {
moves.emplace_back(ri, i);
taken[ri] = false;
taken[i] = true;
}
}
cout << moves.size() << '\n';
for (auto [a, b]: moves) {
cout << (a + 1) << ' ' << (b + 1) << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
if (const char *f = getenv("REDIRECT_STDOUT"); f) {
freopen(f, "w", stdout);
}
int T = 1;
#if TESTCASE
cin >> T;
#endif
for (int t = 1; t <= T; t++) {
solve(t);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
4 4 1 2 10 2 3 3 3 4 1 1 4 4
output:
1 1 4
result:
ok correct!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 8 1 2 10 2 3 10 3 4 10 4 5 10 5 6 10 6 1 10 1 3 1 4 6 1
output:
2 1 7 4 8
result:
ok correct!
Test #3:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
2000 1999 1262 1505 968661582 323 1681 787089412 1132 129 88786681 1909 587 762050278 979 1371 230688681 1686 521 980519364 975 191 887826021 869 461 899130441 1433 259 961154249 1718 547 721696188 1254 1042 458319755 1779 267 85751052 1170 813 283230029 309 20 971682908 224 417 255325364 1084 986 7...
output:
0
result:
ok correct!
Test #4:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
1999 1998 1757 1820 444157563 1757 395 754598547 1757 1571 432619009 1757 1009 456234067 1757 824 935569725 1757 1698 476714469 1757 1420 901765343 1757 1175 225295107 1757 1512 721959801 1757 1585 955067704 1757 1739 635181418 1757 1686 891225461 1757 84 132683224 1757 1696 48915557 1757 1623 42602...
output:
0
result:
ok correct!
Test #5:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
1999 1998 1345 647 232183406 40 837 279910457 819 857 137486924 255 1378 517489941 827 1565 894953662 1556 1545 898170464 965 877 72248541 1631 298 635713424 895 197 366305735 966 1160 515776809 1870 1638 220711661 1736 220 716014108 1914 1609 759121968 1293 153 272816132 1936 1433 263859075 985 460...
output:
0
result:
ok correct!
Test #6:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
500 998 105 1 1 105 2 1 105 3 1 105 4 1 105 5 1 105 6 1 105 7 1 105 8 1 105 9 1 105 10 1 105 11 1 105 12 1 105 13 1 105 14 1 105 15 1 105 16 1 105 17 1 105 18 1 105 19 1 105 20 1 105 21 1 105 22 1 105 23 1 105 24 1 105 25 1 105 26 1 105 27 1 105 28 1 105 29 1 105 30 1 105 31 1 105 32 1 105 33 1 105 ...
output:
0
result:
ok correct!
Test #7:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
500 998 364 1 1 364 2 1 364 3 1 364 4 1 364 5 1 364 6 1 364 7 1 364 8 1 364 9 1 364 10 1 364 11 1 364 12 1 364 13 1 364 14 1 364 15 1 364 16 1 364 17 1 364 18 1 364 19 1 364 20 1 364 21 1 364 22 1 364 23 1 364 24 1 364 25 1 364 26 1 364 27 1 364 28 1 364 29 1 364 30 1 364 31 1 364 32 1 364 33 1 364 ...
output:
0
result:
ok correct!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
500 998 86 1 2 86 2 2 86 3 2 86 4 2 86 5 2 86 6 2 86 7 2 86 8 2 86 9 2 86 10 2 86 11 2 86 12 2 86 13 2 86 14 2 86 15 2 86 16 2 86 17 2 86 18 2 86 19 2 86 20 2 86 21 2 86 22 2 86 23 2 86 24 2 86 25 2 86 26 2 86 27 2 86 28 2 86 29 2 86 30 2 86 31 2 86 32 2 86 33 2 86 34 2 86 35 2 86 36 2 86 37 2 86 38...
output:
499 496 672 172 657 157 658 158 659 159 660 160 661 161 662 162 663 163 664 164 665 165 666 166 667 167 668 168 669 169 670 170 671 171 656 156 673 173 674 174 675 175 676 176 677 177 678 178 679 179 680 180 681 181 682 182 683 183 684 184 685 185 686 186 687 187 641 141 626 126 627 127 628 128 629 ...
result:
ok correct!
Test #9:
score: 0
Accepted
time: 2ms
memory: 3760kb
input:
500 998 198 227 1 227 315 1 315 426 1 426 400 1 400 61 1 61 143 1 143 487 1 487 65 1 65 415 1 415 434 1 434 327 1 327 190 1 190 411 1 411 51 1 51 91 1 91 364 1 364 185 1 185 393 1 393 89 1 89 53 1 53 66 1 66 69 1 69 13 1 13 5 1 5 45 1 45 314 1 314 291 1 291 490 1 490 92 1 92 175 1 175 458 1 458 218 ...
output:
0
result:
ok correct!
Test #10:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
500 998 360 250 1 250 71 1 71 170 1 170 492 1 492 419 1 419 145 1 145 188 1 188 433 1 433 186 1 186 161 1 161 398 1 398 19 1 19 479 1 479 401 1 401 40 1 40 176 1 176 212 1 212 353 1 353 290 1 290 43 1 43 322 1 322 447 1 447 47 1 47 468 1 468 456 1 456 343 1 343 339 1 339 52 1 52 251 1 251 130 1 130 ...
output:
0
result:
ok correct!
Test #11:
score: -100
Wrong Answer
time: 4ms
memory: 3868kb
input:
500 998 369 45 2 45 364 2 364 300 2 300 195 2 195 291 2 291 390 2 390 122 2 122 331 2 331 408 2 408 91 2 91 298 2 298 116 2 116 301 2 301 287 2 287 338 2 338 4 2 4 79 2 79 177 2 177 387 2 387 125 2 125 477 2 477 11 2 11 284 2 284 102 2 102 305 2 305 395 2 395 112 2 112 280 2 280 294 2 294 232 2 232 ...
output:
495 494 672 487 657 358 658 92 659 91 660 168 661 169 662 141 663 57 664 359 665 197 666 241 667 328 668 497 669 67 670 449 671 107 656 269 673 112 674 268 675 142 676 196 677 243 678 111 679 164 680 56 681 448 682 273 683 246 684 184 685 158 686 66 687 90 641 271 626 307 627 459 628 470 629 209 630...
result:
FAIL participant's MST is better than jury!