답안 #915337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915337 2024-01-23T17:45:09 Z StefanL2005 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
840 ms 92528 KB
#include <bits/stdc++.h>
using namespace std;
#define inf 1000*1000*1000 + 6

struct nod{
    int nr;
    vector<nod*> Ch;
    vector<int> Cost;
};

struct muchie{
    int start, end, cost;
};

bool rule (muchie A, muchie B)
{
    if (A.cost == B.cost)
    {
        if (A.start == B.start)
            return A.end > B.end;
        return A.start > B.start;
    }
    return A.cost > B.cost;
}

void bloom (nod *node, vector<pair<int,int>> &Choice, vector<int> &Check, priority_queue<muchie, vector<muchie>, decltype(&rule)> &Q)
{
    for (int i = 0; i < node->Ch.size(); i++)
    {
        auto vecin = node->Ch[i];

        if (Check[vecin->nr] >= 2)
            continue;

        muchie A; A.start = node->nr; A.end = vecin->nr; A.cost = node->Cost[i] + Choice[node->nr].second;
        Q.push(A);
    }
}

int travel_plan(int n, int m, int R[][2], int L[], int k, int exit[])
{
    vector<int> Check(n, 0);
    vector<nod*> Tree(n);
    vector<pair<int,int>> Choice(n);
    priority_queue<muchie, vector<muchie>, decltype(&rule)> Q(rule);
    
    for (int i = 0; i < n; i++)
    { Tree[i] = new nod; Tree[i]->nr = i; }

    for (int i = 0; i < m; i++)
    {
        int a = R[i][0], b = R[i][1];

        Tree[a]->Ch.push_back(Tree[b]);
        Tree[a]->Cost.push_back(L[i]);
        Tree[b]->Ch.push_back(Tree[a]);
        Tree[b]->Cost.push_back(L[i]);
    }

    for (int i = 0; i < k; i++)
    {
        Choice[exit[i]] = make_pair(0, 0);
        Check[exit[i]] = 2;
    }
    for (int i = 0; i < k; i++)
    {
        auto node = Tree[exit[i]];
        bloom(node, Choice, Check, Q);
    }    

    while (!Q.empty())
    {
        auto A = Q.top();
        Q.pop();
     
        switch(Check[A.end])
        {
            case 0:{ Choice[A.end].first = A.cost; break; }
            case 1:{ 
                Choice[A.end].second = A.cost; 
                bloom(Tree[A.end], Choice, Check, Q);                
            break; }
        }
        Check[A.end]++;
    }

    return Choice[0].second;
}

Compilation message

crocodile.cpp: In function 'void bloom(nod*, std::vector<std::pair<int, int> >&, std::vector<int>&, std::priority_queue<muchie, std::vector<muchie>, bool (*)(muchie, muchie)>&)':
crocodile.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<nod*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < node->Ch.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4456 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4456 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 4 ms 5212 KB Output is correct
13 Correct 4 ms 5212 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4456 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 4 ms 5212 KB Output is correct
13 Correct 4 ms 5212 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4472 KB Output is correct
16 Correct 696 ms 83472 KB Output is correct
17 Correct 66 ms 23848 KB Output is correct
18 Correct 96 ms 25240 KB Output is correct
19 Correct 840 ms 92528 KB Output is correct
20 Correct 422 ms 72408 KB Output is correct
21 Correct 33 ms 12116 KB Output is correct
22 Correct 335 ms 57524 KB Output is correct