#include <iostream> #include <vector> #include <set> using namespace std; constexpr int maxN = 30'007; int n; int edgesStart; vector<int> G[maxN]; int edgesCel; set<pair<int, int>> allcurrent; vector<pair<char, pair<int, int>>> ans; pair<int, int> order(pair<int, int> p) { if (p.first > p.second) { swap(p.first, p.second); } return p; } void dfsFill(int node, int from, int ORIGIN) { if (node != ORIGIN) { pair<int, int> newEdge = order({ORIGIN, node}); if (allcurrent.find(newEdge) == allcurrent.end()) { // edge non existent // cout << "+ " << ORIGIN << ' ' << node << '\n'; ans.push_back({'+', {ORIGIN, node}}); allcurrent.insert(newEdge); } } for (int& to : G[node]) { if (to == from) { continue; } dfsFill(to, node, ORIGIN); } } // NIE UTWORZ W ZADNYM MOMENCIE DRUGIEJ TAKIEJ SAMEJ KRAWEDZI int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; cin >> edgesStart; for (int i = 0; i < edgesStart; i++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); allcurrent.insert(order({a, b})); } dfsFill(1, -1, 1); cin >> edgesCel; for (int i = 0; i < edgesCel; i++) { int a, b; cin >> a >> b; pair<int, int> edge = order({a, b}); auto el = allcurrent.find(edge); if (el != allcurrent.end()) { // edge already exits allcurrent.erase(el); // dont want to delete it later continue; } // cout << "+ " << edge.first << ' ' << edge.second << '\n'; ans.push_back({'+', {edge.first, edge.second}}); } for (auto el = allcurrent.begin(); el != allcurrent.end(); ++el) { // cout << "- " << el->first << ' ' << el->second << '\n'; ans.push_back({'-', {el->first, el->second}}); } cout << ans.size() << '\n'; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << ' ' << ans[i].second.first << ' ' << ans[i].second.second << '\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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <iostream> #include <vector> #include <set> using namespace std; constexpr int maxN = 30'007; int n; int edgesStart; vector<int> G[maxN]; int edgesCel; set<pair<int, int>> allcurrent; vector<pair<char, pair<int, int>>> ans; pair<int, int> order(pair<int, int> p) { if (p.first > p.second) { swap(p.first, p.second); } return p; } void dfsFill(int node, int from, int ORIGIN) { if (node != ORIGIN) { pair<int, int> newEdge = order({ORIGIN, node}); if (allcurrent.find(newEdge) == allcurrent.end()) { // edge non existent // cout << "+ " << ORIGIN << ' ' << node << '\n'; ans.push_back({'+', {ORIGIN, node}}); allcurrent.insert(newEdge); } } for (int& to : G[node]) { if (to == from) { continue; } dfsFill(to, node, ORIGIN); } } // NIE UTWORZ W ZADNYM MOMENCIE DRUGIEJ TAKIEJ SAMEJ KRAWEDZI int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; cin >> edgesStart; for (int i = 0; i < edgesStart; i++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); allcurrent.insert(order({a, b})); } dfsFill(1, -1, 1); cin >> edgesCel; for (int i = 0; i < edgesCel; i++) { int a, b; cin >> a >> b; pair<int, int> edge = order({a, b}); auto el = allcurrent.find(edge); if (el != allcurrent.end()) { // edge already exits allcurrent.erase(el); // dont want to delete it later continue; } // cout << "+ " << edge.first << ' ' << edge.second << '\n'; ans.push_back({'+', {edge.first, edge.second}}); } for (auto el = allcurrent.begin(); el != allcurrent.end(); ++el) { // cout << "- " << el->first << ' ' << el->second << '\n'; ans.push_back({'-', {el->first, el->second}}); } cout << ans.size() << '\n'; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << ' ' << ans[i].second.first << ' ' << ans[i].second.second << '\n'; } return 0; } |