Submission #343858

# Submission time Handle Problem Language Result Execution time Memory
343858 2021-01-04T15:36:48 Z 79brue Split the Attractions (IOI19_split) C++14
0 / 100
943 ms 1048580 KB
#include <bits/stdc++.h>
#include "split.h"

using namespace std;

typedef long long ll;

int n, m, a, b, c;
vector<int> link[100002];
int idx[4];
vector<int> ret;
int cnt;
int DP[100002];
int tmp=-1;

int dfs(int x, int p = -1){
    DP[x] = 1;
    for(auto y: link[x]){
        if(p==y) continue;
        DP[x] += dfs(y, x);
    }
    if(min(DP[x], n - DP[x]) >= a){
        tmp = x;
    }
    return DP[x];
}

vector<int> find_split(int _n, int _a, int _b, int _c, vector<int> p, vector<int> q) {
    m = (int)p.size();
    if(m != n-1){
      while(1){
        ret.push_back(1);
      }
    }
    n = _n, a = _a, b = _b, c = _c;

    vector<pair<int, int> > v {make_pair(a, 1), make_pair(b, 2), make_pair(c, 3)};
    sort(v.begin(), v.end());
    a = v[0].first, b = v[1].first, c = v[2].first;
    idx[1] = v[0].second, idx[2] = v[1].second, idx[3] = v[2].second;

    for(int i=0; i<m; i++){
        link[p[i]].push_back(q[i]);
        link[q[i]].push_back(p[i]);
    }
    ret.resize(n);

    dfs(0);
    if(tmp == -1) return ret;

    int rootNum, childNum;
    if(DP[tmp] >= a && n-DP[tmp] >= b) rootNum = 2, childNum = 1;
    else rootNum = 1, childNum = 2;

    queue<int> tq; tq.push(0);
    for(int cnt=0; cnt<((DP[tmp] >= a && n-DP[tmp] >= b) ? b : a); cnt++){
        int tmp = tq.front(); tq.pop();
        ret[tmp] = rootNum;
        for(auto y: link[tmp]){
            if(y == tmp || ret[y]) continue;
            tq.push(y);
        }
    }
    while(!tq.empty()) tq.pop();
    tq.push(tmp);
    for(int cnt=0; cnt<((DP[tmp] >= a && n-DP[tmp] >= b) ? a : b); cnt++){
        int tmp = tq.front(); tq.pop();
        ret[tmp] = childNum;
        for(auto y: link[tmp]){
            if(ret[y]) continue;
            tq.push(y);
        }
    }
    for(int i=0; i<n; i++) if(!ret[i]) ret[i] = 3;
    for(int i=0; i<n; i++) ret[i] = idx[ret[i]];
    return ret;
}
# Verdict Execution time Memory Grader output
1 Runtime error 923 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 941 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 943 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 929 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 923 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -