이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
using namespace std;
typedef long long ll;
typedef long double ld;
struct edge {
int v, u, w;
};
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m;
vector<edge> e;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int a, b, w;
cin >> a >> b >> w;
a--, b--;
g[a].pb(len(e));
e.pb({a, b, w});
g[b].pb(len(e));
e.pb({b, a, w});
}
cin >> q;
while(q--) {
int type, id, w;
cin >> type >> id >> w;
id--;
if(type == 1) {
e[2 * id].w = w;
e[2 * id + 1].w = w;
continue;
}
vector<bool> used(n, 0);
deque<int> q;
used[id] = 1;
q.pb(id);
while(len(q)) {
auto now = q.front();
q.pop_front();
for (auto i : g[now]) {
auto x = e[i];
if(used[x.u] || x.w < w)
continue;
used[x.u] = 1;
q.pb(x.u);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if(used[i])
ans++;
}
cout << ans << '\n';
}
return 0;
}
# | 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... |