# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
265367 | T0p_ | Sightseeing (NOI14_sightseeing) | C++14 | 3028 ms | 121752 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
struct EDGE
{
int u, v, w;
bool operator < (const EDGE & o) const{
return w > o.w;
}
};
int pa[500500], ans[500500];
vector<EDGE> e;
vector<pair<int, int>> g[500500];
int fp(int u)
{
return (u == pa[u]) ? u : pa[u] = fp(pa[u]);
}
void dfs(int u, int p, int v)
{
ans[u] = v;
for(auto x : g[u])
{
if(x.first == p) continue ;
dfs(x.first, u, min(v, x.second));
}
}
int main()
{
int n, m, q;
scanf(" %d %d %d",&n,&m,&q);
for(int i=1 ; i<=n ; i++)
pa[i] = i;
while(m--)
{
int u, v, w;
scanf(" %d %d %d",&u,&v,&w);
e.pb({u, v, w});
}
sort(e.begin(), e.end());
for(auto x : e)
{
int u = fp(x.u), v = fp(x.v);
if(u != v)
{
pa[u] = v;
g[x.u].pb({x.v, x.w});
g[x.v].pb({x.u, x.w});
}
}
dfs(1, 0, 1e9);
while(q--)
{
int d;
scanf(" %d",&d);
printf("%d\n",ans[d]);
}
return 0;
}
Compilation message (stderr)
# | 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... |