Submission #147361

#TimeUsernameProblemLanguageResultExecution timeMemory
147361dimash241Bridges (APIO19_bridges)C++17
0 / 100
3023 ms3144 KiB
#pragma GCC optimize("O3") # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> # include <stdio.h> # include <bits/stdc++.h> #define _USE_MATH_DEFINES_ #define ll long long #define ld long double #define Accepted 0 #define pb push_back #define mp make_pair #define sz(x) (int)(x.size()) #define every(x) x.begin(),x.end() #define F first #define S second #define lb lower_bound #define ub upper_bound #define For(i,x,y) for (ll i = x; i <= y; i ++) #define FOr(i,x,y) for (ll i = x; i >= y; i --) #define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) // ROAD to... Red using namespace __gnu_pbds; using namespace std; template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; inline void Input_Output () { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); } const double eps = 0.000001; const ld pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const ll MOD = 1e18 + 9; const ll INF = 1e18 + 123; const int inf = 2e9 + 11; const int mxn = 1e6 + 9; const int N = 1e5 + 3; const int M = 22; const int pri = 997; const int Magic = 720; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int n, m, k; int ls[N]; struct edge { int a, b, c; bool operator < (const edge &t) const { return c < t.c; } } e[N]; struct que { int t, a, b; } Q[N]; int p[N]; int sz[N]; bool mark[N]; int ans[N]; vector < int > ch; int get (int x) { if (p[x] != x) return get(p[x]); return x; } bool uni (int a, int b, bool type = 0) { a = get(a); b = get(b); if (a == b) return 0; if (sz[a] < sz[b]) swap(sz[a], sz[b]); if (type) ch.pb(b); p[b] = a; sz[a] += sz[b]; } int main () { cin >> n >> m; for (int i = 1; i <= m; i ++) { cin >> e[i].a >> e[i].b >> e[i].c; } vector < que > q; cin >> k; for (int i = 1; i <= k; i ++) { cin >> Q[i].t >> Q[i].a >> Q[i].b; } for (int qq = 1; qq <= k; qq ++) { q.pb(Q[qq]); if (qq == k || q.size() == Magic) { for (int i = 1; i <= n; i ++) { p[i] = i; sz[i] = 1; } for (int i = 1; i <= m; i ++) mark[i] = 0; vector < int > cv; vector < pair < int, int > > qv; for (int i = 0; i < q.size(); i ++) { auto o = q[i]; if (o.t == 1) { mark[o.a] = 1; cv.pb(o.a); } else { qv.pb({o.b, i}); } } sort(e + 1, e + m + 1); sort(every(cv)); sort(qv.rbegin(), qv.rend()); cv.resize(unique(every(cv)) - cv.begin()); int ptr = m; for (auto c : qv) { int s = q[c.S].a, r = q[c.S].b; while (ptr > 0 && r <= e[ptr].c) { if (!mark[ptr]) { uni(e[ptr].a, e[ptr].b); } ptr --; } for (auto x : cv) ls[x] = e[x].c; for (int i = 0; i < c.S; i ++) if (q[i].t == 1) { ls[q[i].a] = q[i].b; } for (auto x : cv) if (ls[x] >= r) { uni(e[x].a, e[x].b, 1); } ans[c.S] = sz[get(s)]; while (ch.size()) { int y = ch.back(); ch.pop_back(); int x = p[y]; p[y] = y; sz[x] -= sz[y]; } } for (int i = 0; i < q.size(); i ++) { auto o = q[i]; if (o.t == 1) { e[o.a].c = o.b; } else { cout << ans[i] << endl; } } q.clear(); } } return Accepted; } // B...a

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < q.size(); i ++) { 
                    ~~^~~~~~~~~~
bridges.cpp:149:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < q.size(); i ++) { 
                    ~~^~~~~~~~~~
bridges.cpp: In function 'bool uni(int, int, bool)':
bridges.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...