이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
const ll N = 1005;
ll dsu[N];
ll repr(ll x)
{
return dsu[x] < 0 ? x : dsu[x] = repr(dsu[x]);
}
bool Union(ll x, ll y)
{
x = repr(x), y = repr(y);
if (x == y)
return false;
if (dsu[x] < dsu[y])
swap(x, y);
dsu[y] += dsu[x];
dsu[x] = y;
return true;
}
vector<int> g[N];
ll cnt[N][N];
bool used[N];
void dfs(ll v, ll st)
{
cnt[v][st]++;
used[v] = 1;
for (ll to : g[v])
if (!used[to])
dfs(to, st);
used[v] = 0;
}
int construct(vector<vector<int>> p)
{
ll n = p.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
for (ll i = 0; i < n; i++)
for (ll j = 0; j < n; j++)
if (p[i][j] == 3)
return false;
for (ll i = 0; i < n; i++)
dsu[i] = -1;
for (ll i = 0; i < n; i++)
for (ll j = 0; j < n; j++)
if (p[i][j] == 1)
Union(i, j);
vector<int> v[n];
for (ll i = 0; i < n; i++)
v[repr(i)].push_back(i);
vector<int> check;
for (ll i = 0; i < n; i++)
{
if (!v[i].empty())
check.push_back(i);
for (ll j = 0; j + 1 < v[i].size(); j++)
ans[v[i][j]][v[i][j + 1]] = ans[v[i][j + 1]][v[i][j]] = 1, g[v[i][j]].push_back(v[i][j + 1]), g[v[i][j + 1]].push_back(v[i][j]);
}
for (ll i = 0; i < n; i++)
dsu[i] = -1;
for (ll i = 0; i < check.size(); i++)
for (ll j = 0; j < check.size(); j++)
if (p[check[i]][check[j]] == 2)
Union(check[i], check[j]);
for (ll i = 0; i < n; i++)
v[i].clear();
for (ll i = 0; i < n; i++)
v[repr(i)].push_back(i);
for (ll i = 0; i < n; i++)
if (v[i].size() > 2)
{
for (ll j = 0; j < v[i].size(); j++)
ans[v[i][j]][v[i][(j + 1) % v[i].size()]] = ans[v[i][(j + 1) % v[i].size()]][v[i][j]] = 1, g[v[i][j]].push_back(v[i][(j + 1) % v[i].size()]), g[v[i][(j + 1) % v[i].size()]].push_back(v[i][j]);
}
for (ll i = 0; i < n; i++)
dfs(i, i);
for (ll i = 0; i < n; i++)
for (ll j = 0; j < n; j++)
if (cnt[i][j] != p[i][j])
return false;
build(ans);
return true;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (ll j = 0; j + 1 < v[i].size(); j++)
| ~~~~~~^~~~~~~~~~~~~
supertrees.cpp:62:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (ll i = 0; i < check.size(); i++)
| ~~^~~~~~~~~~~~~~
supertrees.cpp:63:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (ll j = 0; j < check.size(); j++)
| ~~^~~~~~~~~~~~~~
supertrees.cpp:73:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (ll j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |