# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29479 | samir_droubi | Sightseeing (NOI14_sightseeing) | C++14 | 3500 ms | 110836 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];
int mn=(1e9);
vector<int>e[mxn];
queue<int>qq;
void bfs()
{
while(!qq.empty())
{
int v=qq.front();
qq.pop();
for(int i=0;i<gr[v].size();++i)
{
int u=gr[v][i].first;
int w=gr[v][i].second;
if(ans[u]!=-1)continue;
if(w>=mn)ans[u]=mn,qq.push(u);
else e[w].push_back(u);
}
}
}
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);
qq.push(1);
bfs();
for(int i=(1e5);i>=0;--i)
{
mn=i;
for(int j=0;j<e[i].size();++j)
{
int v=e[i][j];
if(ans[v]!=-1)continue;
ans[v]=i;
qq.push(v);
}
bfs();
}
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... |