답안 #982947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982947 2024-05-15T05:59:34 Z vjudge1 다리 (APIO19_bridges) C++17
0 / 100
54 ms 48556 KB
#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];

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];
}

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;
    while(q--){
        cin>>k>>x>>y;
        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";
        }
    }
}

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 : حسن

Compilation message

bridges.cpp: In function 'void solve()':
bridges.cpp:45:20: warning: unused variable 'j' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                    ^
bridges.cpp:45:23: warning: unused variable 'l' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                       ^
bridges.cpp:45:26: warning: unused variable 'r' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                          ^
bridges.cpp:45:38: warning: unused variable 's' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                      ^
bridges.cpp:45:46: warning: unused variable 'f' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                              ^
bridges.cpp:45:58: warning: unused variable 'mx' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                          ^~
bridges.cpp:45:67: warning: unused variable 'mn' [-Wunused-variable]
   45 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                                   ^~
bridges.cpp: In function 'int main()':
bridges.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 48556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 48488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 48544 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 48504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 48488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 48556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -