제출 #367791

#제출 시각아이디문제언어결과실행 시간메모리
367791Jarif_Rahman다리 (APIO19_bridges)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int SQ = 316;
struct dsu{
    stack<tuple<int, int, int>> st;
    int n;
    int id[N];
    stack<int> comp[N];
    dsu(){
        n = N;
        for(int i = 0; i < n;  i++) id[i] = i, comp[i].push(i);
    }
    int unite(int a, int b){
        a = id[a], b = id[b];
        if(a == b) return 0;
        if(comp[a].size() > comp[b].size()) swap(a, b);
        st.push({a, b, (int)comp[a].size()});
        while(!comp[a].empty()){
            int x = comp[a].top(); comp[a].pop();
            id[x] = b;
            comp[b].push(x);
        }
        return 1;
    }
    void rollback(){
        auto [a, b, sz] = st.top(); st.pop();
        while(sz--){
            int x = comp[b].top(); comp[b].pop();
            id[x] = a;
            comp[a].push(x);
        }
    }
};
int sq;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m; cin >> n >> m;
    tuple<ll, int, int> edge[m];
    for(int i = 0; i < m; i++){
        int a, b; ll w; cin >> a >> b >> w; a--, b--;
        edge[i] = make_tuple(w, a, b);
    }
    int q; cin >> q;
    tuple<ll, int, int> query[q];
    for(int i = 0; i < q; i++){
        int tt, s; ll w; cin >> tt >> s >> w; s--;
        query[i] = {tt, s, w};
    }
    vector<int> ans;
    dsu ds;
    tuple<ll, int, int, int> calc[SQ+5];
    bool ucng[m];
    for(int i = 0; i < m; i++) ucng[i] = 1;
    tuple<ll, int, int> edges[m];
    for(int qi = 0; qi < q; qi+=SQ){
        int ql = min(q-1, qi+SQ-1);
        int cnt = 0;
        for(int j = qi; j <= ql; j++){
            auto [tt, s, w] = query[j];
            if(tt == 1){
                ucng[s] = 0;
            }
            else{
                calc[cnt] = {w, s, cnt, j};
                cnt++;
            }
        }
        vector<int> anss(cnt);
        int inx = 0;
        for(int i = 0; i < m; i++){
            if(ucng[i]) edges[inx++] = edge[i];
        }
        sort(edges, edges+inx);
        sort(calc, calc+cnt, greater<tuple<ll, int, int, int>>());
        int bc = inx-1;
        for(int ii = 0; ii < cnt; ii++){
            auto [w, s, in, jj] = calc[ii];
            while(bc >= 0 && get<0>(edges[bc]) >= w){
                auto [ww, a, b] = edges[bc]; bc--;
                ds.unite(a, b);
            }
            int k = 0;
            for(int j = jj-1; j >= qi; j--){
                auto [tt, ss, ww] = query[j];
                auto [www, a, b] = edge[ss];
                if(tt == 2) continue;
                if(ucng[ss]) continue;
                if(ww >= w) k+=ds.unite(a, b);
                ucng[ss] = 0;
            }
            for(int j = jj+1; j <= ql; j++){
                auto [tt, ss, ww] = query[j];
                auto [www, a, b] = edge[ss];
                if(tt == 2) continue;
                if(ucng[ss]) continue;
                if(www >= w) k+=ds.unite(a, b);
            }
            for(int j = qi; j <= ql; j++){
                auto [tt, ss, ww] = query[j];
                if(tt == 1) ucng[ss] = 0;
            }
            anss[in] = ds.comp[ds.id[s]].size();
            while(k--) ds.rollback();
        }
        for(int j = qi; j <= ql; j++){
            auto [tt, ss, ww] = query[j];
            if(tt == 1) ucng[ss] = 1;
        }
        ans.insert(ans.end(), anss.begin(), anss.end());
        while(!ds.st.empty()) ds.rollback();
    }
    for(int x: ans) cout << x << "\n";
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp:12:12: error: 'N' was not declared in this scope
   12 |     int id[N];
      |            ^
bridges.cpp:13:21: error: 'N' was not declared in this scope
   13 |     stack<int> comp[N];
      |                     ^
bridges.cpp: In constructor 'dsu::dsu()':
bridges.cpp:15:13: error: 'N' was not declared in this scope
   15 |         n = N;
      |             ^
bridges.cpp:16:37: error: 'id' was not declared in this scope; did you mean 'i'?
   16 |         for(int i = 0; i < n;  i++) id[i] = i, comp[i].push(i);
      |                                     ^~
      |                                     i
bridges.cpp:16:48: error: 'comp' was not declared in this scope
   16 |         for(int i = 0; i < n;  i++) id[i] = i, comp[i].push(i);
      |                                                ^~~~
bridges.cpp: In member function 'int dsu::unite(int, int)':
bridges.cpp:19:13: error: 'id' was not declared in this scope
   19 |         a = id[a], b = id[b];
      |             ^~
bridges.cpp:21:12: error: 'comp' was not declared in this scope
   21 |         if(comp[a].size() > comp[b].size()) swap(a, b);
      |            ^~~~
bridges.cpp:22:29: error: 'comp' was not declared in this scope
   22 |         st.push({a, b, (int)comp[a].size()});
      |                             ^~~~
bridges.cpp:22:44: error: no matching function for call to 'std::stack<std::tuple<int, int, int> >::push(<brace-enclosed initializer list>)'
   22 |         st.push({a, b, (int)comp[a].size()});
      |                                            ^
In file included from /usr/include/c++/9/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:89,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_stack.h:233:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::deque<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >; std::stack<_Tp, _Sequence>::value_type = std::tuple<int, int, int>]'
  233 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_stack.h:233:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::tuple<int, int, int>&'}
  233 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_stack.h:238:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(std::stack<_Tp, _Sequence>::value_type&&) [with _Tp = std::tuple<int, int, int>; _Sequence = std::deque<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >; std::stack<_Tp, _Sequence>::value_type = std::tuple<int, int, int>]'
  238 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_stack.h:238:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::stack<std::tuple<int, int, int> >::value_type&&' {aka 'std::tuple<int, int, int>&&'}
  238 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
bridges.cpp: In member function 'void dsu::rollback()':
bridges.cpp:33:21: error: 'comp' was not declared in this scope
   33 |             int x = comp[b].top(); comp[b].pop();
      |                     ^~~~
bridges.cpp:34:13: error: 'id' was not declared in this scope
   34 |             id[x] = a;
      |             ^~
bridges.cpp: In function 'int main()':
bridges.cpp:108:27: error: 'struct dsu' has no member named 'comp'
  108 |             anss[in] = ds.comp[ds.id[s]].size();
      |                           ^~~~
bridges.cpp:108:35: error: 'struct dsu' has no member named 'id'
  108 |             anss[in] = ds.comp[ds.id[s]].size();
      |                                   ^~