이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef evenvalue
#include "debug.h"
#define debug(...) print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...)
#endif
using int64 = long long;
using ld = long double;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
namespace read {
int Int() {
int x;
cin >> x;
return x;
}
int64 Int64() {
int64 x;
cin >> x;
return x;
}
char Char() {
char c;
cin >> c;
return c;
}
string String() {
string s;
cin >> s;
return s;
}
double Double() {
return stod(String());
}
ld LongDouble() {
return stold(String());
}
template<typename T1, typename T2>
pair<T1, T2> Pair() {
pair<T1, T2> p;
cin >> p.first >> p.second;
return p;
}
template<typename T>
vector<T> Vec(const int n) {
vector<T> v(n);
for (T &x : v) {
cin >> x;
}
return v;
}
template<typename T>
vector<vector<T>> VecVec(const int n, const int m) {
vector<vector<T>> v(n);
for (vector<T> &vec : v) {
vec = Vec<T>(m);
}
return v;
}
}//namespace read
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
class dsu {
int n;
std::vector<int> e;
int pfind(const int x) {
return (e[x] < 0 ? x : e[x] = pfind(e[x]));
}
public:
dsu() : n(0), comp(0) {}
explicit dsu(const int n) : n(n), comp(n), e(n, -1) {}
int comp;
int find(const int x) {
assert(0 <= x and x < n);
return pfind(x);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y];
e[y] = x;
comp--;
return true;
}
bool same(const int x, const int y) {
return (find(x) == find(y));
}
int size(const int x) {
return -e[find(x)];
}
std::vector<std::vector<int>> components() {
std::vector<std::vector<int>> res(n);
for (int x = 0; x < n; x++) {
res[pfind(x)].push_back(x);
}
res.erase(
std::remove_if(res.begin(), res.end(), [&](const std::vector<int> &v) { return v.empty(); }),
res.end()
);
return res;
}
};
struct edge {
int x;
int y;
int w;
};
inline void solution() {
const int n = read::Int();
const int m = read::Int();
vector<edge> edges(m);
for (edge &e : edges) {
e.x = read::Int() - 1;
e.y = read::Int() - 1;
e.w = read::Int();
}
int qq = read::Int();
while (qq--) {
const int t = read::Int();
if (t == 1) {
const int e = read::Int() - 1;
const int w = read::Int();
edges[e].w = w;
} else {
const int start = read::Int() - 1;
const int speed = read::Int();
dsu d(n);
vector<edge> bridges = edges;
sort(bridges.begin(), bridges.end(), [&](const edge &e1, const edge &e2) {
return e1.w > e2.w;
});
for (const edge &bridge : bridges) {
if (bridge.w < speed) break;
d.unite(bridge.x, bridge.y);
}
cout << d.size(start) << '\n';
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
cout << fixed << setprecision(10);
int testcases = 1;
//cin >> testcases;
while (testcases--) {
solution();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In constructor 'dsu::dsu(int)':
bridges.cpp:86:7: warning: 'dsu::comp' will be initialized after [-Wreorder]
86 | int comp;
| ^~~~
bridges.cpp:76:20: warning: 'std::vector<int> dsu::e' [-Wreorder]
76 | std::vector<int> e;
| ^
bridges.cpp:84:12: warning: when initialized here [-Wreorder]
84 | explicit dsu(const int n) : n(n), comp(n), e(n, -1) {}
| ^~~
# | 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... |