This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define x first
#define y second
#define pd pair<double,double>
const int siz = 1e5 + 1;
int ans[siz];
vi ed[siz];
vector<vi> e;
vector<vi> q2;
multiset<pi> fr[siz];
void dfs(int i, int b,bitset<siz>&v) {
if (v[i])return;
v[i] = 1;
for (pi f : fr[i]) {
if (f.y >= b) {
dfs(f.x,b,v);
}
}
}
vi c[siz];
int my[siz];
void con(int a, int b) {
int u = my[a], v = my[b];
if (u == v)return;
if (c[u].size() > c[v].size())swap(u, v);
for (int i : c[u]) {
my[i] = v;
c[v].push_back(i);
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v, d;
cin >> u >> v >> d;
u--, v--;
fr[u].insert({ v,d });
fr[v].insert({ u,d });
ed[i] = { d,u,v };
e.push_back({ d,u,v });
}for (int i = 0; i < n; i++) {
c[i].push_back(i);
my[i] = i;
}
sort(e.begin(), e.end());
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int t,a,b;
cin >> t>>a>>b;
a--;
if (t == 1) {
vi v = ed[a];
fr[v[1]].erase(fr[v[1]].find({ v[2], v[0] }));
fr[v[2]].erase(fr[v[2]].find({ v[1], v[0] }));
fr[v[1]].insert({ v[2],b });
fr[v[2]].insert({ v[1],b });
ed[a][0] = b;
}
else {
q2.push_back({ b,a,i });
}
}
reverse(e.begin(), e.end());
sort(q2.begin(), q2.end()); int it = 0;
reverse(q2.begin(), q2.end());
for (int i = 0; i < m; i++) {
while ((it < q) && (e[i][0] < q2[it][0])) {
ans[q2[it][2]] = c[my[q2[it][1]]].size();
it++;
}
con(e[i][1], e[i][2]);
if (i == m - 1) {
while (it < q) {
ans[q2[it][2]] = c[my[q2[it][1]]].size();
it++;
}
}
}
for (int i = 0; i < q; i++)cout << max(1,ans[i]) << "\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# | 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... |