Submission #1183897

#TimeUsernameProblemLanguageResultExecution timeMemory
1183897browntoadSprinkler (JOI22_sprinkler)C++20
0 / 100
8 ms15944 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n) 
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

const ll maxn = 2e5+5;

int n, mod, q;
vector<int> g[maxn];
vector<int> H(maxn);

int eptr = 0;
int Bv[41][10][2*maxn];
int Av[41][2*maxn];
int Btot[41][10][maxn];
int Atot[41][maxn];

// centroid decomposition
vector<bool> isrem(maxn); // removed?
vector<int> preeid[maxn], precent[maxn]; // eid connecting previous centroid - this centroid, previous centroid. last precent is itself
vector<int> sz(maxn); 


int find_sz(int u, int peid, int pecent, int pre){
    sz[u] = 1;
    preeid[u].pb(peid);
    precent[u].pb(pecent);
    for (auto v:g[u]){
        if (v != pre && !isrem[v]) sz[u] += find_sz(v, peid, pecent, u);
    }
    return sz[u];
}
int find_centroid(int u, int expsz, int pre){
    for (auto v:g[u]){
        if (!isrem[v] && v != pre && sz[v]*2 > expsz){
            return find_centroid(v, expsz, u);
        }
    }    
    return u;
}
void decomposition(int u, int peid, int pecent){
    int cent = find_centroid(u, find_sz(u, peid, pecent, -1), -1);
    isrem[cent] = 1;
    precent[cent].pb(cent);
    for (auto v:g[cent]){
        if (!isrem[v]){
            decomposition(v, eptr++, cent);
        }
    }
}
signed main(){
    IOS();
    cout<<3<<endl;
    return 0;
    cin>>n>>mod;
    REP(i, n-1){
        int u, v; cin>>u>>v;
        g[u].pb(v); g[v].pb(u);
    }
    REP1(i, n) cin>>H[i];
    decomposition(1, -1, -1);
    REP1(i, n){
        for (auto v:preeid[i]) cout<<v<<' ';
        cout<<endl;
    }
}
/*
4 7
1 2
2 3
3 4
1
1
1
1

11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...