이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |