103192024-03-30 17:51:24szilPletykálkodáscpp17Wrong answer 16/10012ms7500 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[3]);
	ans1.emplace_back(cyc[1], cyc[2]);
	reverse(ans2.begin(), ans2.end());
	print_ans();
	exit(0);
}

vector<int> mp[MAXN];

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++) {
		for (int u : g[i]) {
			for (int v : g[u]) {
				mp[v].emplace_back(u);
			}
		}
		for (int u = 1; u <= n; u++) {
			if (u == i) continue;
			if (mp[u].size() >= 2) {
				case2({i, mp[u][0], u, mp[u][1]});
			}
			mp[u].clear();
		}
	}
	case1();
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms2540 KiB
2Wrong answer3ms2824 KiB
3Wrong answer4ms3100 KiB
subtask20/9
4Wrong answer3ms2832 KiB
5Wrong answer3ms3084 KiB
6Accepted3ms3280 KiB
subtask30/13
7Wrong answer7ms4424 KiB
8Wrong answer8ms4212 KiB
9Wrong answer8ms4420 KiB
subtask416/16
10Accepted7ms4804 KiB
11Accepted7ms4892 KiB
12Accepted7ms4884 KiB
subtask50/25
13Accepted3ms4184 KiB
14Accepted3ms4320 KiB
15Accepted3ms4208 KiB
16Wrong answer3ms4348 KiB
17Wrong answer3ms4508 KiB
18Wrong answer3ms4600 KiB
19Wrong answer3ms4564 KiB
subtask60/13
20Accepted4ms4936 KiB
21Accepted4ms4952 KiB
22Wrong answer4ms5048 KiB
23Wrong answer6ms5424 KiB
24Wrong answer4ms5168 KiB
25Wrong answer4ms5212 KiB
26Wrong answer4ms5328 KiB
subtask70/24
27Accepted12ms7188 KiB
28Accepted12ms7244 KiB
29Wrong answer12ms7500 KiB
30Wrong answer12ms7136 KiB
31Wrong answer10ms6868 KiB
32Wrong answer9ms6892 KiB
33Wrong answer9ms6880 KiB
34Wrong answer9ms6984 KiB
35Wrong answer10ms7048 KiB
36Wrong answer9ms7016 KiB
37Wrong answer9ms6916 KiB