Submission #764598

# Submission time Handle Problem Language Result Execution time Memory
764598 2023-06-23T16:19:57 Z raysh07 Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

struct edge{
    int u, v, w;
};

bool comp(edge x, edge y){
    return x.w < y.w;
}
 
int n, m;
const int maxn = 1e5 + 69;
vector <pair<int, int>> adj[maxn];
int root[maxn], mn[maxn];
set <pair<int, pair<int, int>>> path, ans;
edge e[2 * maxn]
int mp[maxn];

int find(int x) {
    if (x == root[x]) return x;
    return root[x] = find(root[x]);
}

bool unite(int x, int y){
    x = find(x); y = find(y);
    if (x == y) return false;
    
    root[y] = x;
    return true;
}

pair<int, pair<int, int>> get(int u, int v, int w){
    return {w, {u, v}};
}

void dfs(int u, int need, int par){
    if (need == u) ans = path;
    for (auto [v, w] : adj[u]){
        path.insert(get(u, v, w));
        path.insert(get(v, u, w));
        dfs(v, need, u);
        path.erase(get(u, v, w));
        path.erase(get(v, u, w));
    }
}
 
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    m = M;
    vector <pair<int, pair<int, int>>> vec;
    for (int i = 0; i < m; i++){
        vec.push_back({W[i], {U[i], V[i]}});
    }
    sort(vec.begin(), vec.end());
    
    for (int i = 0; i < m; i++){
        e[i].u = vec[i].second.first; 
        e[i].v = vec[i].second.second; 
        e[i].w = vec[i].first;
    }
    
    for (int i = 0; i < n; i++){
        root[i] = i;
        mn[i] = 1e9 + 1;
    }
    
    for (auto x : e){
        if (unite(x.u, x.v)){
            adj[x.u].push_back({x.v, x.w});
            adj[x.v].push_back({x.u, x.w});
        } else {
            mn[x.u] = min(mn[x.u], x.w);
            mn[x.v] = min(mn[x.v], x.w);
        }
    }
}
 
int getMinimumFuelCapacity(int x, int y) {
    dfs(x, y, -1);
    for (int i = 0; i < n; i++) mp[i] = 0;
    int lol = 0;
    for (auto x : ans) {
        lol = max(lol, x.w);
        mp[x.u]++;
        mp[x.v]++;
    }
    int l1 = 1e9 + 1;
    
    for (int i = 0; i < m; i++){
        if (ans.find(get(e[i].u, e[i].v, e[i].w)) == ans.end()){
            if (mp[e[i].u] || mp[e[i].v]) l1 = min(l1, e[i].w);
        }
    }
    
    if (l1 > 1e9) return -1;
    else return max(l1, lol);
}

Compilation message

swap.cpp:19:1: error: expected initializer before 'int'
   19 | int mp[maxn];
      | ^~~
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:59:9: error: 'e' was not declared in this scope
   59 |         e[i].u = vec[i].second.first;
      |         ^
swap.cpp:69:19: error: 'e' was not declared in this scope
   69 |     for (auto x : e){
      |                   ^
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:82:33: error: 'mp' was not declared in this scope; did you mean 'mn'?
   82 |     for (int i = 0; i < n; i++) mp[i] = 0;
      |                                 ^~
      |                                 mn
swap.cpp:85:26: error: 'struct std::pair<int, std::pair<int, int> >' has no member named 'w'
   85 |         lol = max(lol, x.w);
      |                          ^
swap.cpp:86:9: error: 'mp' was not declared in this scope; did you mean 'mn'?
   86 |         mp[x.u]++;
      |         ^~
      |         mn
swap.cpp:86:14: error: 'struct std::pair<int, std::pair<int, int> >' has no member named 'u'
   86 |         mp[x.u]++;
      |              ^
swap.cpp:87:14: error: 'struct std::pair<int, std::pair<int, int> >' has no member named 'v'
   87 |         mp[x.v]++;
      |              ^
swap.cpp:92:26: error: 'e' was not declared in this scope
   92 |         if (ans.find(get(e[i].u, e[i].v, e[i].w)) == ans.end()){
      |                          ^
swap.cpp:93:17: error: 'mp' was not declared in this scope; did you mean 'mn'?
   93 |             if (mp[e[i].u] || mp[e[i].v]) l1 = min(l1, e[i].w);
      |                 ^~
      |                 mn