#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long n,m,q,x,y,c,ans[500010],t[500010];
vector<pair<long long,pair<long long,long long>>>a;
vector<vector<long long>>f;
long long tata(long long x)
{
if(x==t[x]) return t[x];
t[x]=tata(t[x]);
return t[x];
}
void atribuire(long long nod)
{
ans[nod]=ans[1];
for(auto z:f[nod])
atribuire(z);
return;
}
void combinare(long long x,long long y,long long c)
{
if(tata(x)==1&&tata(y)!=1)
{
f[1].push_back(t[y]);
t[t[y]]=1;
ans[1]=c;
if(t[y]!=1)
atribuire(t[y]);
else
atribuire(y);
return;
}
swap(x,y);
if(t[x]==1&&t[y]!=1)
{
f[1].push_back(t[y]);
t[t[y]]=1;
ans[1]=c;
if(t[y]!=1)
atribuire(t[y]);
else
atribuire(y);
return;
}
if(t[x]!=t[y])
{
f[t[y]].push_back(t[x]);
t[t[x]]=t[y];
}
return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>q;
f.resize(n+5);
for(long long i=1;i<=m;++i)
{
cin>>x>>y>>c;
a.push_back(make_pair(-c,make_pair(x,y)));
}
for(long long i=1;i<=n;++i)
t[i]=i;
sort(a.begin(),a.end());
for(long long i=0;i<m;++i)
{
combinare(a[i].second.first,a[i].second.second,-a[i].first);
}
for(long long i=1;i<=q;++i)
{
cin>>x;
cout<<ans[x]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
3708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3552 ms |
107456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |