답안 #51259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51259 2018-06-17T10:30:50 Z Kubalionzzale 관광 (NOI14_sightseeing) C++14
0 / 25
2 ms 384 KB
#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <functional>

//std::vector< std::vector< std::pair<int, int> > > g(500010);
int ans[5000010] = { 0 };
std::pair<int, std::pair<int, int> > edge[50000010];
int n, m, q;

void bfs()
{
    std::set<std::pair<int, int> , std::greater<std::pair<int, int> > > set;
    set.insert(std::make_pair(2e8, 0));
    bool visited[5000010] = { 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 = std::lower_bound(edge, edge + m * 2, std::make_pair(curNode, std::make_pair(0, 0))) - edge; i < 2 * m; ++i)
        {
            if (edge[i].first != curNode)
                break;
            int nextVal = edge[i].second.first;
            int nextNode = edge[i].second.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);
//    scanf("%d%d%d", &n, &m, &q);
    std::cin >> n >> m >> q;

    for (int i = 0; i < m; ++i)
    {
        int x, y, quality;
//        scanf("%d%d%d", &x, &y, &quality);
        std::cin >> x >> y >> quality;
        --x,
        --y;


        edge[i] = std::make_pair(x, std::make_pair(quality, y));
        edge[m + i] = std::make_pair(y, std::make_pair(quality, x));
    }

    std::sort(edge, edge + 2 * m);

    int node[5000010];
    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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -