답안 #945233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945233 2024-03-13T14:46:33 Z parlimoos 통행료 (APIO13_toll) C++14
컴파일 오류
0 ms 0 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int n , m , k;
vector<arr(3)> mst;
arr(3) cnds[20] , uss[20];
vector<int> a;
vector<arr(2)> adds;
ll bckdsu[500000][3];
ll dsu[100000][2] , mem[100000];
int dsucnt = 0;

void init(){
    for(int v = 0 ; v < n ; v++) dsu[v][0] = -1 , dsu[v][1] = a[v];
}
int findDsu(int v){
    if(dsu[v][0] == -1) return v;
    bckdsu[dsucnt][0] = v;
    bckdsu[dsucnt][1] = dsu[v][0];
    bckdsu[dsucnt++][2] = dsu[v][1];
    return (dsu[v][0] = findDsu(dsu[v][0]));
}
void uDsu(int a , int b){
    a = findDsu(a) , b = findDsu(b);
    if(a == b) return;
    bckdsu[dsucnt][0] = a , bckdsu[dsucnt][1] = dsu[a][0] , bckdsu[dsucnt++][2] = dsu[a][1];
    bckdsu[dsucnt][0] = b , bckdsu[dsucnt][1] = dsu[b][0] , bckdsu[dsucnt++][2] = dsu[b][1];
    dsu[a][1] += dsu[b][1] , dsu[b][0] = a;
}
void clDsu(){
    for(int i = dsucnt - 1 ; i >= 0 ; i--){
        dsu[bckdsu[i][0]][0] = bckdsu[i][1];
        dsu[bckdsu[i][0]][1] = bckdsu[i][2];
    }
    dsucnt = 0;
}
void getCnds(){
    for(auto e : adds) uDsu(e[0] , e[1]);
    for(auto e : mst){
        if(findDsu(e[1]) == findDsu(e[2])) cnds.pb(e);
        else uDsu(e[1] , e[2]);
    }
    clDsu();
    for(auto e : mst){
        if(!(binary_search(cnds.bg() , cnds.end() , e))) uDsu(e[1] , e[2]);
    }
    dsucnt = 0;
}
bool jg(int e , int msk , int c){
    for(int i = 0 ; i < k ; i++){
        if(i == e or !((msk >> i) & 1)) continue;
        uDsu(adds[i][0] , adds[i][1]);
    }
    bool res = 1;
    for(auto ee : cnds){
        if(ee[0] >= c){
            if(findDsu(adds[e][0]) == findDsu(adds[e][1])) res = 0;
            clDsu();
            return res;
        }
        uDsu(ee[1] , ee[2]);
    }
    if(findDsu(adds[e][0]) == findDsu(adds[e][1])) res = 0;
    clDsu();
    return res;
}
int bs(int e , int msk){
    int l = 0 , r = int(1e6) + 1;
    while(r - l - 1 > 1){
        int c = l + (r - l - 1) / 2 + 1;
        if(jg(e , msk , c)) l = c - 1;
        else r = c;
    }
    if(r - l - 1 == 1){
        if(jg(e , msk , l + 1)) return l + 1;
    }
    return l;
}
ll dfs1(int v , int p , int msk){
    ll res = 0;
    mem[v] = dsu[v][1];
    for(int e = 0 ; e < k ; e++){
        if(!((msk >> e) & 1)) continue;
        if(findDsu(adds[e][0]) != v and findDsu(adds[e][1]) != v) continue;
        int u = findDsu(adds[e][0]) + findDsu(adds[e][1]) - v;
        if(u == p) continue;
        res += dfs1(u , v , msk) , mem[v] += mem[u];
        ll d = bs(e , msk);
        res += d * mem[u];
    }
    return res;
}
ll getCst(int msk){
    for(int e = 0 ; e < k ; e++){
        if(!((msk >> e) & 1)) continue;
        uDsu(adds[e][0] , adds[e][1]);
    }
    for(auto e : cnds){
        if(findDsu(e[1]) == findDsu(e[2])) continue;
        uss.pb(e);
    }
    clDsu();
    for(auto e : uss) uDsu(e[1] , e[2]);
    ll res = dfs1(findDsu(0) , -1 , msk);
    clDsu() , uss.cl();
    return res;
}
ll f(){
    ll res = 0;
    for(int msk = 1 ; msk < (1 << k) ; msk++){
        res = max(res , getCst(msk));
    }
    return res;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> k;
    vector<arr(3)> es;
    for(int i = 0 ; i < m ; i++){
        int v , u , c;
        cin >> v >> u >> c;
        v-- , u--;
        es.pb({c , v , u});
    }
    for(int i = 0 ; i < k ; i++){
        int v , u;
        cin >> v >> u;
        adds.pb({v - 1 , u - 1});
    }
    for(int i = 0 ; i < n ; i++){
        int d;
        cin >> d;
        a.pb(d);
    }
    init();
    sort(es.bg() , es.end());
    for(auto e : es){
        if(findDsu(e[1]) == findDsu(e[2])) continue;
        mst.pb(e) , uDsu(e[1] , e[2]);
    }
    // exit(0);
    clDsu() , getCnds();
    cout << f();
}

Compilation message

toll.cpp: In function 'void getCnds()':
toll.cpp:8:12: error: request for member 'push_back' in 'cnds', which is of non-class type 'std::array<int, 3> [20]'
    8 | #define pb push_back
      |            ^~~~~~~~~
toll.cpp:53:49: note: in expansion of macro 'pb'
   53 |         if(findDsu(e[1]) == findDsu(e[2])) cnds.pb(e);
      |                                                 ^~
toll.cpp:13:12: error: request for member 'begin' in 'cnds', which is of non-class type 'std::array<int, 3> [20]'
   13 | #define bg begin
      |            ^~~~~
toll.cpp:58:33: note: in expansion of macro 'bg'
   58 |         if(!(binary_search(cnds.bg() , cnds.end() , e))) uDsu(e[1] , e[2]);
      |                                 ^~
toll.cpp:58:45: error: request for member 'end' in 'cnds', which is of non-class type 'std::array<int, 3> [20]'
   58 |         if(!(binary_search(cnds.bg() , cnds.end() , e))) uDsu(e[1] , e[2]);
      |                                             ^~~
toll.cpp: In function 'll getCst(int)':
toll.cpp:8:12: error: request for member 'push_back' in 'uss', which is of non-class type 'std::array<int, 3> [20]'
    8 | #define pb push_back
      |            ^~~~~~~~~
toll.cpp:113:13: note: in expansion of macro 'pb'
  113 |         uss.pb(e);
      |             ^~
toll.cpp:12:12: error: request for member 'clear' in 'uss', which is of non-class type 'std::array<int, 3> [20]'
   12 | #define cl clear
      |            ^~~~~
toll.cpp:118:19: note: in expansion of macro 'cl'
  118 |     clDsu() , uss.cl();
      |                   ^~