이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
vector <int> par, w;
int parent(int node) {
if(par[node] == node) return node;
return par[node] = parent(par[node]);
}
void dsu(int a, int b) {
a = parent(a);
b = parent(b);
if(a == b) return;
if(w[a] < w[b]) swap(a, b);
// a ya byi ekle
w[a] += w[b];
par[b] = par[a];
}
int32_t main(){
fast
int n, m;
cin >> n >> m;
vector <array<int, 3> > edges;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
edges.push_back({c, a, b});
}
int q;
cin >> q;
vector <array<int, 3> > queries;
for(int i = 0; i < q; i++) {
int type, a, b;
cin >> type >> a >> b;
queries.push_back({b, a, i});
}
{
sort(queries.begin(), queries.end());
sort(edges.begin(), edges.end());
reverse(queries.begin(), queries.end());
reverse(edges.begin(), edges.end());
}
par.resize(n + 1);
w.resize(n + 1);
for(int i = 1; i <= n; i++) par[i] = i, w[i] = 1;
vector <int> ans(q);
int it = 0;
for(auto [we, from, ind]:queries) {
while(it < edges.size() and edges[it][0] >= we) {
dsu(edges[it][1], edges[it][2]);
it++;
}
ans[ind] = w[parent(from)];
}
for(int i = 0; i < q; i++) {
cout << ans[i] << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'int32_t main()':
bridges.cpp:54:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while(it < edges.size() and edges[it][0] >= we) {
| ~~~^~~~~~~~~~~~~~
# | 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... |