#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define int long long #define st first #define nd second #define pb push_back #define mp make_pair #define rep(i,a,b) for(ll i=(ll)a;i<=(ll)b;++i) #define all(a) a.begin(),a.end() #define sz(x) (int)(x).size() const int mxN = 3e4+7; vector<int> graf[mxN]; vector<pair<int,int>> e; int n; vector<pair<char,pair<int,int>>> res; bool vis[mxN], jest[mxN]; void dfs1(int v){ vis[v] = 1; for(auto u : graf[v]) if(!vis[u]){ if(!jest[u]) res.pb({'+',{1,u}}); jest[u] = 1; dfs1(u); } } void dfs2(int v){ vis[v] = 1; for(auto u : graf[v]) if(!vis[u]){ dfs2(u); if(jest[u]) res.pb({'-', {1,u}}); jest[u] = 0; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int m; cin >> m; while(m--){ int u,v; cin >> u >> v; graf[u].pb(v); graf[v].pb(u); e.pb({u,v}); } for(auto u : graf[1]) jest[u] = 1; dfs1(1); for(auto [u,v] : e) if(min(u,v) != 1) res.pb({'-',{u,v}}); rep(i,1,n) graf[i].clear(); cin >> m; while(m--){ int u,v; cin >> u >> v; graf[u].pb(v); graf[v].pb(u); if(min(u,v) != 1) res.pb({'+', {u,v}}); else jest[max(u,v)] = 0; } rep(i,1,n) vis[i] = 0; dfs2(1); cout << sz(res) << "\n"; for(auto [x,u] : res) cout << x << " " << u.st << " " << u.nd << "\n"; }
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; typedef long long ll; typedef long double ld; #define int long long #define st first #define nd second #define pb push_back #define mp make_pair #define rep(i,a,b) for(ll i=(ll)a;i<=(ll)b;++i) #define all(a) a.begin(),a.end() #define sz(x) (int)(x).size() const int mxN = 3e4+7; vector<int> graf[mxN]; vector<pair<int,int>> e; int n; vector<pair<char,pair<int,int>>> res; bool vis[mxN], jest[mxN]; void dfs1(int v){ vis[v] = 1; for(auto u : graf[v]) if(!vis[u]){ if(!jest[u]) res.pb({'+',{1,u}}); jest[u] = 1; dfs1(u); } } void dfs2(int v){ vis[v] = 1; for(auto u : graf[v]) if(!vis[u]){ dfs2(u); if(jest[u]) res.pb({'-', {1,u}}); jest[u] = 0; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int m; cin >> m; while(m--){ int u,v; cin >> u >> v; graf[u].pb(v); graf[v].pb(u); e.pb({u,v}); } for(auto u : graf[1]) jest[u] = 1; dfs1(1); for(auto [u,v] : e) if(min(u,v) != 1) res.pb({'-',{u,v}}); rep(i,1,n) graf[i].clear(); cin >> m; while(m--){ int u,v; cin >> u >> v; graf[u].pb(v); graf[v].pb(u); if(min(u,v) != 1) res.pb({'+', {u,v}}); else jest[max(u,v)] = 0; } rep(i,1,n) vis[i] = 0; dfs2(1); cout << sz(res) << "\n"; for(auto [x,u] : res) cout << x << " " << u.st << " " << u.nd << "\n"; } |