10317 | 2024-03-30 17:49:07 | szil | Pletykálkodás | cpp17 | Time limit exceeded 76/100 | 1.6s | 7956 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);
}
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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1996 KiB | ||||
2 | Accepted | 3ms | 2308 KiB | ||||
3 | Accepted | 10ms | 3088 KiB | ||||
subtask2 | 9/9 | ||||||
4 | Accepted | 3ms | 3036 KiB | ||||
5 | Accepted | 3ms | 3252 KiB | ||||
6 | Accepted | 3ms | 3176 KiB | ||||
subtask3 | 13/13 | ||||||
7 | Accepted | 27ms | 4456 KiB | ||||
8 | Accepted | 13ms | 4304 KiB | ||||
9 | Accepted | 12ms | 4184 KiB | ||||
subtask4 | 16/16 | ||||||
10 | Accepted | 8ms | 4500 KiB | ||||
11 | Accepted | 8ms | 4516 KiB | ||||
12 | Accepted | 7ms | 4736 KiB | ||||
subtask5 | 25/25 | ||||||
13 | Accepted | 3ms | 3748 KiB | ||||
14 | Accepted | 3ms | 3936 KiB | ||||
15 | Accepted | 3ms | 4060 KiB | ||||
16 | Accepted | 4ms | 4080 KiB | ||||
17 | Accepted | 3ms | 4040 KiB | ||||
18 | Accepted | 4ms | 4036 KiB | ||||
19 | Accepted | 3ms | 4032 KiB | ||||
subtask6 | 13/13 | ||||||
20 | Accepted | 4ms | 4408 KiB | ||||
21 | Accepted | 4ms | 4456 KiB | ||||
22 | Accepted | 4ms | 4712 KiB | ||||
23 | Accepted | 108ms | 5424 KiB | ||||
24 | Accepted | 115ms | 5208 KiB | ||||
25 | Accepted | 193ms | 5032 KiB | ||||
26 | Accepted | 68ms | 4824 KiB | ||||
subtask7 | 0/24 | ||||||
27 | Accepted | 13ms | 6376 KiB | ||||
28 | Accepted | 12ms | 6604 KiB | ||||
29 | Accepted | 12ms | 6636 KiB | ||||
30 | Time limit exceeded | 1.544s | 5044 KiB | ||||
31 | Time limit exceeded | 1.574s | 4988 KiB | ||||
32 | Time limit exceeded | 1.567s | 5084 KiB | ||||
33 | Time limit exceeded | 1.6s | 5092 KiB | ||||
34 | Time limit exceeded | 1.562s | 5332 KiB | ||||
35 | Accepted | 67ms | 7956 KiB | ||||
36 | Accepted | 388ms | 7836 KiB | ||||
37 | Accepted | 14ms | 7224 KiB |