이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using int128 = __int128_t;
using pll = pair<ll, ll>;
template <class T>
using vec = vector<T>;
template <class T>
using indexed_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define FOR(i, s, e) for (ll i = (ll)s; i < (ll)e; i++)
#define CFOR(i, s, e) for (ll i = (ll)s; i <= (ll)e; i++)
#define TRAV(e, a) for (const auto &e : a)
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << "ln" << __LINE__ << ": " << #x << " = " << x << endl;
template <class T, class = decay_t<decltype(*begin(declval<T>()))>,
class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &out, const T &obj) {
out << "[";
for (auto it = obj.begin(); it != obj.end(); it++) {
out << &", "[2 * (it == obj.begin())] << *it;
}
return out << "]";
}
template <class K, class V>
ostream &operator<<(ostream &out, const pair<K, V> &obj) {
return out << "(" << obj.first << ", " << obj.second << ")";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, m;
cin >> n >> m;
vec<vec<pll>> graph(n + 1);
vec<ll> w(m + 1);
CFOR(i, 1, m) {
ll a, b;
cin >> a >> b >> w[i];
graph[a].push_back({b, i});
graph[b].push_back({a, i});
}
ll q;
cin >> q;
vec<vec<ll>> queries(q, vec<ll>(3));
FOR(i, 0, q) {
cin >> queries[i][0] >> queries[i][1] >> queries[i][2];
}
vec<bool> visited(n + 1);
FOR(i, 0, q) {
if (queries[i][0] == 1) {
w[queries[i][1]] = queries[i][2];
} else {
fill(all(visited), 0ll);
function<void(ll)> dfs = [&](ll curr) {
visited[curr] = 1;
TRAV(e, graph[curr]) {
if (visited[e.first] || queries[i][2] > w[e.second])
continue;
dfs(e.first);
}
};
dfs(queries[i][1]);
cout << accumulate(all(visited), 0ll) << "\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... |