# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
163447 | davitmarg | 게임 (IOI14_game) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
#include "game.h"
#endif
const int N = 1503;
int p[N], sz[N], s[N], n, comp, k;
int par(int v)
{
if (p[v] == v)
return v;
return p[v] = par(p[v]);
}
void dsu(int a, int b)
{
a = par(a);
b = par(b);
if (a == b)
return;
if (sz[b] > sz[a])
swap(a, b);
sz[a] += sz[b];
s[a] += s[b];
comp--;
p[b] = a;
}
void initialize(int x)
{
srand(time(NULL));
n = comp = x;
k = n * (n - 1) / 2;
for (int i = 0; i < n; i++)
{
sz[i] = 1;
p[i] = i;
}
}
int hasEdge(int u, int v)
{
int ans = 0;
else if ((sz[par(u)] * (n - sz[par(u)]) == s[par(u)] + 1) || (sz[par(v)] * (n - sz[par(v)]) == s[par(v)] + 1))
ans = 1;
if (ans)
dsu(u, v);
else
{
s[par(u)]++;
s[par(v)]++;
}
k--;
return ans;
}
#ifdef death
int main()
{
int N;
cin >> N;
initialize(N);
N = N * (N - 1) / 2;
while (N--)
{
int a, b;
cin >> a >> b;
cout << hasEdge(a, b) << endl;
}
return 0;
}
#endif
/*
*/