답안 #914010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914010 2024-01-20T18:35:42 Z VMaksimoski008 Railway (BOI17_railway) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
 
const short LOG = 17;
const int maxn = 1e5 + 1;
 
struct BIT {
    int n;
    vector<int> tree;
 
    void config(int _n) {
        n = _n + 1;
        tree.resize(_n+1);
    }
 
    void add(int p, int v) {
        for(p++; p<n; p+=p&-p) tree[p] += v;
    }
 
    int sum(int p) {
        int ans = 0;
        for(p++; p>0; p-=p&-p) ans += tree[p];
        return ans;
    }
 
    int query(int l, int r) { return sum(r) - sum(l-1); }
};
 
int n, m, k, timer = 0, i, j;
int depth[maxn+1], up[maxn+1][LOG], in[maxn+1], out[maxn+1];
vector<vector<int> > graph;
 
void dfs(int u, int p) {
    in[u] = timer++;
    for(i=1; i<LOG; i++)
        up[u][i] = up[ up[u][i-1] ][i-1];
 
    for(int &v : graph[u]) {
        if(v == p) continue;
        depth[v] = depth[u] + 1;
        up[v][0] = u;
        dfs(v, u);
    }
 
    out[u] = timer;
}
 
int jmp(int x, int d) {
    for(j=LOG-1; j>=0; j--)
        if(d & (1 << j)) x = up[x][j];
    return x;
}
 
int get_lca(int a, int b) {
    if(depth[a] < depth[b]) swap(a, b);
 
    a = jmp(a, depth[a] - depth[b]);
    if(a == b) return a;
    for(j=LOG-1; j>=0; j--)
        if(up[a][j] != up[b][j])
            a = up[a][j], b = up[b][j];
 
    return up[a][0];
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n >> m >> k;
    graph.resize(n+1);
 
    pii edges[n-1];
    
    for(i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        edges = {a, b};
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
 
    dfs(1, 0);
 
    int edge_id[n+1];
    for(i=0; i<n-1; i++) {
        if(depth[edges[i].first] > depth[edges[i].second]) swap(edges[i].first, edges[i].second);
        edge_id[edges[i].second] = i + 1;
    }
 
    BIT bit;
    bit.config(n);
 
    int cnt, a, b, lca, v[n+1];
    while(m--) {
        cin >> cnt;
        for(i=0; i<cnt; i++) cin >> v[i];
 
        sort(v, v + cnt, [&](int &u, int &v) { return in[u] < in[v]; });
        v[cnt] = v[0];
 
        for(i=0; i<cnt; i++) {
            a = v[i], b = v[i+1], lca = get_lca(a, b);
            bit.add(in[a], 1);
            bit.add(in[b], 1);
            bit.add(in[lca], -2);
        }
    }
 
    vector<int> ans;
    for(i=1; i<=n; i++)
        if(bit.query(in[i], out[i]-1) >= 2 * k) ans.push_back(edge_id[i]);
 
    cout << ans.size() << '\n';
    sort(ans.begin(), ans.end());
    for(int &x : ans) cout << x << " ";
    return 0;
}

Compilation message

railway.cpp: In function 'int32_t main()':
railway.cpp:80:15: error: assigning to an array from an initializer list
   80 |         edges = {a, b};
      |         ~~~~~~^~~~~~~~