QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863690#9881. Diverge and ConvergeqLCompile Error//C++172.7kb2025-01-19 21:17:002025-01-19 21:17:06

Judging History

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

  • [2025-01-19 21:17:06]
  • 评测
  • [2025-01-19 21:17:00]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <functional>
using i32 = int;
using edges = std::vector<std::pair<i32, i32>>;
signed main() noexcept {
	i32 n;
	scanf("%d", &n);
	edges e1(n - 1), e2(n - 1);
	auto edge = [](i32 x, i32 y) noexcept { return x < y ? std::make_pair(x, y) : std::make_pair(y, x); };
	for (i32 i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), e1[i - 1] = edge(--u, --v);
	for (i32 i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), e2[i - 1] = edge(--u, --v);
	std::function<std::pair<edges, edges>(edges, edges)> solve = [&](edges e1, edges e2) noexcept -> std::pair<edges, edges> {
		if (e1.empty()) return {};
		std::vector<std::vector<i32>> G1(n), G2(n);
		for (auto [u, v] : e1) G1[u].push_back(v), G1[v].push_back(u);
		for (auto [u, v] : e2) G2[u].push_back(v), G2[v].push_back(u);
		for (i32 x = 0; x < n; ++x)
			if (G1[x].size() + G2[x].size() == 2) {
				i32 a = G1[x][0], b = G2[x][0];
				e1.erase(std::find(e1.begin(), e1.end(), edge(x, a)));
				e2.erase(std::find(e2.begin(), e2.end(), edge(x, b)));
				auto [t1, t2] = solve(e1, e2);
				t1.emplace_back(edge(x, a)), t2.emplace_back(edge(x, b));
				return {t1, t2};
			} else if (G1[x].size() + G2[x].size() == 3) {
				bool swapped = G1[x].size() > G2[x].size();
				if (swapped) std::swap(G1, G2), std::swap(e1, e2);
				i32 a = G1[x][0], b = G2[x][0], c = G2[x][1];
				e1.erase(std::find(e1.begin(), e1.end(), edge(x, a)));
				e2.erase(std::find(e2.begin(), e2.end(), edge(x, b)));
				e2.erase(std::find(e2.begin(), e2.end(), edge(x, c)));
				e2.emplace_back(edge(b, c));
				auto [t1, t2] = solve(e1, e2);
				i32 cur = std::find(t2.begin(), t2.end(), edge(b, c)) - t2.begin();
				std::vector<std::vector<i32>> G3(n);
				std::vector<bool> vis(n);
				for (i32 i = 0; i != cur; ++i) {
					auto [u, v] = t2[i];
					G3[u].push_back(v), G3[v].push_back(u);
				}
				for (i32 i = t1.size() - 1; i != cur; ++i) {
					auto [u, v] = t1[i];
					G3[u].push_back(v), G3[v].push_back(u);
				}
				std::function<void(i32, i32)> dfs = [&](i32 x, i32 fa) noexcept {
					vis[x] = true;
					for (i32 y : G3[x])
						if (y != fa) dfs(y, x);
				};
				auto [d, e] = t1[cur];
				dfs(d, 0);
				if (vis[a] != vis[b]) std::swap(b, c);
				t2[cur] = edge(x, c);
				t1.insert(t1.begin() + cur + 1, edge(x, a));
				t2.insert(t2.begin() + cur + 1, edge(x, b));
				if (swapped) std::swap(t1, t2);
				return {t1, t2};
			}
	};
	auto [t1, t2] = solve(e1, e2);
	for (i32 i = 1; i < n; ++i) printf("%d%c", (std::find(e1.begin(), e1.end(), t1[i - 1]) - e1.begin()) + 1, " \n"[i == n - 1]);
	for (i32 i = 1; i < n; ++i) printf("%d%c", (std::find(e2.begin(), e2.end(), t2[i - 1]) - e2.begin()) + 1, " \n"[i == n - 1]);
	return 0;
}

详细

answer.code: In lambda function:
answer.code:21:47: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   21 |                                 e1.erase(std::find(e1.begin(), e1.end(), edge(x, a)));
      |                                               ^~~~
      |                                               bind
answer.code:22:47: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   22 |                                 e2.erase(std::find(e2.begin(), e2.end(), edge(x, b)));
      |                                               ^~~~
      |                                               bind
answer.code:30:47: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   30 |                                 e1.erase(std::find(e1.begin(), e1.end(), edge(x, a)));
      |                                               ^~~~
      |                                               bind
answer.code:31:47: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   31 |                                 e2.erase(std::find(e2.begin(), e2.end(), edge(x, b)));
      |                                               ^~~~
      |                                               bind
answer.code:32:47: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   32 |                                 e2.erase(std::find(e2.begin(), e2.end(), edge(x, c)));
      |                                               ^~~~
      |                                               bind
answer.code:35:48: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   35 |                                 i32 cur = std::find(t2.begin(), t2.end(), edge(b, c)) - t2.begin();
      |                                                ^~~~
      |                                                bind
answer.code: In function ‘int main()’:
answer.code:62:58: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   62 |         for (i32 i = 1; i < n; ++i) printf("%d%c", (std::find(e1.begin(), e1.end(), t1[i - 1]) - e1.begin()) + 1, " \n"[i == n - 1]);
      |                                                          ^~~~
      |                                                          bind
answer.code:63:58: error: ‘find’ is not a member of ‘std’; did you mean ‘bind’?
   63 |         for (i32 i = 1; i < n; ++i) printf("%d%c", (std::find(e2.begin(), e2.end(), t2[i - 1]) - e2.begin()) + 1, " \n"[i == n - 1]);
      |                                                          ^~~~
      |                                                          bind
answer.code:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:11:48: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         for (i32 i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), e1[i - 1] = edge(--u, --v);
      |                                           ~~~~~^~~~~~~~~~~~~~~~
answer.code:12:48: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         for (i32 i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), e2[i - 1] = edge(--u, --v);
      |                                           ~~~~~^~~~~~~~~~~~~~~~
answer.code: In lambda function:
answer.code:60:9: warning: control reaches end of non-void function [-Wreturn-type]
   60 |         };
      |         ^