Submission #781744

#TimeUsernameProblemLanguageResultExecution timeMemory
781744makanhuliaNaboj (COCI22_naboj)C++17
0 / 110
146 ms21984 KiB
#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)

naboj.cpp: In function 'int main()':
naboj.cpp:38: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]
   38 |   if(st.size() < n/2 || st.size() == n) {
      |      ~~~~~~~~~~^~~~~
naboj.cpp:38: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]
   38 |   if(st.size() < n/2 || st.size() == n) {
      |                         ~~~~~~~~~~^~~~
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:42:3: note: in expansion of macro 'FOR'
   42 |   FOR(1,i,v.size()-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:53:3: note: in expansion of macro 'FOR'
   53 |   FOR(1,i,v.size()-1) {
      |   ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...