Submission #955695

# Submission time Handle Problem Language Result Execution time Memory
955695 2024-03-31T10:33:57 Z Macker Split the Attractions (IOI19_split) C++17
Compilation error
0 ms 0 KB
#include "split.h"
#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
using namespace std;

vector<vector<int>> adj;
vector<vector<int>> chld;
vector<bool> vis;
vector<int> res;
vector<pii> f;
vector<int> coln;
int v = -1;
bool r = 0;
int n;

int dfs(int a){
	vis[a] = 1;
	int ret = 1;
	for (auto b : adj[a]) {
		if(!vis[b]){
			ret += dfs(b);
			chld[a].push_back(b);
		} 
	}
	if(v != -1) return ret;
	if((ret >= f[0].ff && n - ret >= f[1].ff) || (ret >= f[1].ff && n - ret >= f[0].ff)) v = a;
	if((ret >= f[1].ff && n - ret >= f[0].ff)) r = 1;
	return ret;
}

void coldfs(int a, int col){
	if(coln[col-1] == 0) return;
	res[a] = col;
	coln[col-1]--;
	for (auto b : chld[a]) {
		if(!res[b]){
			coldfs(b, col);
		}
	}
}

vector<int> find_split(int nn, int a, int b, int c, vector<int> p, vector<int> q) {
	n = nn;
	f = {{a, 1}, {b, 2}, {c, 3}};
	coln = {a, b, c};
	adj.assign(n, {});
	chld.assign(n, {});
	vis.assign(n, 0);
	res.assign(n, 0);
	FOR(i, p.size()){
		adj[p[i]].push_back(q[i]);
		adj[q[i]].push_back(p[i]);
	}
	sort(all(f));

	dfs(0);
	if(v == -1) return res;
	
	if(r) {
		coldfs(v, f[1].ss);
		coldfs(0, f[0].ss);
	}
	else{
		coldfs(v, f[0].ss);
		coldfs(0, f[1].ss);
	}
	FOR(i, n) if(res[i] == 0) res[i] = f[2].ss;

	return res;
}

Compilation message

split.cpp:6:9: error: 'pair' does not name a type
    6 | typedef pair<int, int> pii;
      |         ^~~~
split.cpp:17:8: error: 'pii' was not declared in this scope
   17 | vector<pii> f;
      |        ^~~
split.cpp:17:11: error: template argument 1 is invalid
   17 | vector<pii> f;
      |           ^
split.cpp:17:11: error: template argument 2 is invalid
split.cpp: In function 'int dfs(int)':
split.cpp:33:14: error: invalid types 'int[int]' for array subscript
   33 |  if((ret >= f[0].ff && n - ret >= f[1].ff) || (ret >= f[1].ff && n - ret >= f[0].ff)) v = a;
      |              ^
split.cpp:33:36: error: invalid types 'int[int]' for array subscript
   33 |  if((ret >= f[0].ff && n - ret >= f[1].ff) || (ret >= f[1].ff && n - ret >= f[0].ff)) v = a;
      |                                    ^
split.cpp:33:56: error: invalid types 'int[int]' for array subscript
   33 |  if((ret >= f[0].ff && n - ret >= f[1].ff) || (ret >= f[1].ff && n - ret >= f[0].ff)) v = a;
      |                                                        ^
split.cpp:33:78: error: invalid types 'int[int]' for array subscript
   33 |  if((ret >= f[0].ff && n - ret >= f[1].ff) || (ret >= f[1].ff && n - ret >= f[0].ff)) v = a;
      |                                                                              ^
split.cpp:34:14: error: invalid types 'int[int]' for array subscript
   34 |  if((ret >= f[1].ff && n - ret >= f[0].ff)) r = 1;
      |              ^
split.cpp:34:36: error: invalid types 'int[int]' for array subscript
   34 |  if((ret >= f[1].ff && n - ret >= f[0].ff)) r = 1;
      |                                    ^
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:51:29: error: cannot convert '<brace-enclosed initializer list>' to 'int' in assignment
   51 |  f = {{a, 1}, {b, 2}, {c, 3}};
      |                             ^
split.cpp:10:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, n) for (int i = 0; i < n; i++)
......
   57 |  FOR(i, p.size()){
      |      ~~~~~~~~~~~                     
split.cpp:57:2: note: in expansion of macro 'FOR'
   57 |  FOR(i, p.size()){
      |  ^~~
split.cpp:9:18: error: request for member 'begin' in 'f', which is of non-class type 'int'
    9 | #define all(v) v.begin(), v.end()
      |                  ^~~~~
split.cpp:61:7: note: in expansion of macro 'all'
   61 |  sort(all(f));
      |       ^~~
split.cpp:9:29: error: request for member 'end' in 'f', which is of non-class type 'int'
    9 | #define all(v) v.begin(), v.end()
      |                             ^~~
split.cpp:61:7: note: in expansion of macro 'all'
   61 |  sort(all(f));
      |       ^~~
split.cpp:67:14: error: invalid types 'int[int]' for array subscript
   67 |   coldfs(v, f[1].ss);
      |              ^
split.cpp:68:14: error: invalid types 'int[int]' for array subscript
   68 |   coldfs(0, f[0].ss);
      |              ^
split.cpp:71:14: error: invalid types 'int[int]' for array subscript
   71 |   coldfs(v, f[0].ss);
      |              ^
split.cpp:72:14: error: invalid types 'int[int]' for array subscript
   72 |   coldfs(0, f[1].ss);
      |              ^
split.cpp:74:38: error: invalid types 'int[int]' for array subscript
   74 |  FOR(i, n) if(res[i] == 0) res[i] = f[2].ss;
      |                                      ^