Submission #291357

# Submission time Handle Problem Language Result Execution time Memory
291357 2020-09-05T07:52:16 Z Dremix10 Split the Attractions (IOI19_split) C++17
0 / 100
636 ms 1048580 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#ifdef dremix
    #define p(x) cerr<<#x<<" = "<<x<<endl;
    #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
    #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl;
    #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl;
    #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl;
#else
    #define p(x)
    #define p2(x,y)
    #define pp(x)
    #define pv(x)
    #define ppv(x)
#endif
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int maxp = 22;
const ld EPS = 1e-18;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5+1;

vector<vector<int> > adj(N);
vector<int> res;
bool v[N];
pi siz[3];
int cnt[N];

void dfs(int s, int e){
    cnt[s] = 1;
    for(auto x : adj[s])
        if(x!=e && res[x]==0){
            dfs(x,s);
            cnt[s] += cnt[x];
        }
}

int curr;
int now;
void color(int s, int e){
    if(now+1>siz[curr-1].F)return;
    res[s] = siz[curr-1].S;
    now++;
    for(auto x : adj[s])
        if(x!=e){
            color(x,s);
        }
}

int lim;

void solve(int s, int e){
    for(auto x : adj[s])
        if(x!=e && cnt[x]>=siz[curr-1].F && res[x]==0){
            solve(x,s);
            if(curr==lim)return;
        }
    if(cnt[s] >= siz[curr-1].F){
        res[s] = siz[curr-1].S;
        now = 1;
        for(auto x : adj[s])
            if(x!=e)
            color(x,s);
        curr++;
    }
}



vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
    siz[0] = {a,1};
    siz[1] = {b,2};
    siz[2] = {c,3};
    sort(siz,siz+3);
    swap(siz[0],siz[1]);
	int i;
	for(i=0;i<p.size();i++){
        int x = p[i],y = q[i];
        adj[x].push_back(y);
        adj[y].push_back(x);
	}
	res.assign(n,0);
	dfs(0,0);
    curr = 1;
    lim = 2;
    solve(0,0);

    if(res[0]){
        for(auto &x : res)
            x = 0;
        return res;
    }
    dfs(0,0);
    lim = 3;
    solve(0,0);

    if(curr==2){
        for(auto &x : res)
            x = 0;
        return res;
    }

    for(auto &x : res)
        if(x==0)x = siz[curr-1].S;
    return res;


}

/*
11 10
3 4 4
0 1
1 3
1 4
1 5
4 6
0 2
2 7
2 8
7 9
9 10
*/

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:87:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(i=0;i<p.size();i++){
      |          ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Runtime error 629 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Runtime error 636 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Incorrect 89 ms 11060 KB invalid split: #1=20000, #2=31206, #3=48794
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 630 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Runtime error 629 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -