QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134470 | #2760. Simurgh | Qwerty1232# | 0 | 679ms | 5820kb | C++20 | 3.4kb | 2023-08-03 20:29:30 | 2024-07-04 01:15:56 |
Judging History
answer
#include "simurgh.h"
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <random>
struct DSU {
std::vector<int> prv;
DSU(int n) {
clear(n);
}
void clear(int n) {
prv.assign(n, -1);
}
int get(int i) {
return prv[i] == -1 ? i : prv[i] = get(prv[i]);
}
void merge(int u, int v) {
u = get(u);
v = get(v);
assert(u != v);
prv[u] = v;
}
};
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
static std::mt19937 rnd;
int m = u.size();
std::vector<std::pair<int, int>> edg(m);
std::vector<int> gold(m, -1);
for (int i = 0; i < m; i++) {
edg[i] = {u[i], v[i]};
}
std::vector<int> all(m);
std::iota(all.begin(), all.end(), 0);
std::shuffle(all.begin(), all.end(), rnd);
std::vector<int> ans;
DSU dsu(n);
for (int &i : all) {
auto [u, v] = edg[i];
if (dsu.get(u) != dsu.get(v)) {
dsu.merge(u, v);
ans.push_back(i);
i = -1;
}
}
all.erase(std::remove(all.begin(), all.end(), -1), all.end());
int cnt_rl = count_common_roads(ans);
std::shuffle(all.begin(), all.end(), rnd);
int cnt_q = 1;
while (!all.empty()) {
int id = all.back();
all.pop_back();
std::shuffle(ans.begin(), ans.end(), rnd);
// std::cerr << std::count_if(ans.begin(), ans.end(), [&](int i) { return gold[i] == 0; }) << "\n";
std::vector<bool> used(n - 1);
for (int i = 0; i < n - 1; i++) {
if (gold[ans[i]] == 1) {
continue;
}
std::swap(ans[i], id);
dsu.clear(n);
bool fuck = false;
for (int i : ans) {
auto [u, v] = edg[i];
if (dsu.get(u) == dsu.get(v)) {
fuck = true;
break;
}
dsu.merge(u, v);
}
if (!fuck) {
int cnt2 = count_common_roads(ans);
cnt_q++;
std::swap(ans[i], id);
if (cnt2 < cnt_rl) {
gold[ans[i]] = true;
gold[id] = false;
break;
} else if (cnt2 > cnt_rl) {
cnt_rl = cnt2;
gold[ans[i]] = false;
gold[id] = true;
std::cerr << cnt2 << " " << cnt_q << "\n";
std::swap(ans[i], id);
break;
} else {
if (gold[ans[i]] == 0) {
// std::cerr << "FFF\n";
gold[id] = 0;
break;
}
continue;
}
} else {
used[i] = true;
std::swap(ans[i], id);
}
}
if (gold[id] == -1) {
gold[id] = 0;
// std::cerr << "cum: " << id << "\n";
}
if (gold[id] == 0) {
for (int i = 0; i < n - 1; i++) {
if (used[i] && gold[ans[i]] == -1) {
gold[ans[i]] = 0;
}
}
}
}
assert(cnt_rl == n - 1);
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 13
Accepted
time: 0ms
memory: 4088kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 2 0 0 1 5 2 2 6 1 3 3 0 6 0 4 5 3 2 4 0 1 4 0 5 4 3 4 6 6 1 2 1 5 3 2 4 5 6 5 1 6 3 7 10 9 13 12 17
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 10 7 12 17 9 13
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 4 6 1 6 2 3 0 3 2 1 2 6 5 6 6 3 0 2 1 0 4 2 1 3 5 2 5 0 0 6 5 3 4 5 5 1 3 4 1 4 4 0 4 16 10 0 20 18
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 10 16 4 18 0 20
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 2 5 0 4 4 5 4 3 5 3 1 3 3 6 4 1 6 0 5 6 6 2 6 1 6 4 3 2 2 1 1 0 0 2 5 0 5 1 4 2 0 3 20 17 15 9 2 19
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 17 19 15 2 9 20
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 13 30000 2 4 4 3 3 2 0 3 0 4 6 3 6 1 4 5 6 2 1 3 5 6 6 0 6 4 3 9 12 7 0 4
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0 9 3 12 4 7
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 6 10 30000 5 2 0 1 1 2 0 3 3 2 1 4 0 5 3 5 4 3 1 3 5 0 7 2 1
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 7 2 5 1 0
result:
ok correct
Test #6:
score: -13
Runtime Error
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 16 30000 3 4 2 5 2 1 0 5 1 5 0 2 2 6 6 1 4 6 0 1 2 3 6 3 3 1 1 4 4 5 3 5 0 9 5 15 3 11
output:
Unauthorized output
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #58:
score: 19
Accepted
time: 0ms
memory: 3868kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 2 1 12000 1 0 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0
result:
ok correct
Test #59:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 10 45 12000 4 8 0 5 2 0 5 8 8 0 3 8 6 4 4 1 2 3 2 1 6 2 1 7 3 7 8 1 7 0 8 6 0 6 9 5 9 6 7 4 7 6 7 9 1 6 3 5 2 5 7 5 3 9 0 3 3 6 2 9 1 5 0 4 7 8 5 4 9 4 5 6 3 1 2 8 7 2 2 4 1 0 9 8 4 3 1 9 9 0 22 41 3 16 7 25 28 11 39
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 22 39 28 25 41 3 16 7 11
result:
ok correct
Test #60:
score: -19
Wrong Answer
time: 679ms
memory: 5820kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 400 79800 12000 32 64 96 254 115 203 7 171 112 81 124 143 336 175 217 328 152 133 124 331 19 91 92 232 152 43 215 169 4 341 363 18 83 99 52 46 248 66 242 187 150 319 335 158 172 150 3 49 126 256 60 153 165 230 265 68 119 380 171 22 35 169 3...
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs WA NO
result:
wrong answer WA in grader: NO
Subtask #5:
score: 0
Skipped
Dependency #1:
0%