이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |