Submission #952763

# Submission time Handle Problem Language Result Execution time Memory
952763 2024-03-24T17:57:45 Z abczz Split the Attractions (IOI19_split) C++14
0 / 100
5 ms 18780 KB
#include "split.h"
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#define ll long long

using namespace std;

vector <ll> V;
vector <ll> adj[100000], E[200000];
bool ap[200000], ok;
vector <ll> G[200000], X[100000];
bool visited[100000];
array<ll, 2> T[3];
ll m, k, A[3], B[3], low[100000], st[100000], sz[200000], F[200000], C[200000], cnt;

void tar(ll u, ll p) {
	V.push_back(u);
	low[u] = st[u] = ++cnt;
	ll rch = 0;
	for (auto v : adj[u]) {
		if (!st[v]) {
			++rch;
			tar(v, u);
			low[u] = min(low[u], low[v]);
			if (low[v] >= st[u]) {
				if (p != -1) ap[u] = 1;
				while (!V.empty()) {
					auto x = V.back();
					V.pop_back();
					X[x].push_back(k);
					G[k].push_back(x);
					if (x == v) break;
				}
				X[u].push_back(k);
				G[k].push_back(u);
				++k;
			}
		}
		else if (v != p) {
			low[u] = min(low[u], st[v]);
		}
	}
	if (p == -1 & rch > 1) ap[u] = 1;
}

void dfs(ll u, ll w) {
  visited[u] = 1;
  for (auto v : adj[u]) {
    if (!visited[v] && !C[v]) {
      if (B[w] < A[w]) {
        F[v] = w;
        ++B[w];
      }
      else F[v] = 2;
      dfs(v, w);
    }
  }
}

void find(ll u, ll w) {
  if (B[w] < A[w]) {
    ++B[w];
    F[u] = w;
  }
  else F[u] = 2;
  dfs(u, w);
  for (auto v : adj[u]) {
    if (C[v] && !visited[v]) {
      find(v, w);
    }
  }
}

void solve(ll u, ll p) {
	if (ap[u]) ++sz[u];
	else sz[u] += G[u].size() - E[u].size();
	ll mx = -1;
	for (auto v : E[u]) {
		if (v != p) {
			solve(v, u);
			sz[u] += sz[v];
			mx = max(mx, sz[v]);
		}
	}
	mx = max(mx, m - sz[u]);
	if (!ok && !ap[u] && mx <= m-A[0]) {
		if (mx >= A[1]) {
			if (m-sz[u] == mx) {
				F[p] = 1;
			}
			else {
				for (auto v : E[u]) {
					if (v != p) {
						if (sz[v] == mx) {
							F[v] = 1;
							break;
						}
					}
				}
			}
      for (auto v : G[u]) {
        C[v] = 1;
      }
      for (auto v : G[u]) {
        if (F[v]) dfs(v, 1);
      }
      for (auto v : G[u]) {
        if (!F[v]) {
          find(v, 0);
          break;
        }
      }
		}
		else {
			ll cur = 0;
      for (int i=0; i<m; ++i) F[i] = 2;
      for (auto v : G[u]) {
        C[v] = 1;
      }
			find(G[u][0], 0);
      for (int i=0; i<m; ++i) {
        if (F[i] != 0) visited[i] = 0;
      }
      for (auto v : G[u]) {
        if (!visited[v]) {
          find(v, 1);
          break;
        }
      }
		}
    ok = 1;
    return;
	}
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	A[0] = T[0][0] = a, A[1] = T[1][0] = b, A[2] = T[2][0] = c;
  T[1][1] = 1, T[2][1] = 2;
	sort(A, A+3);
  sort(T, T+3);
	m = n;
	k = n;
	for (int i=0; i<p.size(); ++i) {
		adj[p[i]].push_back(q[i]);
		adj[q[i]].push_back(p[i]);
	}
	tar(0, -1);
	for (int i=0; i<n; ++i) {
		if (ap[i]) {
			for (auto u : X[i]) {
				E[i].push_back(u);
				E[u].push_back(i);
			}
		}
	}
  solve(n, -1);
  vector <int> U;
  if (ok) {
    U.clear();
    for (int i=0; i<n; ++i) {
      U.push_back(T[F[i]][1]+1);
    }
  }
  else {
    for (int i=0; i<n; ++i) {
      U.push_back(F[i]);
    }
  }
	return U;
}

Compilation message

split.cpp: In function 'void tar(long long int, long long int)':
split.cpp:45:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   45 |  if (p == -1 & rch > 1) ap[u] = 1;
      |      ~~^~~~~
split.cpp: In function 'void solve(long long int, long long int)':
split.cpp:117:7: warning: unused variable 'cur' [-Wunused-variable]
  117 |    ll cur = 0;
      |       ^~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:145:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |  for (int i=0; i<p.size(); ++i) {
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 18780 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 18780 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 18776 KB invalid split: #1=3, #2=1, #3=1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 18780 KB invalid split: #1=3, #2=2, #3=4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 18780 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -