# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781744 | makanhulia | Naboj (COCI22_naboj) | C++17 | 146 ms | 21984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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,a,b;
set<ll> st;
ll temp1,temp2;
vector<ll> adj[200200],v;
bool vis[200200];
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(n == 2) {
cout << 1 << endl;
cout << a << " 1" << endl;
return 0;
}
if(st.size() < n/2 || st.size() == n) {
cout << -1 << endl;
return 0;
}
FOR(1,i,v.size()-1) {
if(v[i] - v[i-1] > 2) {
cout << -1 << endl;
return 0;
}
}
cout << v.size() << endl;
cout << v[0] << " 1" << endl;
vis[0] = true;
temp1 = 0;
temp2 = v.size() -1 ;
FOR(1,i,v.size()-1) {
if(v[i] - v[i-1] == 1) {
temp1 = i;
vis[i] = true;
cout << v[i] << " 1" << endl;
}
else {
break;
}
}
if(!vis[v.size()-1]) {
cout << v[v.size()-1] << " 1" << endl;
vis[v.size()-1] = true;
}
FORM(v.size()-2,i,temp1+1) {
if(v[i+1] - v[i] == 1 && !vis[i]) {
temp2 = i;
cout << v[i] << " 1" << endl;
}
else {
break;
}
}
// cout << "temp1 " << temp1 << endl;
// cout << "temp2 " << temp2 << endl;
FOR(temp1+1,i,temp2-1) {
if(vis[i]) continue;
cout << v[i] << " 1" << endl;
}
}
/*
9 8
1 2
2 3
3 4
5 4
5 6
6 7
7 8
8 9
5 4
1 2
3 2
3 4
5 4
4 3
1 2
2 3
3 4
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |