MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / main

Function main

Data Structures/Dynamic Connectivity Problem.cpp:120–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118bool isquery[N];
119unordered_map<pair<int, int>, int, HASH>st;
120int main() {
121 ios_base::sync_with_stdio(0);
122 cin.tie(0);
123 freopen("connect.in", "r", stdin);
124 freopen("connect.out", "w", stdout);
125 st.reserve(1 << 20);
126 int i, j, k, n, m, u, v;
127 cin >> n >> m;
128 d.init(n);
129 for(i = 1; i <= m; i++) {
130 string ty;
131 cin >> ty;
132 if(ty == "?") {
133 isquery[i] = 1;
134 } else if(ty == "+") {
135 cin >> u >> v;
136 if(u > v) swap(u, v);
137 pair<int, int> p = {u, v};
138 se.insert(p);
139 st[p] = i;
140 } else {
141 cin >> u >> v;
142 if(u > v) swap(u, v);
143 pair<int, int> p = {u, v};
144 se.erase(p);
145 upd(1, 1, m, st[p], i - 1, p); ///in this time range this edge was in the DSU
146 }
147 }
148 for(auto p : se) upd(1, 1, m, st[p], m, p); ///update rest of the edges
149 se.clear();
150 query(1, 1, m);
151 for(i = 1; i <= m; i++) if(isquery[i]) cout << ans[i] << endl;
152 return 0;
153}
154// https://codeforces.com/gym/100551/problem/A

Callers

nothing calls this directly

Calls 6

updFunction · 0.70
queryFunction · 0.70
initMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected