# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29471 | samir_droubi | Sightseeing (NOI14_sightseeing) | C++14 | 3500 ms | 99516 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;
int n,m,q;
const int mxn=(5e5)+5;
vector<pair<int,int> >gr[mxn];
int ans[mxn];
set<pair<int,int> >s;
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=0;i<m;++i)
{
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
gr[x].push_back({y,w});
gr[y].push_back({x,w});
}
memset(ans,-1,sizeof ans);
ans[1]=(1e9);
s.insert({ans[1],1});
while(!s.empty())
{
set< pair<int,int> >::iterator it=s.end();
--it;
int vl=it->first;
int v=it->second;
s.erase(it);
if(vl<ans[v])continue;
ans[v]=vl;
for(int i=0;i<gr[v].size();++i)
{
int u=gr[v][i].first;
int w=gr[v][i].second;
if(min(vl,w)>ans[u])
{
ans[u]=min(vl,w);
s.insert({ans[u],u});
}
}
}
while(q--)
{
int x;
scanf("%d",&x);
printf("%d\n",ans[x]);
}
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... |