이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define MAX 100000
#define u second.first
#define v second.second
#define w first.first
#define tipo first.second
#define padre first
#define tam second
lli n,m,q,a,b,c,t,x,y;
vector< pair<pair<lli,lli>, pair<lli,lli> > > orden;
pair<lli,lli> uf[MAX];
lli res[MAX+2];
lli sube(lli pos) {
if (uf[pos].padre == pos) return pos;
uf[pos].padre = sube(uf[pos].padre);
return uf[pos].padre;
}
void une(lli a, lli b) {
uf[b].padre = a;
uf[a].tam += uf[b].tam;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b >> c;
c = -c;
orden.push_back({{c,1},{a,b} });
}
cin >> q;
rep(Q,1,q) {
cin >> t >> a >> b;
b = -b;
orden.push_back({ {b,2},{a,t} });
}
sort(orden.begin(), orden.end());
for (auto act : orden) {
if (act.tipo == 1) {
x = sube(act.u);
y = sube(act.v);
if (x != y) une(x,y);
}
else {
x = sube(act.u);
res[act.v] = uf[x].tam;
}
}
rep(i,1,q) cout << res[i] << "\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... |