103162024-03-30 17:41:57szilPletykálkodáscpp17Wrong answer 29/1001.582s7872 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 7001;

vector<int> g[MAXN];
vector<pair<int, int>> ans1, ans2;
bool vis[MAXN];

void dfs(int u) {
	vis[u] = true;
	for (int v : g[u]) {
		if (!vis[v]) {
			dfs(v);
			ans1.emplace_back(u, v);
		}
	}
}

void print_ans() {
	int k = ans1.size() + ans2.size();
	cout << k << "\n";
	for (auto [u, v] : ans1) {
		cout << u << " " << v << "\n";
	}
	for (auto [u, v] : ans2) {
		cout << u << " " << v << "\n";
	}
}

void case1() {
	dfs(1);
	ans2 = ans1;
	ans2.pop_back();
	reverse(ans2.begin(), ans2.end());
	print_ans();
	exit(0);
}

void case2(vector<int> cyc) {
	for (int i : cyc) vis[i] = true;
	for (int i : cyc) {
		dfs(i);
	}
	ans2 = ans1;
	ans1.emplace_back(cyc[0], cyc[1]);
	ans1.emplace_back(cyc[2], cyc[3]);
	ans1.emplace_back(cyc[0], cyc[2]);
	ans1.emplace_back(cyc[1], cyc[3]);
	reverse(ans2.begin(), ans2.end());
	print_ans();
	exit(0);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	if (n == 1) {
		cout << "0\n";
		return 0;
	}
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	for (int i = 1; i <= n; i++) {
		map<int, vector<int>> mp;
		for (int u : g[i]) {
			for (int v : g[u]) {
				mp[v].emplace_back(u);
			}
		}
		for (auto [u, vec] : mp) {
			if (u == i) continue;
			if (vec.size() >= 2) {
				case2({i, vec[0], u, vec[1]});
			}
		}
	}
	case1();
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2268 KiB
2Accepted3ms2568 KiB
3Wrong answer10ms3180 KiB
subtask20/9
4Accepted3ms3056 KiB
5Accepted3ms3188 KiB
6Wrong answer3ms3084 KiB
subtask313/13
7Accepted27ms4412 KiB
8Accepted13ms4300 KiB
9Accepted12ms4532 KiB
subtask416/16
10Accepted8ms4828 KiB
11Accepted8ms5044 KiB
12Accepted8ms5040 KiB
subtask50/25
13Wrong answer3ms4168 KiB
14Wrong answer3ms4428 KiB
15Wrong answer3ms4556 KiB
16Accepted4ms4820 KiB
17Accepted4ms4772 KiB
18Accepted4ms4784 KiB
19Wrong answer3ms4840 KiB
subtask60/13
20Wrong answer4ms5108 KiB
21Wrong answer4ms5112 KiB
22Wrong answer4ms5108 KiB
23Accepted108ms5800 KiB
24Accepted115ms5540 KiB
25Accepted193ms5360 KiB
26Wrong answer68ms5480 KiB
subtask70/24
27Wrong answer13ms6860 KiB
28Wrong answer13ms6888 KiB
29Wrong answer13ms6788 KiB
30Time limit exceeded1.575s5092 KiB
31Time limit exceeded1.57s5020 KiB
32Time limit exceeded1.582s5300 KiB
33Time limit exceeded1.574s5240 KiB
34Time limit exceeded1.574s5200 KiB
35Wrong answer67ms7872 KiB
36Wrong answer388ms7680 KiB
37Wrong answer14ms7244 KiB