답안 #47348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47348 2018-05-01T07:03:14 Z dqhungdl 관광 (NOI14_sightseeing) C++17
15 / 25
3500 ms 160336 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
int n,m,T,d[500005];
vector<ii> g[500005];
set<ii> s;

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n>>m>>T;
    int u,v,w;
    while(m--)
    {
        cin>>u>>v>>w;
        g[u].push_back(ii(v,w));
        g[v].push_back(ii(u,w));
    }
    for(int i=2;i<=n;i++)
        d[i]=-1;
    d[1]=1e9;
    s.insert(ii(1e9,1));
    while(s.size()>0)
    {
        int u=(*s.rbegin()).second;
        s.erase(s.find(*s.rbegin()));
        for(int i=0;i<g[u].size();i++)
        {
            int v=g[u][i].first;
            int w=g[u][i].second;
            if(d[v]<min(d[u],w))
            {
                if(d[v]!=-1)
                    s.erase(s.find(ii(d[v],v)));
                d[v]=min(d[u],w);
                s.insert(ii(d[v],v));
            }
        }
    }
    while(T--)
    {
        cin>>u;
        cout<<d[u]<<"\n";
    }
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[u].size();i++)
                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12024 KB Output is correct
2 Correct 12 ms 12136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12304 KB Output is correct
2 Correct 12 ms 12332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15708 KB Output is correct
2 Correct 57 ms 15908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3573 ms 160336 KB Time limit exceeded
2 Halted 0 ms 0 KB -