This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 1000;
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;
};
int p[N];
int sz[N];
int mark[N];
int ans[N];
vector < int > res;
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 () {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i ++) {
scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
}
vector < que > q;
scanf("%d", &k);
for (int qq = 1; qq <= k; qq ++) {
que Q;
scanf("%d%d%d", &Q.t, &Q.a, &Q.b);
q.pb(Q);
if (qq == k || q.size() == Magic) {
for (int i = 1; i <= n; i ++) {
p[i] = i;
sz[i] = 1;
}
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 --;
}
ch.clear();
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 {
printf("%d\n", ans[i]);
}
}
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:152: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:87:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
bridges.cpp: In function 'int main()':
bridges.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &k);
~~~~~^~~~~~~~~~
bridges.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &Q.t, &Q.a, &Q.b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |