Submission #47360

# Submission time Handle Problem Language Result Execution time Memory
47360 2018-05-01T07:53:19 Z dqhungdl Sightseeing (NOI14_sightseeing) C++17
15 / 25
3500 ms 159432 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

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

void ReadInt(int &number)
{
    number=0;
    int c=getchar();
    while(c<'0'||c>'9')
        c=getchar();
    for (; ('0'<=c&&c<='9'); c=getchar())
        number=number*10+c-48;
}

int Min(int x,int y)
{
    return (x<y?x:y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    ReadInt(n);
    ReadInt(m);
    ReadInt(T);
    int u,v,w;
    while(m--)
    {
        ReadInt(u);
        ReadInt(v);
        ReadInt(w);
        g[u].push_back(ii(v,w));
        g[v].push_back(ii(u,w));
    }
    d[1]=1e9;
    Q.push(ii(1e9,1));
    while(Q.size()>0)
    {
        u=Q.top().second;
        w=Q.top().first;
        Q.pop();
        if(d[u]==w)
            for(int i=0; i<g[u].size(); ++i)
            {
                v=g[u][i].first;
                w=g[u][i].second;
                if(d[v]<Min(d[u],w))
                {
                    d[v]=Min(d[u],w);
                    Q.push(ii(d[v],v));
                }
            }
    }
    while(T--)
    {
        ReadInt(u);
        cout<<d[u]<<'\n';
    }
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:49:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=0; i<g[u].size(); ++i)
                          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 13 ms 12264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12340 KB Output is correct
2 Correct 13 ms 12340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 14352 KB Output is correct
2 Correct 35 ms 14352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2776 ms 106172 KB Output is correct
2 Execution timed out 3550 ms 159432 KB Time limit exceeded