제출 #927070

#제출 시각아이디문제언어결과실행 시간메모리
927070hqminhuwu다리 (APIO19_bridges)C++14
0 / 100
3047 ms69472 KiB
#include <bits/stdc++.h> #define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a) #define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);) #define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a) #define st first #define nd second #define ll long long #define ull unsigned long long #define pii pair <int,int> #define pll pair <ll,ll> #define piii pair <int,pii> #define vi vector <int> #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define file "test" using namespace std; const int N = 1e5 + 5; const ll oo = 1e9; const ll mod = 1e9 + 7; int n, m, i, u, v, w, q, t[N], x[N], y[N], uwu = 317, par[N], sz[N], mk[N], ans[N], j; piii edge[N]; vi uc, ask, upd, qq[N]; stack <int> s; int get (int u){ while (par[u] != u) u = par[u]; return u; } void update (int u, int v){ u = get(u); v = get(v); //cout << u << " " << v << "\n"; if (u == v) return; if (sz[u] < sz[v]) swap(u, v); s.push(v); par[v] = u; sz[u] += sz[v]; } void rollback (int pv){ while (s.size() > pv){ int u = s.top(); s.pop(); sz[par[u]] -= sz[u]; par[u] = u; } } void rs (){ ask.clear(); upd.clear(); uc.clear(); memset(mk, 0, sizeof mk); for (int h = 1; h <= n; h++) par[h] = h, sz[h] = 1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef hqm freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); #endif cin >> n >> m; forr (i, 1, m){ cin >> u >> v >> w; edge[i] = {w, {u, v}}; } cin >> q; forr (i, 1, q) cin >> t[i] >> x[i] >> y[i]; for (int i = 1; i <= q; i += uwu){ int lmt = min (i + uwu - 1, q); rs(); forr (j, i, lmt) if (t[j] == 1) upd.pb(j); forr (j, i, lmt) if (t[j] == 1) mk[x[j]] = 1, edge[x[j]].st = y[j]; else { ask.pb(j); for (int v : upd) if (edge[x[v]].st >= y[j]) qq[j].pb(v); } forr (i, 1, m){ if (mk[i]) continue; uc.pb(i); } sort(all(ask), [&](int u, int v) {return y[u] > y[v]; }); sort(all(uc), [&](int u, int v) {return edge[u].st > edge[v].st; }); int it = 0; for (int u : ask){ while (it < uc.size() && edge[uc[it]].st >= y[u]) update (edge[uc[it]].nd.st, edge[uc[it]].nd.nd), it++; int prev = s.size(); for (int v : qq[u]){ update(edge[x[v]].nd.st, edge[x[v]].nd.nd); } ans[u] = sz[get(x[u])]; rollback(prev); } } forr (i, 1, q) if (t[i] - 1) cout << ans[i] << "\n"; return 0; } /* */

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'void rollback(int)':
bridges.cpp:46:18: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |  while (s.size() > pv){
      |         ~~~~~~~~~^~~~
bridges.cpp: In function 'int main()':
bridges.cpp:107:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |    while (it < uc.size() && edge[uc[it]].st >= y[u])
      |           ~~~^~~~~~~~~~~
#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...