제출 #447501

#제출 시각아이디문제언어결과실행 시간메모리
447501S2speed다리 (APIO19_bridges)C++17
13 / 100
78 ms9704 KiB
#include<bits/stdc++.h> using namespace std; #define all(x) x.begin() , x.end() #define sze(x) (ll)(x.size()) typedef long long ll; typedef pair<ll , ll> pll; typedef pair<bool , pll> plll; const ll maxn = 3e5 + 16 , inf = 2e18; ll n , m , q; ll v[maxn] , u[maxn] , w[maxn]; vector<ll> adj[maxn]; bitset<maxn> mark; ll cnt; void DFS(ll r){ mark[r] = true; cnt++; for(auto i : adj[r]){ if(mark[i]) continue; DFS(i); } return; } void sub1(){ for(ll e = 0 ; e < q ; e++){ ll t; cin>>t; t--; if(t){ cnt = 0; for(ll i = 0 ; i < n ; i++){ mark[i] = false; adj[i].clear(); } ll s , r; cin>>s>>r; s--; for(ll i = 0 ; i < m ; i++){ if(w[i] >= r){ adj[v[i]].push_back(u[i]); adj[u[i]].push_back(v[i]); } } DFS(s); cout<<cnt<<'\n'; } else { ll b , r; cin>>b>>r; b--; w[b] = r; } } return; } struct segtree { ll sz = 1; vector<ll> val; void init(ll n){ while(sz < n) sz <<= 1; val.assign(sz << 1 , inf); return; } void set(ll i , ll k , ll x , ll lx , ll rx){ if(rx - lx == 1){ val[x] = k; return; } ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1; if(i < m){ set(i , k , ln , lx , m); } else { set(i , k , rn , m , rx); } val[x] = min(val[ln] , val[rn]); return; } void set(ll i , ll k){ set(i , k , 0 , 0 , sz); return; } ll cal(ll i , ll k , bool c , ll x , ll lx , ll rx){ if(c){ if(rx >= i) return inf; if(val[x] >= k) return inf; if(rx - lx == 1) return lx; ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1; ll a = cal(i , k , c , ln , lx , m); if(a != inf) return a; a = cal(i , k , c , rn , m , rx); return a; } else { if(lx > i) return -1; if(val[x] >= k) return -1; if(rx - lx == 1) return lx; ll m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1; ll a = cal(i , k , c , rn , m , rx); if(a != -1) return -1; a = cal(i , k , c , ln , m , rx); return a; } } ll cal(ll i , ll k , bool c){ return cal(i , k , c , 0 , 0 , sz); } }; int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin>>n>>m; for(ll i = 0 ; i < m ; i++){ cin>>v[i]>>u[i]>>w[i]; v[i]--; u[i]--; } cin>>q; if(n <= 1e3 && m <= 1e3 && q <= 1e4){ sub1(); return 0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...