#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,m,pre,a,b;
set<ll> st;
ll temp1,temp2;
vector<ll> adj[200200],v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
FOR(1,i,m) {
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
st.insert(a);
}
for(auto i : st) {
v.pb(i);
}
if(st.size() < n/2 || st.size() == n-1) {
cout << -1 << endl;
return 0;
}
pre = -1;
for(auto i : v) {
if(pre != -1 && i - pre > 2) {
cout << -1 << endl;
return 0;
}
pre = i;
}
pre = -1;
FOR(0,i,v.size()-1) {
if(pre != -1) {
if(v[i] - pre != 1) {
temp1 = i;
break;
}
}
cout << v[i] << " 1" << endl;
pre = v[i];
}
pre = -1;
FORM(v.size()-1,i,1) {
if(pre != -1) {
if(v[i] - pre != 1) {
temp2 = i;
break;
}
}
cout << v[i] << " 1" << endl;
pre = i;
}
FOR(temp1,i,temp2) {
cout << v[i] << " 1" << endl;
}
}
/*
9 8
1 2
2 3
3 4
5 4
5 6
6 7
7 8
8 9
*/
Compilation message
naboj.cpp: In function 'int main()':
naboj.cpp:32:16: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
32 | if(st.size() < n/2 || st.size() == n-1) {
| ~~~~~~~~~~^~~~~
naboj.cpp:32:35: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
32 | if(st.size() < n/2 || st.size() == n-1) {
| ~~~~~~~~~~^~~~~~
naboj.cpp:13:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | #define FOR(m,i,n) for(int i=(m); i<=(n); i++)
| ^
naboj.cpp:45:3: note: in expansion of macro 'FOR'
45 | FOR(0,i,v.size()-1) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5020 KB |
Integer parameter [name=d] equals to 2, violates the range [0, 1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
23336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5020 KB |
Integer parameter [name=d] equals to 2, violates the range [0, 1] |
3 |
Halted |
0 ms |
0 KB |
- |