답안 #29471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29471 2017-07-19T12:09:36 Z samir_droubi 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 99516 KB
#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

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:30:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<gr[v].size();++i)
                      ^
sightseeing.cpp:10:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&q);
                             ^
sightseeing.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&w);
                                 ^
sightseeing.cpp:44:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15696 KB Output is correct
2 Correct 3 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15828 KB Output is correct
2 Correct 0 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 18204 KB Output is correct
2 Correct 46 ms 17544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3500 ms 99516 KB Execution timed out
2 Halted 0 ms 0 KB -