# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
982975 | vjudge1 | 다리 (APIO19_bridges) | C++17 | 102 ms | 26684 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] ,p[N] , sz[N] , c[N] , d[N] , ans[N];
vector<pair<int,int>>v[N];
ll get(int x){
return (p[x] == x ? x : get(p[x]));
}
void join(int x , int y){
x = get(x) , y = get(y);
if(x != y){
if(sz[x] < sz[y])
swap(x , y);
p[y] = x;
sz[x] += sz[y];
}
}
bool bmp(int i , int j){
return c[i] > c[j];
}
struct query{
ll x , y , k;
}Q[N];
bool bmp1(query &i , query &j){
return i.y > j.y;
}
void solve()
{
ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
cin>>n>>m;
for(i = 1; i <= m; i++){
cin>>a[i]>>b[i]>>c[i];
v[a[i]].pb({b[i] , c[i]});
v[b[i]].pb({a[i] , c[i]});
d[i] = i;
}
cin>>q;
vector<pair<int,int>>vc;
for(j = 1; j <= q; j++){
cin>>k>>x>>y;
Q[j] = {x , y , j};
if(max({n , m , q}) <= 1000){
if(k == 1){
c[x] = y;
}else {
for(i = 1; i <= n; i++)
p[i] = i , sz[i] = 1;
for(i = 1; i <= m; i++){
if(c[i] >= y){
join(a[i] , b[i]);
}
}
cout<<sz[get(x)]<<"\n";
}
if(j == q)
return;
}
}
sort(d + 1 , d + m + 1 , bmp);
sort(Q + 1 , Q + q + 1 , bmp1);
for(i = 1; i <= n; i++)
p[i] = i , sz[i] = 1;
l = 1;
for(i = 1; i <= m + 1; i++){
j = d[i];
while(l <= q && Q[l].y > c[j]){
ans[Q[l].k] = sz[get(Q[l].x)];
l++;
}
join(a[j] , b[j]);
if(i == m + 1)
continue;
}
for(j = 1; j <= q; j++)
cout<<ans[j]<<"\n";
}
int main(){
TL;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |