답안 #321562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321562 2020-11-12T18:27:35 Z wind_reaper 관광 (NOI14_sightseeing) C++17
컴파일 오류
0 ms 0 KB
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;
using namespace __gnu_pbds;
using namespace chrono;

#define pb emplace_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9;
// const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;
struct edge{
    int u, v, w;
};
struct DSU{
    vi e;
    void init(int n){
        e = vi(n, -1);
    }

    int get(int x){
        return (e[x] < 0 ? x : e[x] = get(e[x]));
    }

    bool same_set(int x, int y){
        return get(x) == get(y);
    }

    void unite(int x, int y){
        x = get(x), y = get(y);

        if(e[x] < e[y])
            swap(x, y);

        e[x] += e[y];
        e[y] = x;
        return;
    }
};
vi dp;
vector<vpi> g;
void dfs(int node, int p, int w){
    dp[node] = min(dp[p], w);

    for(auto v : g[node]){
        if(v.f == p) continue;
        dfs(v.f, node, v.s);
    }
}
void solve(int tc){
    int n, m, q;
    cin >> n >> m >> q;

    vector<edge> edges(m);

    for(int i = 0; i < m; i++){
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        edges.pb({u, v, w});
    }

    sort(all(edges), [&](edge a, edge b){
        if(a.w > b.w) return true;
        return false;
    });

    DSU s;
    s.init(n);
    dp.resize(n), g.resize(n);
    for(edge a : edges){
        if(s.get(a.u) == s.get(a.v)) continue;
        s.unite(a.u, a.v);
        g[a.u].pb({a.v, a.w});
        g[a.v].pb({a.u, a.w});
    }
    dp[0] = INF;
    dfs(0, 0, INF); 

    for(int i = 0; i < q; i++){
        int x;
        cin >> x;
        --x;
        cout << dp[x] << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    #ifdef LOCAL
        auto begin = high_resolution_clock::now();
    #endif

    int tc = 1;
    // cin >> tc; 
    for (int t = 0; t < tc; t++) solve(t);
    
    #ifdef LOCAL 
        auto end = high_resolution_clock::now();
        cout << fixed << setprecision(4) << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
    #endif
    return 0;
}

Compilation message

sightseeing.cpp: In function 'void solve(int)':
sightseeing.cpp:89:27: error: no matching function for call to 'std::vector<edge>::emplace_back(<brace-enclosed initializer list>)'
   89 |         edges.pb({u, v, w});
      |                           ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from sightseeing.cpp:3:
/usr/include/c++/9/bits/vector.tcc:109:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = edge; _Alloc = std::allocator<edge>; std::vector<_Tp, _Alloc>::reference = edge&]'
  109 |       vector<_Tp, _Alloc>::
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:109:7: note:   candidate expects 0 arguments, 1 provided
sightseeing.cpp:103:29: error: no matching function for call to 'std::vector<std::pair<int, int> >::emplace_back(<brace-enclosed initializer list>)'
  103 |         g[a.u].pb({a.v, a.w});
      |                             ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from sightseeing.cpp:3:
/usr/include/c++/9/bits/vector.tcc:109:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::reference = std::pair<int, int>&]'
  109 |       vector<_Tp, _Alloc>::
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:109:7: note:   candidate expects 0 arguments, 1 provided
sightseeing.cpp:104:29: error: no matching function for call to 'std::vector<std::pair<int, int> >::emplace_back(<brace-enclosed initializer list>)'
  104 |         g[a.v].pb({a.u, a.w});
      |                             ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from sightseeing.cpp:3:
/usr/include/c++/9/bits/vector.tcc:109:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::reference = std::pair<int, int>&]'
  109 |       vector<_Tp, _Alloc>::
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:109:7: note:   candidate expects 0 arguments, 1 provided