#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef long double db; const int N = 1 << 15; set<int> g[2][N]; bool used[2][N]; vector<tuple<char, int, int>> ans; void dfs(int i, int v) { used[i][v] = true; if (i == 0 && v != 0 && !g[i][0].count(v)) ans.PB({'+', 0, v}); for (int to : g[i][v]) { if (!used[i][to]) dfs(i, to); } if (i == 1 && v != 0 && !g[i][0].count(v)) ans.PB({'-', 0, v}); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; FOR(i, 0, 2) { int m; cin >> m; FOR(j, 0, m) { int u, v; cin >> u >> v; u--; v--; g[i][u].insert(v); g[i][v].insert(u); } } dfs(0, 0); FOR(i, 0, 2) { FOR(u, 1, n) { for (int v : g[i][u]) { if (u < v && !g[i ^ 1][u].count(v)) ans.PB({i == 0 ? '-' : '+', u, v}); } } } dfs(1, 0); cout << SZ(ans) << "\n"; for (auto [c, u, v] : ans) cout << c << " " << u + 1 << " " << v + 1 << "\n"; 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 | #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef long double db; const int N = 1 << 15; set<int> g[2][N]; bool used[2][N]; vector<tuple<char, int, int>> ans; void dfs(int i, int v) { used[i][v] = true; if (i == 0 && v != 0 && !g[i][0].count(v)) ans.PB({'+', 0, v}); for (int to : g[i][v]) { if (!used[i][to]) dfs(i, to); } if (i == 1 && v != 0 && !g[i][0].count(v)) ans.PB({'-', 0, v}); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; FOR(i, 0, 2) { int m; cin >> m; FOR(j, 0, m) { int u, v; cin >> u >> v; u--; v--; g[i][u].insert(v); g[i][v].insert(u); } } dfs(0, 0); FOR(i, 0, 2) { FOR(u, 1, n) { for (int v : g[i][u]) { if (u < v && !g[i ^ 1][u].count(v)) ans.PB({i == 0 ? '-' : '+', u, v}); } } } dfs(1, 0); cout << SZ(ans) << "\n"; for (auto [c, u, v] : ans) cout << c << " " << u + 1 << " " << v + 1 << "\n"; return 0; } |