Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
// Nie opuszczaj si�! #include<bits/stdc++.h> using namespace std; set<pair<int,int>> niunia, risa; vector<pair<int,int>> plusy, minusy; void dfs(int v, bool odw[], vector<int> g[]) { odw[v] = true; if (v != 1 && niunia.find({1,v}) == niunia.end()) niunia.insert({1,v}), plusy.push_back({1,v}); for (int u : g[v]) if (!odw[u]) dfs(u,odw,g); } void dfs2(int v, bool odw[], vector<int> g2[]) { odw[v] = true; for (int u : g2[v]) if (!odw[u]) dfs2(u,odw,g2); if (niunia.find({1,v}) != niunia.end() && risa.find({1,v}) == risa.end()) minusy.push_back({1,v}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,a,b; cin >> n >> m; vector<int> g[n+1], g2[n+1]; for (int i = 0; i < m; i++) { cin >> a >> b; if (a > b) swap(a,b); g[a].push_back(b), g[b].push_back(a), niunia.insert({a,b}); } cin >> m; for (int i = 0; i < m; i++) { cin >> a >> b; if (a > b) swap(a,b); g2[a].push_back(b), g2[b].push_back(a), risa.insert({a,b}); } bool odw[n+1]; fill(odw,odw+n+1,false), dfs(1,odw,g); for (auto p : risa) if (niunia.find(p) == niunia.end()) plusy.push_back(p); for (auto p : niunia) if (risa.find(p) == risa.end() && p.first != 1) minusy.push_back(p); fill(odw,odw+n+1,false), dfs2(1,odw,g2); cout << plusy.size()+minusy.size() << endl; for (auto p : plusy) cout << "+ " << p.first << " " << p.second << endl; for (auto p : minusy) cout << "- " << p.first << " " << p.second << 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 | // Nie opuszczaj si�! #include<bits/stdc++.h> using namespace std; set<pair<int,int>> niunia, risa; vector<pair<int,int>> plusy, minusy; void dfs(int v, bool odw[], vector<int> g[]) { odw[v] = true; if (v != 1 && niunia.find({1,v}) == niunia.end()) niunia.insert({1,v}), plusy.push_back({1,v}); for (int u : g[v]) if (!odw[u]) dfs(u,odw,g); } void dfs2(int v, bool odw[], vector<int> g2[]) { odw[v] = true; for (int u : g2[v]) if (!odw[u]) dfs2(u,odw,g2); if (niunia.find({1,v}) != niunia.end() && risa.find({1,v}) == risa.end()) minusy.push_back({1,v}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,a,b; cin >> n >> m; vector<int> g[n+1], g2[n+1]; for (int i = 0; i < m; i++) { cin >> a >> b; if (a > b) swap(a,b); g[a].push_back(b), g[b].push_back(a), niunia.insert({a,b}); } cin >> m; for (int i = 0; i < m; i++) { cin >> a >> b; if (a > b) swap(a,b); g2[a].push_back(b), g2[b].push_back(a), risa.insert({a,b}); } bool odw[n+1]; fill(odw,odw+n+1,false), dfs(1,odw,g); for (auto p : risa) if (niunia.find(p) == niunia.end()) plusy.push_back(p); for (auto p : niunia) if (risa.find(p) == risa.end() && p.first != 1) minusy.push_back(p); fill(odw,odw+n+1,false), dfs2(1,odw,g2); cout << plusy.size()+minusy.size() << endl; for (auto p : plusy) cout << "+ " << p.first << " " << p.second << endl; for (auto p : minusy) cout << "- " << p.first << " " << p.second << endl; return 0; } |