Submission #713534

#TimeUsernameProblemLanguageResultExecution timeMemory
713534bin9638Bridges (APIO19_bridges)C++17
14 / 100
176 ms18252 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define N 100010 #define ii pair<int,int> #define fs first #define sc second #define ld double struct canh { int u,v,L; bool operator<(const canh&A)const { return L>A.L; } }edge[N]; struct DSU { int lab[N]; void init() { memset(lab,-1,sizeof(lab)); } int root(int u) { if(lab[u]<0) return u; return(lab[u]=root(lab[u])); } void update(int u,int v) { if((u=root(u))==(v=root(v))) return; if(lab[u]>lab[v]) swap(u,v); lab[u]+=lab[v]; lab[v]=u; } }T; int kq[N],n,m,q; ii tv[N]; map<ii,vector<int>>mp; int main() { #ifdef SKY freopen("A.inp","r",stdin); freopen("A.out","w",stdout); #endif // SKY ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; for(int i=1;i<=m;i++) cin>>edge[i].u>>edge[i].v>>edge[i].L; cin>>q; sort(edge+1,edge+1+m); for(int i=1;i<=q;i++) { cin>>tv[i].fs>>tv[i].sc>>tv[i].fs; mp[tv[i]].pb(i); } T.init(); sort(tv+1,tv+1+q,greater<ii>()); for(int i=1,pos=1;i<=q;i++) { while(pos<=m&&edge[pos].L>=tv[i].fs) { T.update(edge[pos].u,edge[pos].v); pos++; } int id=mp[tv[i]].back(); mp[tv[i]].pop_back(); kq[id]=-T.lab[T.root(tv[i].sc)]; } for(int i=1;i<=q;i++)cout<<kq[i]<<"\n"; 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...