답안 #51235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51235 2018-06-17T09:43:35 Z Kubalionzzale 관광 (NOI14_sightseeing) C++
15 / 25
3500 ms 116592 KB
#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <functional>

std::vector< std::vector< std::pair<int, int> > > g(1000010);
int ans[1000010] = { 0 };

void bfs()
{
    std::set<std::pair<int, int> , std::greater<std::pair<int, int> > > set;
    set.insert(std::make_pair(2e8, 0));
    bool visited[1000010] = { 0 };

    while (set.empty() == false)
    {
        std::pair<int, int> top = *set.begin();
        int curNode = top.second;
        int curVal = top.first;
        set.erase(set.begin());

  //      std::cout << curNode << " " << curVal << "\n";

        if (visited[curNode])
            continue;
        else
            visited[curNode] = 1;

        for (int i = 0; i < g[curNode].size(); ++i)
        {
            std::pair<int, int> next = g[curNode][i];
            int nextVal = next.first;
            int nextNode = next.second;
            if (std::min(nextVal, curVal) > ans[nextNode])
            {
                ans[nextNode] = std::max(ans[nextNode], std::min(nextVal, curVal));
                set.insert(std::make_pair(std::min(nextVal, curVal), nextNode));
            }
        }
    }
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
//    std::cin >> n >> m >> q;

    while (m--)
    {
        int x, y, quality;
        scanf("%d%d%d", &x, &y, &quality);
//        std::cin >> x >> y >> quality;
        --x,
        --y;

        g[x].push_back(std::make_pair(quality, y));
        g[y].push_back(std::make_pair(quality, x));
    }

    int node[1000010];
    for (int i = 0; i < q; ++i)
    {
        scanf("%d", &node[i]);
//        std::cin >> node[i];
    }

    bfs();

    for (int i = 0; i < q; ++i)
    {
        printf("%d\n", ans[node[i] - 1]);
//        std::cout << ans[node[i] - 1] << "\n";
    }
}

Compilation message

sightseeing.cpp: In function 'void bfs()':
sightseeing.cpp:32:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < g[curNode].size(); ++i)
                         ~~^~~~~~~~~~~~~~~~~~~
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:51:10: 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:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &quality);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &node[i]);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 24824 KB Output is correct
2 Correct 25 ms 24824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 24980 KB Output is correct
2 Correct 23 ms 25044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 27680 KB Output is correct
2 Correct 81 ms 27680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3608 ms 116592 KB Time limit exceeded
2 Halted 0 ms 0 KB -