#include <bits/stdc++.h>
#include "worldmap.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(v) v.begin(), v.end()
constexpr ll inf = 1ll << 62ll;
mt19937 mt(time(0));
ll _ = 0;
void fix_answer(vector<vector<int>> &res) {
ll k = res.size();
for (ll i = 0; i < k; i++) {
for (ll j = 0; j < k; j++) {
res[i][j]++;
}
}
}
vector<vector<int>> create_map(int N, int M, vector<int> u, vector<int> v) {
ll n = N, m = M;
if (n == 1) return {{1}};
vector<set<ll>> adj(n);
for (ll i = 0; i < m; i++) {
adj[u[i]-1].insert(v[i]-1);
adj[v[i]-1].insert(u[i]-1);
}
vector<ll> rows;
vector<ll> node_row(n);
ll mx_used = 0;
auto dfs = [&](const auto &self, ll cur) -> void {
ll child_cnt = 0;
for (auto &e : adj[cur]) {
child_cnt += !node_row[e];
}
if (!child_cnt) return;
mx_used = node_row[cur] = rows.size() + 1;
rows.push_back(cur);
rows.push_back(cur);
rows.push_back(cur);
for (auto &e : adj[cur]) {
if (node_row[e]) continue;
self(self, e);
rows.push_back(cur);
}
};
dfs(dfs, 0);
rows.erase(rows.begin());
while (rows.size() > mx_used) rows.pop_back();
ll k = max((ll)rows.size(), 2 * n - 3);
while (rows.size() < k) rows.push_back(rows.back());
vector<vector<int>> res(k);
for (ll i = 0; i < k; i++) {
res[i] = vector<int>(k, rows[i]);
}
for (ll i = 0; i < n; i++) {
if (!node_row[i]) continue;
ll col = 0;
for (auto &e : adj[i]) {
res[node_row[i]-1][col] = e;
col += 2;
}
}
fix_answer(res);
return res;
}
#ifdef TEST
#include "grader.cpp"
#endif
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |