답안 #1109114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109114 2024-11-06T04:11:22 Z nh0902 악어의 지하 도시 (IOI11_crocodile) C++14
컴파일 오류
0 ms 0 KB
vector<pair<int, long long>> g[N];

vector<int> Exit;

int trace1[N], trace2[N];

long long min_dist1[N], min_dist2[N];

bool update(int x, int i, long long d) {
    if (x == trace2[i]) {
        if (min_dist2[i] <= d) {
            return false;
        }
        min_dist2[i] = d;
        if (min_dist1[i] > min_dist2[i]) {
            swap(min_dist1[i], min_dist2[i]);
            swap(trace1[i], trace2[i]);
        }
        return true;
    }

    if (x == trace1[i]) {
        if (min_dist1[i] <= d) {
            return false;
        }
        min_dist1[i] = d;
        return true;
    }

    if (min_dist2[i] <= d) {
        return false;
    }
    min_dist2[i] = d;
    trace2[i] = x;
    if (min_dist1[i] > min_dist2[i]) {
        swap(min_dist1[i], min_dist2[i]);
        swap(trace1[i], trace2[i]);
    }
    return true;
}

int travel_plan(int n, int m, int r[][2], int w[], int k, int e[]) {
    for (int i = 0; i < m; i ++) {
        g[r[i][0]].push_back({r[i][1], w[i]});
        g[r[i][1]].push_back({r[i][0], w[i]});
    }

    for (int i = 0; i < k; i ++) {
        Exit.push_back(e[i]);
    }

    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;

    for (int i = 0; i < n; i ++) {
        min_dist1[i] = min_dist2[i] = inf;
        trace1[i] = n;
        trace2[i] = n;
    }

    for (int a : Exit) {
        min_dist1[a] = min_dist2[a] = 0;
        trace1[a] = a;
        trace2[a] = a;
        pq.push({0, a});
    }

    int x;
    long long d;

    while (!pq.empty()) {
        auto [d, x] = pq.top();
        pq.pop();

        if (d > min_dist2[x]) continue;

        for (pair<int, long long> e : g[x]) {
            if (update(x, e.first, d + e.second)) {
                if (min_dist2[e.first] < inf) {
                    pq.push({min_dist2[e.first], e.first});
                }
            }
        }
    }

    return min_dist2[0];
}

Compilation message

crocodile.cpp:1:1: error: 'vector' does not name a type
    1 | vector<pair<int, long long>> g[N];
      | ^~~~~~
crocodile.cpp:3:1: error: 'vector' does not name a type
    3 | vector<int> Exit;
      | ^~~~~~
crocodile.cpp:5:12: error: 'N' was not declared in this scope
    5 | int trace1[N], trace2[N];
      |            ^
crocodile.cpp:5:23: error: 'N' was not declared in this scope
    5 | int trace1[N], trace2[N];
      |                       ^
crocodile.cpp:7:21: error: 'N' was not declared in this scope
    7 | long long min_dist1[N], min_dist2[N];
      |                     ^
crocodile.cpp:7:35: error: 'N' was not declared in this scope
    7 | long long min_dist1[N], min_dist2[N];
      |                                   ^
crocodile.cpp: In function 'bool update(int, int, long long int)':
crocodile.cpp:10:14: error: 'trace2' was not declared in this scope
   10 |     if (x == trace2[i]) {
      |              ^~~~~~
crocodile.cpp:11:13: error: 'min_dist2' was not declared in this scope
   11 |         if (min_dist2[i] <= d) {
      |             ^~~~~~~~~
crocodile.cpp:14:9: error: 'min_dist2' was not declared in this scope
   14 |         min_dist2[i] = d;
      |         ^~~~~~~~~
crocodile.cpp:15:13: error: 'min_dist1' was not declared in this scope
   15 |         if (min_dist1[i] > min_dist2[i]) {
      |             ^~~~~~~~~
crocodile.cpp:16:13: error: 'swap' was not declared in this scope
   16 |             swap(min_dist1[i], min_dist2[i]);
      |             ^~~~
crocodile.cpp:17:18: error: 'trace1' was not declared in this scope
   17 |             swap(trace1[i], trace2[i]);
      |                  ^~~~~~
crocodile.cpp:22:14: error: 'trace1' was not declared in this scope
   22 |     if (x == trace1[i]) {
      |              ^~~~~~
crocodile.cpp:23:13: error: 'min_dist1' was not declared in this scope
   23 |         if (min_dist1[i] <= d) {
      |             ^~~~~~~~~
crocodile.cpp:26:9: error: 'min_dist1' was not declared in this scope
   26 |         min_dist1[i] = d;
      |         ^~~~~~~~~
crocodile.cpp:30:9: error: 'min_dist2' was not declared in this scope
   30 |     if (min_dist2[i] <= d) {
      |         ^~~~~~~~~
crocodile.cpp:33:5: error: 'min_dist2' was not declared in this scope
   33 |     min_dist2[i] = d;
      |     ^~~~~~~~~
crocodile.cpp:34:5: error: 'trace2' was not declared in this scope
   34 |     trace2[i] = x;
      |     ^~~~~~
crocodile.cpp:35:9: error: 'min_dist1' was not declared in this scope
   35 |     if (min_dist1[i] > min_dist2[i]) {
      |         ^~~~~~~~~
crocodile.cpp:36:9: error: 'swap' was not declared in this scope
   36 |         swap(min_dist1[i], min_dist2[i]);
      |         ^~~~
crocodile.cpp:37:14: error: 'trace1' was not declared in this scope
   37 |         swap(trace1[i], trace2[i]);
      |              ^~~~~~
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:44:9: error: 'g' was not declared in this scope
   44 |         g[r[i][0]].push_back({r[i][1], w[i]});
      |         ^
crocodile.cpp:49:9: error: 'Exit' was not declared in this scope
   49 |         Exit.push_back(e[i]);
      |         ^~~~
crocodile.cpp:52:5: error: 'priority_queue' was not declared in this scope
   52 |     priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
      |     ^~~~~~~~~~~~~~
crocodile.cpp:52:20: error: 'pair' was not declared in this scope
   52 |     priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
      |                    ^~~~
crocodile.cpp:52:25: error: expected primary-expression before 'long'
   52 |     priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
      |                         ^~~~
crocodile.cpp:55:9: error: 'min_dist1' was not declared in this scope
   55 |         min_dist1[i] = min_dist2[i] = inf;
      |         ^~~~~~~~~
crocodile.cpp:55:24: error: 'min_dist2' was not declared in this scope
   55 |         min_dist1[i] = min_dist2[i] = inf;
      |                        ^~~~~~~~~
crocodile.cpp:55:39: error: 'inf' was not declared in this scope; did you mean 'int'?
   55 |         min_dist1[i] = min_dist2[i] = inf;
      |                                       ^~~
      |                                       int
crocodile.cpp:56:9: error: 'trace1' was not declared in this scope
   56 |         trace1[i] = n;
      |         ^~~~~~
crocodile.cpp:57:9: error: 'trace2' was not declared in this scope
   57 |         trace2[i] = n;
      |         ^~~~~~
crocodile.cpp:60:18: error: 'Exit' was not declared in this scope
   60 |     for (int a : Exit) {
      |                  ^~~~
crocodile.cpp:61:9: error: 'min_dist1' was not declared in this scope
   61 |         min_dist1[a] = min_dist2[a] = 0;
      |         ^~~~~~~~~
crocodile.cpp:61:24: error: 'min_dist2' was not declared in this scope
   61 |         min_dist1[a] = min_dist2[a] = 0;
      |                        ^~~~~~~~~
crocodile.cpp:62:9: error: 'trace1' was not declared in this scope
   62 |         trace1[a] = a;
      |         ^~~~~~
crocodile.cpp:63:9: error: 'trace2' was not declared in this scope
   63 |         trace2[a] = a;
      |         ^~~~~~
crocodile.cpp:64:9: error: 'pq' was not declared in this scope
   64 |         pq.push({0, a});
      |         ^~
crocodile.cpp:70:13: error: 'pq' was not declared in this scope
   70 |     while (!pq.empty()) {
      |             ^~
crocodile.cpp:71:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |         auto [d, x] = pq.top();
      |              ^
crocodile.cpp:74:17: error: 'min_dist2' was not declared in this scope
   74 |         if (d > min_dist2[x]) continue;
      |                 ^~~~~~~~~
crocodile.cpp:76:19: error: expected primary-expression before 'int'
   76 |         for (pair<int, long long> e : g[x]) {
      |                   ^~~
crocodile.cpp:83:5: error: expected primary-expression before '}' token
   83 |     }
      |     ^
crocodile.cpp:82:10: error: expected ';' before '}' token
   82 |         }
      |          ^
      |          ;
   83 |     }
      |     ~     
crocodile.cpp:83:5: error: expected primary-expression before '}' token
   83 |     }
      |     ^
crocodile.cpp:82:10: error: expected ')' before '}' token
   82 |         }
      |          ^
      |          )
   83 |     }
      |     ~     
crocodile.cpp:76:13: note: to match this '('
   76 |         for (pair<int, long long> e : g[x]) {
      |             ^
crocodile.cpp:83:5: error: expected primary-expression before '}' token
   83 |     }
      |     ^
crocodile.cpp:85:12: error: 'min_dist2' was not declared in this scope
   85 |     return min_dist2[0];
      |            ^~~~~~~~~
crocodile.cpp:67:9: warning: unused variable 'x' [-Wunused-variable]
   67 |     int x;
      |         ^
crocodile.cpp:68:15: warning: unused variable 'd' [-Wunused-variable]
   68 |     long long d;
      |               ^