#include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<ll, ll> using namespace std; const int N = 4e4; int n; vec<int> e[N]; bool visited[N]; void get_to_normal_form(vec<string>* output){ int m; cin >> m; foru(_i, m) { int a, b; cin >> a >> b; a--; b--; e[a].pb(b); e[b].pb(a); } queue<int> q; q.push(0); visited[0]=true; while(!q.empty()){ int v = q.front(); q.pop(); bool connected = false; for(auto i : e[v]){ if (i == 0) connected = true; if(visited[i]) continue; visited[i] = true; q.push(i); } if(!connected && v != 0) output->pb("+ 1 " + to_string(v+1)); } fors(i, n, 1) { for(auto j : e[i]) { if (j > i) output->pb("- " + to_string(i+1) + " " + to_string(j+1)); } } foru(i, N) e[i].clear(); foru(i, N) visited[i] = false; } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; vec<string> a; vec<string> b; get_to_normal_form(&a); get_to_normal_form(&b); cout << a.size() + b.size() << endl; for(auto i : a) cout << i << endl; for(int i = b.size()-1; i>=0; i--) { string str = b[i]; if(str[0]=='+') str[0]='-'; else str[0]='+'; cout << str << endl; } 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 | #include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<ll, ll> using namespace std; const int N = 4e4; int n; vec<int> e[N]; bool visited[N]; void get_to_normal_form(vec<string>* output){ int m; cin >> m; foru(_i, m) { int a, b; cin >> a >> b; a--; b--; e[a].pb(b); e[b].pb(a); } queue<int> q; q.push(0); visited[0]=true; while(!q.empty()){ int v = q.front(); q.pop(); bool connected = false; for(auto i : e[v]){ if (i == 0) connected = true; if(visited[i]) continue; visited[i] = true; q.push(i); } if(!connected && v != 0) output->pb("+ 1 " + to_string(v+1)); } fors(i, n, 1) { for(auto j : e[i]) { if (j > i) output->pb("- " + to_string(i+1) + " " + to_string(j+1)); } } foru(i, N) e[i].clear(); foru(i, N) visited[i] = false; } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; vec<string> a; vec<string> b; get_to_normal_form(&a); get_to_normal_form(&b); cout << a.size() + b.size() << endl; for(auto i : a) cout << i << endl; for(int i = b.size()-1; i>=0; i--) { string str = b[i]; if(str[0]=='+') str[0]='-'; else str[0]='+'; cout << str << endl; } return 0; } |