#include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; using ll = long long; template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out, const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } vector<vector<int>> get_res(int n) { int m; cin >> m; vector<vector<int>> g(n + 1); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } vector<int> edge1(n + 1); for(int to : g[1]) { edge1[to] = 1; } vector<vector<int>> upd; vector<int> u(n + 1); queue<int> q; q.push(1); u[1] = 1; while(!q.empty()) { int v = q.front(); q.pop(); if(v > 1 && !edge1[v]) upd.push_back({0, 1, v}); for(int to : g[v]) { if(u[to]) continue; u[to] = 1; q.push(to); } } for(int v = 2; v <= n; v++) { for(int to : g[v]) { if(v < to) { upd.push_back({1, v, to}); } } } return upd; } void print(vector<vector<int>>& v) { for(int i = 0; i < v.size(); i++) { if(v[i][0] == 0) cout << "+ "; else cout << "- "; cout << v[i][1] << " " << v[i][2] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; auto a = get_res(n); auto b = get_res(n); reverse(b.begin(), b.end()); for(int i = 0; i < b.size(); i++) { b[i][0] ^= 1; } cout << a.size() + b.size() << '\n'; print(a); print(b); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; using ll = long long; template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out, const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } vector<vector<int>> get_res(int n) { int m; cin >> m; vector<vector<int>> g(n + 1); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } vector<int> edge1(n + 1); for(int to : g[1]) { edge1[to] = 1; } vector<vector<int>> upd; vector<int> u(n + 1); queue<int> q; q.push(1); u[1] = 1; while(!q.empty()) { int v = q.front(); q.pop(); if(v > 1 && !edge1[v]) upd.push_back({0, 1, v}); for(int to : g[v]) { if(u[to]) continue; u[to] = 1; q.push(to); } } for(int v = 2; v <= n; v++) { for(int to : g[v]) { if(v < to) { upd.push_back({1, v, to}); } } } return upd; } void print(vector<vector<int>>& v) { for(int i = 0; i < v.size(); i++) { if(v[i][0] == 0) cout << "+ "; else cout << "- "; cout << v[i][1] << " " << v[i][2] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; auto a = get_res(n); auto b = get_res(n); reverse(b.begin(), b.end()); for(int i = 0; i < b.size(); i++) { b[i][0] ^= 1; } cout << a.size() + b.size() << '\n'; print(a); print(b); return 0; } |