#include "bits/stdc++.h"
using namespace std;
vector<int> v[5];
vector<pair<int,int>> con,all;
int lim = 5 , mi = 1e9 , m;
void rec(int dep){
if(dep>lim)return ;
bool ss = 1;
for(int i = 0;i<m;i++){
if(v[i].size()==1){ss = 0;break;}
if(v[i].size()){
if(v[i][0]!=v[i][1])ss = 0;
}
}
if(ss){
if(mi>dep){
mi =dep;
all.clear();
all = con;
}
return ;
}
for(int i = 0;i<m;i++){
if(v[i].empty())continue;
for(int j = 0;j<m;j++){
if(v[j].size()==2||i==j)continue;
con.push_back({i+1,j+1});
int x = v[i].back();v[i].pop_back();
v[j].push_back(x);
rec(dep+1);
con.pop_back();
x = v[j].back();v[j].pop_back();
v[i].push_back(x);
}
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n;
cin>>n>>m;
for(int i = 0;i<m;i++){
int a,b;cin>>a>>b;
if(a!=0)v[i].push_back(a);
if(b!=0)v[i].push_back(b);
}
rec(0);
if(mi==1e9){
cout<<-1<<endl;
return 0;
}
cout<<mi<<endl;
for(auto i:all){
cout<<i.first<<" "<<i.second<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |