답안 #1041825

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041825 2024-08-02T08:33:59 Z stdfloat 자매 도시 (APIO20_swap) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "swap.h"
// #include "grader.cpp"
using namespace std;

#define int long long

using ll = long long;

#define ff  first
#define ss  second
#define pii pair<int, int>

int n;

vector<vector<pii>> E;

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    E.assign(n, {});
    for (int i = 0; i < M; i++) {
        E[U[i]].push_back({V[i], W[i]});
        E[V[i]].push_back({U[i], W[i]});
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    int l = 0, r = (int)1e9 + 1;
    while (l < r) {
        int md = (l + r) >> 1;

        queue<int> q;
        vector<bool> visX(n);
        vector<int> p(n, -1);
        q.push(X); visX[X] = true;
        while (!q.empty()) {
            int x = q.front(); q.pop();

            for (auto [i, w] : E[x]) {
                if (w <= md && !visX[i]) {
                    p[i] = x;
                    q.push(i);
                    visX[i] = true;
                }
            }
        }

        if (!visX[Y]) {
            l = md + 1;
            continue;
        }

        bool tr = false;
        vector<bool> visY(n);
        queue<pii> q1;
        q1.push({Y, -1}); visY[Y] = true;
        while (!q1.empty() && !tr) {
            auto [x, p] = q1.front(); q1.pop();
        
            for (auto [i, w] : E[x]) {
                if (w > md || i == p) continue;

                if (visY[i]) {
                    if (visX[i]) {
                        tr = true;
                        break;
                    }
                }
                else {
                    visY[i] = true;
                    q1.push({i, x});
                }
            }
        }

        int x = Y;
        while (x != X && !tr) {
            x = p[x];

            int cnt = 0;
            for (auto [i, w] : E[x]) {
                cnt += (w <= md);
            }

            tr = (cnt > 2);#include <bits/stdc++.h>
#include "swap.h"
// #include "grader.cpp"
using namespace std;

#define int long long

using ll = long long;

#define ff  first
#define ss  second
#define pii pair<int, int>

int n;

vector<vector<pii>> E;

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    E.assign(n, {});
    for (int i = 0; i < M; i++) {
        E[U[i]].push_back({V[i], W[i]});
        E[V[i]].push_back({U[i], W[i]});
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    int l = 0, r = (int)1e9 + 1;
    while (l < r) {
        int md = (l + r) >> 1;

        queue<int> q;
        vector<bool> visX(n);
        vector<int> p(n, -1);
        q.push(X); visX[X] = true;
        while (!q.empty()) {
            int x = q.front(); q.pop();

            for (auto [i, w] : E[x]) {
                if (w <= md && !visX[i]) {
                    p[i] = x;
                    q.push(i);
                    visX[i] = true;
                }
            }
        }

        if (!visX[Y]) {
            l = md + 1;
            continue;
        }

        bool tr = false;
        vector<bool> visY(n);
        queue<pii> q1;
        q1.push({Y, -1}); visY[Y] = true;
        while (!q1.empty() && !tr) {
            auto [x, p] = q1.front(); q1.pop();
        
            for (auto [i, w] : E[x]) {
                if (w > md || i == p) continue;

                if (visY[i]) {
                    if (visX[i]) {
                        tr = true;
                        break;
                    }
                }
                else {
                    visY[i] = true;
                    q1.push({i, x});
                }
            }
        }

        int x = Y;
        while (x != X && !tr) {
            x = p[x];

            int cnt = 0;
            for (auto [i, w] : E[x]) {
                cnt += (w <= md);
            }

            tr = (cnt > 2);
        }

        if (!tr) l = md + 1;
        else r = md;
    }

    return (l == (int)1e9 + 1 ? -1 : l);
}
        }

        if (!tr) l = md + 1;
        else r = md;
    }

    return (l == (int)1e9 + 1 ? -1 : l);
}

Compilation message

swap.cpp:85:28: error: stray '#' in program
   85 |             tr = (cnt > 2);#include <bits/stdc++.h>
      |                            ^
swap.cpp: In function 'long long int getMinimumFuelCapacity(long long int, long long int)':
swap.cpp:85:29: error: 'include' was not declared in this scope
   85 |             tr = (cnt > 2);#include <bits/stdc++.h>
      |                             ^~~~~~~
swap.cpp:85:38: error: 'bits' was not declared in this scope
   85 |             tr = (cnt > 2);#include <bits/stdc++.h>
      |                                      ^~~~
swap.cpp:85:43: error: 'stdc' was not declared in this scope; did you mean 'std'?
   85 |             tr = (cnt > 2);#include <bits/stdc++.h>
      |                                           ^~~~
      |                                           std
In file included from swap.cpp:86:
swap.h:3:1: error: expected primary-expression before 'void'
    3 | void init(int N, int M,
      | ^~~~
swap.cpp:102:70: error: a function-definition is not allowed here before '{' token
  102 | void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
      |                                                                      ^
swap.cpp:111:42: error: a function-definition is not allowed here before '{' token
  111 | int getMinimumFuelCapacity(int X, int Y) {
      |                                          ^
swap.cpp:98:5: warning: unused variable 'n' [-Wunused-variable]
   98 | int n;
      |     ^