제출 #567820

#제출 시각아이디문제언어결과실행 시간메모리
5678208e7다리 (APIO19_bridges)C++17
14 / 100
100 ms7756 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T,class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); const int inf = 1<<30; struct edge{ int u, v, w; edge(){u = v = w = 0;} edge(int a, int b, int c){u = a, v = b, w = c;} }; vector<edge> ed; struct DSU{ int par[maxn], siz[maxn]; void init(int n) { for (int i = 1;i <= n;i++) par[i] = i, siz[i] = 1; } int find(int a) { return a == par[a] ? a : (par[a] = find(par[a])); } void Union(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (siz[a] < siz[b]) swap(a, b); par[b] = a; siz[a] += siz[b]; } } d; int ans[maxn]; int main() { io int n, m; cin >> n >> m; for (int i = 0;i < m;i++) { int u, v, w; cin >> u >> v >> w; ed.push_back(edge(u, v, w)); } int q; cin >> q; for (int i = 0;i < q;i++) { int type, s, w; cin >> type >> s >> w; ed.push_back(edge(-i, s, w)); } sort(ed.begin(), ed.end(), [&] (edge x, edge y){return x.w == y.w ? x.u > y.u : x.w > y.w;}); d.init(n); for (auto e:ed) { if (e.u <= 0) { ans[-e.u] = d.siz[d.find(e.v)]; } else { d.Union(e.u, e.v); } } for (int i = 0;i < q;i++) cout << ans[i] << "\n"; } /* 7 6 1 2 4 1 3 5 2 4 2 2 5 1 3 6 7 3 7 3 5 2 3 3 1 4 3 2 3 5 2 2 2 2 1 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...