Submission #288613

# Submission time Handle Problem Language Result Execution time Memory
288613 2020-09-01T16:53:34 Z Mercenary Split the Attractions (IOI19_split) C++14
40 / 100
169 ms 22300 KB
#include "split.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int A , B;
int sub[maxn];

vector<int> canpick;
vector<int> adj[maxn] , adj1[maxn];
int root = -1;
void dfs(int u){
    sub[u] = 1;
    bool ok = 0;
    for(auto & c : adj[u]){
        if(sub[c] == -1){
            adj1[u].pb(c);
            dfs(c);
            sub[u] += sub[c];
            ok |= sub[c] >= A;
        }
    }
    if(ok == 0 && sub[u] >= A)root = u;
}

void dfs1(int u){
    bool ok = 0;
    for(auto & c : adj[u]){
        if(sub[c] > sub[root])ok = 1;
    }
    if(u != root && ok){
        canpick.pb(u);
        return;
    }
    for(auto & c : adj1[u]){
        dfs1(c);
    }
}

bool cut[maxn];

bool vis[maxn];
vector<int> valA , valB;

void dfs2(int u){
    valA.pb(u);
    vis[u] = 1;
    for(auto & c : adj1[u]){
        if(cut[c])continue;
        dfs2(c);
    }
}

void dfs3(int u){
    valB.pb(u);
    vis[u] = 1;
    for(auto &c : adj[u]){
        if(vis[c] == 1)continue;
        dfs3(c);
    }
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
    for(int i = 0 ; i < p.size() ; ++i){
        adj[p[i]].pb(q[i]);
        adj[q[i]].pb(p[i]);
    }
    A = min({a , b , c});
    memset(sub,-1,sizeof sub);
    dfs(0);
    dfs1(root);
    for(auto & c : canpick){
        if(sub[root] - sub[c] < A)break;
        cut[c] = 1;
    }
    dfs2(root);
    for(int i = 0 ; i < n ; ++i){
        if(vis[i] == 0){
            dfs3(i);
            break;
        }
    }
    if(valA.size() > valB.size())swap(valA,valB);
    vector<ii> val = {mp(a,1),mp(b,2),mp(c,3)};
    sort(val.begin(),val.end());
    if(val[0].first <= valA.size() && val[1].first <= valB.size()){
        vector<int> res(n , val[2].second);
        for(int i = 0 ; i < val[0].first ; ++i){
            res[valA[i]] = val[0].second;
        }
        for(int i = 0 ; i < val[1].first ; ++i){
            res[valB[i]] = val[1].second;
        }
        return res;
    }
    return vector<int>(n , 0);
}

#ifdef LOCAL
#include "split.h"
#include <cstdio>
#include <cassert>

using namespace std;

int main() {
    freopen("A.INP","r",stdin);
	int n, m, a, b, c;
	assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c));
	vector<int> p(m), q(m);
	for (int i=0; i<m; i++)
		assert(2 == scanf("%d%d", &p[i], &q[i]));
	fclose(stdin);

	vector<int> result = find_split(n, a, b, c, p, q);

	for (int i=0; i<(int)result.size(); i++)
		printf("%s%d", ((i>0)?" ":""), result[i]);
	printf("\n");
	fclose(stdout);
	return 0;
}

#endif // LOCAL

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0 ; i < p.size() ; ++i){
      |                     ~~^~~~~~~~~~
split.cpp:101:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     if(val[0].first <= valA.size() && val[1].first <= valB.size()){
split.cpp:101:52: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     if(val[0].first <= valA.size() && val[1].first <= valB.size()){
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB ok, correct split
2 Correct 4 ms 5376 KB ok, correct split
3 Correct 4 ms 5376 KB ok, correct split
4 Correct 4 ms 5376 KB ok, correct split
5 Correct 5 ms 5376 KB ok, correct split
6 Correct 4 ms 5376 KB ok, correct split
7 Correct 124 ms 21872 KB ok, correct split
8 Correct 125 ms 19696 KB ok, correct split
9 Correct 126 ms 18928 KB ok, correct split
10 Correct 124 ms 22256 KB ok, correct split
11 Correct 133 ms 22256 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5376 KB ok, correct split
2 Correct 4 ms 5376 KB ok, correct split
3 Correct 4 ms 5376 KB ok, correct split
4 Correct 155 ms 18192 KB ok, correct split
5 Correct 117 ms 13044 KB ok, correct split
6 Correct 134 ms 22300 KB ok, correct split
7 Correct 126 ms 19616 KB ok, correct split
8 Correct 169 ms 15864 KB ok, correct split
9 Correct 118 ms 14576 KB ok, correct split
10 Correct 62 ms 12144 KB ok, correct split
11 Correct 62 ms 12144 KB ok, correct split
12 Correct 64 ms 12144 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5376 KB ok, correct split
2 Correct 109 ms 13044 KB ok, correct split
3 Correct 37 ms 8952 KB ok, correct split
4 Correct 4 ms 5376 KB ok, correct split
5 Correct 123 ms 18032 KB ok, correct split
6 Correct 125 ms 17776 KB ok, correct split
7 Correct 134 ms 17520 KB ok, correct split
8 Correct 130 ms 18928 KB ok, correct split
9 Correct 122 ms 17392 KB ok, correct split
10 Correct 30 ms 8320 KB ok, no valid answer
11 Correct 46 ms 9716 KB ok, no valid answer
12 Correct 84 ms 13680 KB ok, no valid answer
13 Correct 107 ms 13936 KB ok, no valid answer
14 Correct 67 ms 13044 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5376 KB ok, correct split
2 Correct 4 ms 5376 KB ok, no valid answer
3 Correct 4 ms 5376 KB ok, correct split
4 Correct 5 ms 5376 KB ok, correct split
5 Correct 4 ms 5376 KB ok, correct split
6 Correct 4 ms 5376 KB ok, correct split
7 Correct 4 ms 5376 KB ok, correct split
8 Correct 4 ms 5376 KB ok, correct split
9 Correct 6 ms 5760 KB ok, correct split
10 Correct 7 ms 5760 KB ok, correct split
11 Correct 4 ms 5376 KB ok, correct split
12 Correct 6 ms 5760 KB ok, correct split
13 Incorrect 4 ms 5376 KB jury found a solution, contestant did not
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB ok, correct split
2 Correct 4 ms 5376 KB ok, correct split
3 Correct 4 ms 5376 KB ok, correct split
4 Correct 4 ms 5376 KB ok, correct split
5 Correct 5 ms 5376 KB ok, correct split
6 Correct 4 ms 5376 KB ok, correct split
7 Correct 124 ms 21872 KB ok, correct split
8 Correct 125 ms 19696 KB ok, correct split
9 Correct 126 ms 18928 KB ok, correct split
10 Correct 124 ms 22256 KB ok, correct split
11 Correct 133 ms 22256 KB ok, correct split
12 Correct 4 ms 5376 KB ok, correct split
13 Correct 4 ms 5376 KB ok, correct split
14 Correct 4 ms 5376 KB ok, correct split
15 Correct 155 ms 18192 KB ok, correct split
16 Correct 117 ms 13044 KB ok, correct split
17 Correct 134 ms 22300 KB ok, correct split
18 Correct 126 ms 19616 KB ok, correct split
19 Correct 169 ms 15864 KB ok, correct split
20 Correct 118 ms 14576 KB ok, correct split
21 Correct 62 ms 12144 KB ok, correct split
22 Correct 62 ms 12144 KB ok, correct split
23 Correct 64 ms 12144 KB ok, correct split
24 Correct 4 ms 5376 KB ok, correct split
25 Correct 109 ms 13044 KB ok, correct split
26 Correct 37 ms 8952 KB ok, correct split
27 Correct 4 ms 5376 KB ok, correct split
28 Correct 123 ms 18032 KB ok, correct split
29 Correct 125 ms 17776 KB ok, correct split
30 Correct 134 ms 17520 KB ok, correct split
31 Correct 130 ms 18928 KB ok, correct split
32 Correct 122 ms 17392 KB ok, correct split
33 Correct 30 ms 8320 KB ok, no valid answer
34 Correct 46 ms 9716 KB ok, no valid answer
35 Correct 84 ms 13680 KB ok, no valid answer
36 Correct 107 ms 13936 KB ok, no valid answer
37 Correct 67 ms 13044 KB ok, no valid answer
38 Correct 4 ms 5376 KB ok, correct split
39 Correct 4 ms 5376 KB ok, no valid answer
40 Correct 4 ms 5376 KB ok, correct split
41 Correct 5 ms 5376 KB ok, correct split
42 Correct 4 ms 5376 KB ok, correct split
43 Correct 4 ms 5376 KB ok, correct split
44 Correct 4 ms 5376 KB ok, correct split
45 Correct 4 ms 5376 KB ok, correct split
46 Correct 6 ms 5760 KB ok, correct split
47 Correct 7 ms 5760 KB ok, correct split
48 Correct 4 ms 5376 KB ok, correct split
49 Correct 6 ms 5760 KB ok, correct split
50 Incorrect 4 ms 5376 KB jury found a solution, contestant did not
51 Halted 0 ms 0 KB -