이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bulb.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>;
int parent[300005];
int sel[1005][1005];
bool visit[1005];
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int N = L.size();
for (int i = 0; i < N; i++)
{
if (L[i] >= 0)
parent[L[i]] = i;
if (R[i] >= 0)
parent[R[i]] = i;
}
// �� ó�� ��
int first = 0;
while (first >= 0)
first = L[first];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
sel[i][j] = first;
for (int i = 0; i < N; i++)
{
memset(visit, false, sizeof(visit));
if (L[i] < 0)
{
vector<int> rs;
int now = i;
visit[i] = true;
while (now != parent[now])
{
if (now == R[parent[now]])
rs.push_back(parent[now]);
now = parent[now];
visit[now] = true;
}
if (rs.size() == 2)
{
sel[rs[0]][rs[1]] = L[i];
sel[rs[1]][rs[0]] = L[i];
}
if (rs.size() == 1)
{
for (int j = 0; j < N; j++)
if (!visit[j])
sel[rs[0]][j] = sel[j][rs[0]] = L[i];
}
}
if (R[i] < 0)
{
vector<int> rs;
rs.push_back(i);
int now = i;
visit[i] = true;
while (now != parent[now])
{
if (now == R[parent[now]])
rs.push_back(parent[now]);
now = parent[now];
visit[now] = true;
}
if (rs.size() == 2)
{
sel[rs[0]][rs[1]] = R[i];
sel[rs[1]][rs[0]] = R[i];
}
if (rs.size() == 1)
{
for (int j = 0; j < N; j++)
if (!visit[j])
sel[rs[0]][j] = sel[j][rs[0]] = L[i];
}
}
}
int winner = 0;
for (int f = 0; f < N; f++)
{
//��� �ι�° ���ÿ� ���� �� R�� ������ �¸� ����
bool allRed = true;
for (int s = 0; s < N; s++)
{
if (sel[f][s] == -2)
allRed = false;
}
if (allRed)
winner = 1;
}
return winner;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |