QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387084 | #8029. Traveling Merchant | 15owzLy1 | Compile Error | / | / | C++14 | 2.8kb | 2024-04-12 01:39:37 | 2024-04-12 01:39:37 |
Judging History
你现在查看的是最新测评结果
- [2024-08-07 20:25:21]
- hack成功,自动添加数据
- (/hack/771)
- [2024-04-12 01:39:37]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-04-12 01:39:37]
- 提交
answer
#include <bits/stdc++.h>
int main() {
// freopen("in", "r", stdin);
int ttt;
std::cin >> ttt;
while (ttt--) {
int n, m;
std::cin >> n >> m;
std::vector<int> fa(n + 1), dsu(n + 1);
int dfn_tot = 0, bel_tot = 0;
std::vector<int> dfn(n + 1), low(n + 1), dep(n + 1), bel(n + 1);
std::vector<std::vector<int>> ver(n + 1), diff(n + 1);
std::vector<bool> vis(n + 1);
std::string c;
std::cin >> c;
for (int i = 0, u, v; i < m; ++i) {
std::cin >> u >> v; ++u, ++v;
if (c[u - 1] == c[v - 1]) {
diff[u].emplace_back(v);
diff[v].emplace_back(u);
} else {
ver[u].emplace_back(v);
ver[v].emplace_back(u);
}
}
auto tarjan = [&] (auto self, const int u, const int pre = -1) -> void {
dfn[u] = low[u] = ++dfn_tot;
vis[u] = true;
for (auto &&v: ver[u]) {
if (!dfn[v]) {
fa[v] = u;
self(self, v, i);
low[u] = std::min(low[u], low[v]);
} else if (i != (pre ^ 1)) {
low[u] = std::min(low[u], dfn[v]);
}
}
};
auto shrink = [&] (auto self, const int u) -> void {
bel[u] = bel_tot;
for (auto &&v: ver[u]) {
if (bel[v] == 0 && low[v] <= dfn[u]) {
self(self, v);
}
}
};
tarjan(tarjan, 1);
for (int i = 1; i <= n; ++i) {
if (dfn[i] != 0 && bel[i] == 0) {
++bel_tot;
shrink(shrink, i);
}
}
bool flag{false};
for (int i = 1; i <= n; ++i)
dsu[i] = i;
auto GetFa = [&] (auto self, const int u) -> int {
return dsu[u] == u ? u : dsu[u] = self(self, dsu[u]);
};
auto dfs = [&] (auto self, const int u) -> void {
vis[u] = true;
for (auto &&v: diff[u]) {
if (vis[v]) {
if (dfn[u] == 0 || dfn[v] == 0) {
continue;
}
int w = GetFa(GetFa, v);
if (u == w || v == w) {
flag = true;
}
if (bel[fa[w]] == bel[u] || bel[fa[w]] == bel[v]) {
flag = true;
}
}
}
for (auto &&v: ver[u]) {
if (!vis[v]) {
self(self, v);
}
}
dsu[u] = fa[u];
};
dfs(dfs, 1);
puts(flag ? "yes" : "no");
}
return 0;
}
Details
answer.code:2:1: error: ‘’ does not name a type 2 | |