# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982974 | 2024-05-15T06:20:33 Z | vjudge1 | Bridges (APIO19_bridges) | C++17 | 54 ms | 51088 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] , 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 : حسن
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 54 ms | 48380 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 53 ms | 48568 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 50 ms | 51008 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 50 ms | 51088 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 53 ms | 48568 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 54 ms | 48380 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |