ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 5a9228f8-4375-462d-9961-6e10e828eace
コード
#include <atcoder/dsu> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; } int q; cin >> q; vector<int> v(q), s(q), t(q); map<pair<int, int>, int> dpa; for (int i = 0; i < q; i++) { cin >> v[i] >> s[i]; s[i]--; if (v[i] != 3 && v[i] != 4) { cin >> t[i]; t[i]--; } if (v[i] == 5) { dpa[make_pair(s[i], t[i])] = dpa.size(); } } atcoder::dsu uf(n); assert(dpa.size() <= 3); vector<bool> state(dpa.size(), false); set<pair<int, int>> gs; for (int i = 0; i < m; i++) { gs.insert(make_pair(a[i], b[i])); } for (int i = 0; i < q; i++) { if (v[i] == 1) { gs.erase(make_pair(s[i], t[i])); } else if (v[i] == 5) { gs.insert(make_pair(s[i], t[i])); } } reverse(v.begin(), v.end()); reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); for (auto [u, v] : gs) { if (dpa.contains(make_pair(u, v))) { state[dpa[make_pair(u, v)]] = true; } else { uf.merge(u, v); } } vector<string> ans; for (int i = 0; i < q; i++) { if (v[i] == 1) { if (dpa.contains(make_pair(s[i], t[i]))) { state[dpa[make_pair(s[i], t[i])]] = true; } else { uf.merge(s[i], t[i]); } } else if (v[i] == 2) { if (uf.same(s[i], t[i])) { ans.push_back("Yes"); continue; } set<int> lds; lds.insert(uf.leader(s[i])); vector<int> cs; bool ok = false; for (int j = 0; j < 3; j++) for (auto [k, q] : dpa) { if (!state[q]) continue; auto [u, v] = k; for (int h : lds) if (uf.same(u, h) || uf.same(v, h)) { if (uf.same(u, t[i]) || uf.same(v, t[i])) { ok = true; break; } } } if (ok) { ans.push_back("Yes"); } else { ans.push_back("No"); } } else if (v[i] == 3) { auto vec = uf.groups(); set<int> lds; lds.insert(uf.leader(s[i])); for (int j = 0; j < 3; j++) for (auto [k, q] : dpa) { if (!state[q]) continue; auto [u, v] = k; for (int h : lds) if (uf.same(u, h) || uf.same(v, h)) { lds.insert(uf.leader(u)); lds.insert(uf.leader(v)); } } vector<int> vcs; for (int j = 0; j < n; j++) { for (int v : lds) { if (uf.same(v, j)) { vcs.push_back(j); break; } } } string str = ""; for (int v : vcs) { str += to_string(v + 1); str += " "; } str.pop_back(); ans.push_back(str); } else if (v[i] == 4) { set<int> lds; lds.insert(uf.leader(s[i])); for (int j = 0; j < 3; j++) for (auto [k, q] : dpa) { if (!state[q]) continue; auto [u, v] = k; for (int h : lds) if (uf.same(u, h) || uf.same(v, h)) { lds.insert(uf.leader(u)); lds.insert(uf.leader(v)); } } int sum = 0; for (int v : lds) { sum += uf.size(v); } ans.push_back(to_string(sum)); } else { state[dpa[make_pair(s[i], t[i])]] = false; } } for (int i = ans.size() - 1; i >= 0; i--) { cout << ans[i] << endl; } }
結果
問題
点数
言語
結果
実行時間
メモリ
G - Breaking Friends
0
C++
WJ
0 ms
0 KiB
コンパイルエラー
Main.cpp: In function 'int main()': Main.cpp:7:9: error: 'cin' was not declared in this scope 7 | cin >> n >> m; | ^~~ Main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'? 1 | #include <atcoder/dsu> +++ |+#include <iostream> 2 | using namespace std; Main.cpp:17:9: error: 'map' was not declared in this scope 17 | map<pair<int, int>, int> dpa; | ^~~ Main.cpp:2:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'? 1 | #include <atcoder/dsu> +++ |+#include <map> 2 | using namespace std; Main.cpp:17:27: error: expected primary-expression before ',' token 17 | map<pair<int, int>, int> dpa; | ^ Main.cpp:17:29: error: expected primary-expression before 'int' 17 | map<pair<int, int>, int> dpa; | ^~~ Main.cpp:29:25: error: 'dpa' was not declared in this scope 29 | dpa[make_pair(s[i], t[i])] = dpa.size(); | ^~~ In file included from /usr/include/c++/13/cassert:44, from /include/cpp/atcoder/dsu.hpp:5, from /include/cpp/atcoder/dsu:1, from Main.cpp:1: Main.cpp:33:16: error: 'dpa' was not declared in this scope 33 | assert(dpa.size() <= 3); | ^~~ Main.cpp:35:9: error: 'set' was not declared in this scope 35 | set<pair<int, int>> gs; | ^~~ Main.cpp:2:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'? 1 | #include <atcoder/dsu> +++ |+#include <set> 2 | using namespace std; Main.cpp:35:26: error: expected primary-expression before '>' token 35 | set<pair<int, int>> gs; | ^~ Main.cpp:35:29: error: 'gs' was not declared in this scope; did you mean 's'? 35 | set<pair<int, int>> gs; | ^~ | s Main.cpp:65:16: error: 'string' was not declared in this scope 65 | vector<string> ans; | ^~~~~~ Main.cpp:2:1: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'? 1 | #include <atcoder/dsu> +++ |+#include <string> 2 | using namespace std; Main.cpp:65:22: error: template argument 1 is invalid 65 | vector<string> ans; | ^ Main.cpp:65:22: error: template argument 2 is invalid Main.cpp:83:37: error: request for member 'push_back' in 'ans', which is of non-class type 'int' 83 | ans.push_back("Yes"); | ^~~~~~~~~ Main.cpp:86:29: error: expected primary-expression before 'int' 86 | set<int> lds; | ^~~ Main.cpp:87:25: error: 'lds' was not declared in this scope 87 | lds.insert(uf.leader(s[i])); | ^~~ Main.cpp:108:37: error: request for member 'push_back' in 'ans', which is of non-class type 'int' 108 | ans.push_back("Yes"); | ^~~~~~~~~ Main.cpp:112:37: error: request for member 'push_back' in 'ans', which is of non-class type 'int' 112 | ans.push_back("No"); | ^~~~~~~~~ Main.cpp:118:29: error: expected primary-expression before 'int' 118 | set<int> lds; | ^~~ Main.cpp:119:25: error: 'lds' was not declared in this scope 119 | lds.insert(uf.leader(s[i])); | ^~~ Main.cpp:145:31: error: expected ';' before 'str' 145 | string str = ""; | ^~~~ | ; Main.cpp:148:33: error: 'str' was not declared in this scope; did you mean 'std'? 148 | str += to_string(v + 1); | ^~~ | std Main.cpp:148:40: error: 'to_string' was not declared in this scope 148 | str += to_string(v + 1); | ^~~~~~~~~ Main.cpp:148:40: note: 'std::to_string' is defined in header '<string>'; did you forget to '#include <string>'? Main.cpp:151:25: error: 'str' was not declared in this scope; did you mean 'std'? 151 | str.pop_back(); | ^~~ | std Main.cpp:152:29: error: request for member 'push_back' in 'ans', which is of non-class type 'int' 152 | ans.push_back(str); | ^~~~~~~~~ Main.cpp:156:29: error: expected primary-expression before 'int' 156 | set<int> lds; | ^~~ Main.cpp:157:25: error: 'lds' was not declared in this scope 157 | lds.insert(uf.leader(s[i])); | ^~~ Main.cpp:176:29: error: request for member 'push_back' in 'ans', which is of non-class type 'int' 176 | ans.push_back(to_string(sum)); | ^~~~~~~~~ Main.cpp:176:39: error: 'to_string' was not declared in this scope 176 | ans.push_back(to_string(sum)); | ^~~~~~~~~ Main.cpp:176:39: note: 'std::to_string' is defined in header '<string>'; did you forget to '#include <string>'? Main.cpp:183:26: error: request for member 'size' in 'ans', which is of non-class type 'int' 183 | for (int i = ans.size() - 1; i >= 0; i--) | ^~~~ Main.cpp:185:17: error: 'cout' was not declared in this scope 185 | cout << ans[i] << endl; | ^~~~ Main.cpp:185:17: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'? Main.cpp:185:28: error: invalid types 'int[int]' for array subscript 185 | cout << ans[i] << endl; | ^ Main.cpp:185:35: error: 'endl' was not declared in this scope 185 | cout << ans[i] << endl; | ^~~~ Main.cpp:2:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'? 1 | #include <atcoder/dsu> +++ |+#include <ostream> 2 | using namespace std;