QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68260 | #2760. Simurgh | Lenstar | 13 | 6ms | 7808kb | C++14 | 5.1kb | 2022-12-15 15:36:52 | 2022-12-15 15:36:55 |
Judging History
answer
#include <bits/stdc++.h>
#include "simurgh.h"
using pii = std::pair<int, int>;
#define mkp(a, b) std::make_pair(a, b)
const int N = 5e2 + 10, M = N * N;
std::vector<int> Gold_Roads, Spanning_Tree;
int tot = 1, fir[N], nex[M], got[M], idx[M], Map[N][N], n;
inline void AddEdge(int u, int v, int I) {
nex[++tot] = fir[u], fir[u] = tot, got[tot] = v, idx[tot] = I;
nex[++tot] = fir[v], fir[v] = tot, got[tot] = u, idx[tot] = I;
}
int par[N], vis[N], dep[N], Vis[N], par_edge[N], TYPE[N], w[N], f[N], U[N], V[N], d[N];
inline void dfs(int u) {
vis[u] = true;
for (int i = fir[u]; i; i = nex[i])
if (!vis[got[i]])
Spanning_Tree.push_back(idx[i]), dfs(got[i]);
}
inline int find(int u) {
return f[u] == u ? u : f[u] = find(f[u]);
}
inline int count(std::vector<int> E) {
if (E.size() == n - 1)
return count_common_roads(E);
int s = 0;
for (int i = 0; i < n; ++i)
f[i] = i;
for (int i = 0; i < E.size(); ++i) {
int u = U[E[i]], v = V[E[i]];
f[find(u)] = find(v);
}
for (auto i : Spanning_Tree) {
int u = U[i], v = V[i];
if (find(u) != find(v))
f[find(u)] = find(v), s += TYPE[i], E.push_back(i);
}
return count_common_roads(E) - s;
}
inline std::vector<int> ring(std::vector<int> bas, int ban) {
std::vector<int> res;
for (auto dat : bas)
if (dat != ban)
res.push_back(dat);
return res;
}
inline void solve(int u, int v, int edg_num) {
int flg = 0, edg = 0;
std::vector<int> query;
memset(Vis, 0, sizeof(Vis));
for (int U = u; U != v; U = par[U]) {
Vis[par_edge[U]] = true;
if (TYPE[par_edge[U]] != -1)
flg = true, edg = par_edge[U];
}
if (flg) {
std::vector<int> bas = Spanning_Tree;
bas.push_back(edg_num);
int sum = count(ring(bas, edg));
for (int U = u; U != v; U = par[U]) {
int e = par_edge[U];
if (TYPE[e] == -1) {
std::vector<int> query = ring(bas, e);
int s = count(query);
TYPE[e] = -TYPE[edg] + s - sum;
}
}
} else {
std::vector<int> bas = Spanning_Tree;
int Min = count(bas);
for (int U = u; U != v; U = par[U]) {
int e = par_edge[U];
std::vector<int> query = ring(bas, e);
query.push_back(edg_num);
w[U] = count(query), Min = std::min(Min, w[U]);
}
for (int U = u; U != v; U = par[U])
TYPE[par_edge[U]] = 1 - w[U] + Min;
}
// for (int i = 0; i < 6; ++i) printf("%d ", TYPE[i]); puts("");
}
inline void dfs(int u, int fa) {
par[u] = fa, vis[u] = true, dep[u] = dep[fa] + 1;
for (int i = fir[u]; i; i = nex[i])
if (got[i] != fa) {
if (!vis[got[i]])
par_edge[got[i]] = idx[i], dfs(got[i], u);
else if (dep[u] > dep[got[i]])
solve(u, got[i], idx[i]);
}
}
inline int solve(int u, std::vector<int> vec) {
if (vec.size() == 1)
return vec[0];
int mid = vec.size() / 2;
std::vector<int> E;
for (int i = 0; i < mid; ++i)
E.push_back(Map[u][vec[i]]);
if (count(E)) {
std::vector<int> v;
for (int i = 0; i < mid; ++i)
v.push_back(vec[i]);
return solve(u, v);
} else {
std::vector<int> v;
for (int i = mid; i < vec.size(); ++i)
v.push_back(vec[i]);
return solve(u, v);
}
}
inline int solve(int u) {
std::vector<int> vec;
for (int i = fir[u]; i; i = nex[i])
if (TYPE[Map[u][got[i]]] == -1)
vec.push_back(got[i]);
return solve(u, vec);
}
std::vector<int> find_roads(int N, std::vector<int> U, std::vector<int> V) {
int m = U.size();
n = N;
for (int i = 0; i < m; ++i) {
int u = U[i], v = V[i];
AddEdge(u, v, i);
Map[u][v] = Map[v][u] = i;
::U[i] = u, ::V[i] = v;
}
memset(TYPE, -1, sizeof(TYPE));
dfs(0), memset(vis, 0, sizeof(vis)), dfs(0, -1);
for (auto i : Spanning_Tree)
if (TYPE[i] == -1)
TYPE[i] = 1;
// for (int i = 0; i < m; ++i) printf("%d ", TYPE[i]); puts("");
// std::cout << "Spanning_Tree.size() = " << Spanning_Tree.size() << std::endl;
// for (int i: Spanning_Tree) printf("%d %d %d\n", U[i], V[i], TYPE[i]);
for (int u = 0; u < n; ++u) {
std::vector<int> E;
for (int i = fir[u]; i; i = nex[i])
E.push_back(idx[i]);
d[u] = count(E);
}
for (auto i : Spanning_Tree)
if (TYPE[i] == 1) {
Gold_Roads.push_back(i), --d[U[i]], --d[V[i]];
}
for (int i = 0; i < n - 1; ++i) {
for (int u = 0; u < n; ++u)
if (d[u]) {
int v = solve(u);
Gold_Roads.push_back(Map[u][v]), --d[u], --d[v];
TYPE[Map[u][v]] = 1;
break;
}
}
return Gold_Roads;
}
详细
Subtask #1:
score: 13
Accepted
Test #1:
score: 13
Accepted
time: 2ms
memory: 5696kb
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 17 13 9 10 12 7
result:
ok correct
Test #2:
score: 0
Accepted
time: 2ms
memory: 5760kb
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 20 4 10 18 16 0
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 5836kb
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 20 19 17 15 2 9
result:
ok correct
Test #4:
score: 0
Accepted
time: 1ms
memory: 5844kb
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 12 7 9 4 3 0
result:
ok correct
Test #5:
score: 0
Accepted
time: 2ms
memory: 5628kb
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 5 2 1 0
result:
ok correct
Test #6:
score: 0
Accepted
time: 3ms
memory: 5764kb
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:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 9 15 11 5 3 0
result:
ok correct
Test #7:
score: 0
Accepted
time: 2ms
memory: 5756kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 2 1 30000 0 1 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0
result:
ok correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 3 3 30000 0 1 2 0 1 2 2 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 2 0
result:
ok correct
Test #9:
score: 0
Accepted
time: 3ms
memory: 5696kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 6 5 30000 2 4 5 4 4 0 4 1 3 4 3 1 4 0 2
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 2 4 3 1 0
result:
ok correct
Test #10:
score: 0
Accepted
time: 2ms
memory: 5624kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 6 14 30000 4 2 1 3 4 5 4 1 0 4 0 1 2 3 2 1 0 3 5 3 0 5 0 2 5 2 1 5 13 8 10 7 3
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 13 3 10 8 7
result:
ok correct
Test #11:
score: 0
Accepted
time: 2ms
memory: 5584kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 6 30000 3 0 3 5 4 0 5 6 0 2 1 3 3 4 1 5 0 2
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 4 2 0 5 1 3
result:
ok correct
Test #12:
score: 0
Accepted
time: 2ms
memory: 5632kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 6 15 30000 4 3 2 3 3 5 2 0 5 2 1 3 1 4 0 5 3 0 4 0 1 0 2 1 4 5 4 2 5 1 9 13 12 6 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 12 13 9 6 0
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 5708kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 0 2 2 5 3 4 0 3 5 4 4 2 2 1 4 6 5 3 0 1 4 0 1 6 3 6 1 3 1 5 5 0 0 6 4 1 6 5 3 2 2 6 16 3 18 17 4 6
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 16 17 4 3 6 18
result:
ok correct
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #14:
score: 0
Wrong Answer
time: 0ms
memory: 5744kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 50 1225 30000 47 4 24 48 42 13 5 42 19 17 29 31 23 48 37 25 37 43 27 22 43 30 19 44 49 37 39 14 26 46 46 35 49 15 40 19 6 31 37 1 21 0 26 45 6 4 38 36 6 8 20 4 18 24 20 35 5 29 1 19 35 49 29 20 25 10 10 36 2 22 26 11 7 9 24 3 35 38 48 41 22...
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs WA NO
result:
wrong answer WA in grader: NO
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #58:
score: 19
Accepted
time: 2ms
memory: 5664kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 2 1 12000 1 0 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0
result:
ok correct
Test #59:
score: -19
Wrong Answer
time: 6ms
memory: 7808kb
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 WA NO
result:
wrong answer WA in grader: NO
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%