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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define sz size()
const int N = 5e4 + 5;
pii val[N];
int l[N], r[N], w[N], vis[N];
vector <pii> v[N];
void dfs (int x, int y) {
vis[x] = 1;
for (pii i : v[x]) {
if (vis[i.ff]) continue;
if (y <= i.ss) dfs (i.ff, y);
}
}
int main () {
// freopen ("input.txt", "r", stdin);
int n, m, q;
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> l[i] >> r[i] >> w[i];
val[i] = {(int)v[l[i]].sz, (int)v[r[i]].sz};
v[l[i]].pb({r[i], w[i]});
v[r[i]].pb({l[i], w[i]});
}
cin >> q;
while ( q-- ) {
int query, x, y;
cin >> query >> x >> y;
// cout << "--> " << query << " " << x << " " << y << "\n";
if (query == 1) {
pii pos = val[x];
v[l[x]][pos.ff].ss = y;
v[r[x]][pos.ss].ss = y;
}
else {
dfs (x, y);
int jog = 0;
for (int i = 1; i <= n; ++i) {
if (vis[i]) jog++;
vis[i] = 0;
}
cout << jog << "\n";
}
}
}
# | 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... |