Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Miles Morales : When will I know I'm ready?
- Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
- */
- // KEEP IT SIMPLE STUPID
- #include <bits/stdc++.h>
- using namespace std;
- /*================PRAGMAS START===============================================*/
- #pragma GCC optimize("O3")
- #pragma GCC target("avx")
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- /*================PRAGMAS END===============================================*/
- /*=================DEFINES/TYPEDEF START==============================*/
- #define int long long
- #define FIO \
- freopen("input.txt", "r", stdin); \
- freopen("output.txt", "w", stdout);
- #define Lightspeed \
- ios::sync_with_stdio(0); \
- cin.tie(0); \
- cout.tie(0);
- #define google cout << "Case #" << tt << ": "
- #define umin(...) min({__VA_ARGS__})
- #define umax(...) max({__VA_ARGS__})
- #define MAX(v) *max_element(all(v))
- #define MIN(v) *min_element(all(v))
- #define fi first
- #define se second
- /*=================DEFINES/TYPEDEF END================================*/
- /*=================DEBUGGING START====================================*/
- vector<string> split(const string &s, char c)
- {
- vector<string> v;
- stringstream ss(s);
- string x;
- while (getline(ss, x, c))
- v.emplace_back(x);
- return move(v);
- }
- template <typename T, typename... Args>
- inline string arrStr(T arr, int n)
- {
- stringstream s;
- s << "[";
- for (int i = 0; i < n - 1; i++)
- s << arr[i] << ",";
- s << arr[n - 1] << "]";
- return s.str();
- }
- #ifndef ONLINE_JUDGE
- #define debug(args...) \
- { \
- __evars_begin(__LINE__); \
- __evars(split(#args, ',').begin(), args); \
- }
- inline void __evars_begin(int line)
- {
- cerr << "#" << line << ": ";
- }
- template <typename T>
- inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
- template <typename T>
- inline void __evars_out_var(T *val) { cerr << arrStr(val, 10); }
- template <typename T>
- inline void __evars_out_var(T val) { cerr << val; }
- inline void __evars(vector<string>::iterator it) { cerr << endl; }
- template <typename T, typename... Args>
- inline void __evars(vector<string>::iterator it, T a, Args... args)
- {
- cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
- __evars_out_var(a);
- cerr << "; ";
- __evars(++it, args...);
- }
- // #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
- #else
- #define debug(...) 42
- #endif
- /*===============================DEBUGGING END======================*/
- /*=======================CONSTANTS START============================*/
- const int INF = 1e18;
- const int MOD = 1e9 + 7;
- /*=======================CONSTANTS END==============================*/
- /*======================SOME USEFUL FUNCTIONS START=======================*/
- void usaco(string prob)
- {
- freopen((prob + ".in").c_str(), "r", stdin);
- freopen((prob + ".out").c_str(), "w", stdout);
- }
- int gcd(int a, int b)
- {
- return __gcd(a, b);
- }
- int lcm(int a, int b)
- {
- return (a * b) / __gcd(a, b);
- }
- int bpow(int a, int n)
- {
- int res = 1;
- a %= MOD;
- while (n > 0)
- {
- if (n & 1)
- {
- res *= a;
- res %= MOD;
- }
- a *= a;
- a %= MOD;
- n >>= 1;
- }
- return res;
- }
- bool isPrime(int n)
- {
- if (n < 2)
- {
- return false;
- }
- for (int i = 2; i * i <= n; i++)
- {
- if (n % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- /*======================SOME USEFUL FUNCTIONS END=======================*/
- class Graph
- {
- int vertex;
- int edges;
- vector<unordered_map<int, int>> adj;
- public:
- Graph(int v)
- {
- vertex = v;
- adj = vector<unordered_map<int, int>>(v + 1);
- edges = 0;
- }
- void addEdge(int u, int v)
- {
- edges++;
- adj[u][v] = 1;
- adj[v][u] = 1;
- }
- void removeEdge(int u, int v)
- {
- adj[v].erase(u);
- adj[u].erase(v);
- }
- vector<int> printEulerCircuit()
- {
- bool ok = true;
- for (int i = 1; i <= vertex; ++i)
- {
- if (adj[i].size() % 2)
- {
- ok = false;
- break;
- }
- }
- if (ok)
- {
- return printEuler(1);
- }
- else
- {
- return {};
- }
- }
- vector<int> printEuler(int v)
- {
- stack<int> cpath;
- stack<int> epath;
- cpath.push(v);
- while (!cpath.empty())
- {
- int u = cpath.top();
- if (adj[u].empty())
- {
- epath.push(u);
- cpath.pop();
- }
- else
- {
- cpath.push(adj[u].begin()->first);
- removeEdge(u, adj[u].begin()->first);
- }
- }
- vector<int> ans;
- while (!epath.empty())
- {
- ans.push_back(epath.top());
- epath.pop();
- }
- // ans.push_back(ans.front());
- return ans;
- }
- void Solution()
- {
- auto v = printEulerCircuit();
- if (v.empty() or (int) v.size() != (edges + 1))
- {
- cout << "NO\n";
- }
- else
- {
- cout << "YES\n";
- for (int i = 0; i < edges; i++)
- {
- cout << v[i] << " " << v[i + 1] << "\n";
- }
- }
- }
- };
- void solve()
- {
- int n, m;
- cin >> n >> m;
- Graph G = Graph(n);
- for (int i = 0; i < m; i++)
- {
- int u, v;
- cin >> u >> v;
- G.addEdge(u, v);
- }
- G.Solution();
- }
- signed main()
- {
- // FIO;
- Lightspeed;
- // usaco("cowlands");
- int TC = 1;
- // cin >> TC;
- for (int tt = 1; tt <= TC; tt++)
- {
- // google;
- solve();
- }
- return 0;
- }
- /* stuff you should look for
- * int overflow, array bounds
- * special cases (n=1?)
- * do smth instead of nothing and stay organized
- * WRITE STUFF DOWN
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement