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>
#define nl '\n'
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> adj(n);
struct Edge {
int u, v, d;
inline int other(int x) { return u ^ v ^ x; }
};
std::vector<Edge> edges(m);
for (int i = 0; i < m; i++) {
int u, v, d;
std::cin >> u >> v >> d;
--u, --v;
adj[u].emplace_back(i);
adj[v].emplace_back(i);
edges[i] = {u, v, d};
}
auto solve = [&](int s, int w) {
std::queue<int> q;
std::vector<int> vis(n, 0);
q.emplace(s);
vis[s] = 1;
int cnt = 0;
while (q.size()) {
int u = q.front();
q.pop();
cnt++;
for (int eid : adj[u]) {
int v = edges[eid].other(u);
if (edges[eid].d < w) continue;
if (!vis[v]) {
vis[v] = 1;
q.emplace(v);
}
}
}
return cnt;
};
int q;
std::cin >> q;
while (q--) {
int t;
std::cin >> t;
if (t == 1) {
int i, v;
std::cin >> i >> v;
--i;
edges[i].d = v;
} else {
int s, w;
std::cin >> s >> w;
--s;
std::cout << solve(s, w) << nl;
}
}
}
# | 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... |