이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
vector<int> edge[100005];
int sub[100005];
int parent[100005];
int check[100005];
void dfs(int root)
{
sub[root] = 1;
for (auto&e : edge[root])
{
if (e == parent[root])
continue;
parent[e] = root;
dfs(e);
sub[root] += sub[e];
}
}
void mark(int root, vector<int>& num, int& a, int& b)
{
for (auto& e : edge[root])
{
if (e == parent[root])
continue;
if (check[e] == 0)
check[e] = check[root];
}
if (check[root] == 1 && a > 0)
{
num[root] = 1;
a--;
}
if (check[root] == 2 && b > 0)
{
num[root] = 2;
b--;
}
for (auto& e : edge[root])
{
if (e == parent[root])
continue;
mark(e, num, a, b);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
memset(parent, -1, sizeof(parent));
for (int i = 0; i < p.size(); i++)
{
edge[p[i]].push_back(q[i]);
edge[q[i]].push_back(p[i]);
}
if (p.size() == n - 1)
{
vector<int> num(n, 0);
dfs(0);
for (int i = 1; i < n; i++)
{
int ai = sub[i];
int bi = n - sub[i];
if (min(ai, bi) < min(a, b) || max(ai, bi) < max(a, b))
continue;
if (ai >= a && bi >= b)
{
check[i] = 1;
check[0] = 2;
}
else
{
check[0] = 1;
check[i] = 2;
}
mark(0, num, a, b);
for (int j = 0; j < n; j++)
{
if (num[j] == 0)
num[j] = 3;
}
break;
}
return num;
}
else
{
vector<int> num(n, -1);
queue<int> que;
que.push(1);
b--;
num[1] = 2;
while (!que.empty() && b > 0)
{
auto now = que.front();
que.pop();
for (auto& e : edge[now])
{
if (num[e] != -1)
continue;
if (b == 0)
break;
num[e] = 2;
que.push(e);
b--;
}
}
for (int i = 0; i < n; i++)
{
if (num[i] == -1)
{
num[i] = 1;
break;
}
}
for (int i = 0; i < n; i++)
{
if (num[i] == -1)
num[i] = 3;
}
return num;
}
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:82:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < p.size(); i++)
~~^~~~~~~~~~
split.cpp:88:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (p.size() == n - 1)
~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |