//testing AI COde
#include "worldmap.h"
#include <bits/stdc++.h>
using namespace std;
// We create a DFS order of the adjacency graph and use it as the linear ordering.
// Then we place that ordering onto a cyclic Latin torus grid of size K = N.
vector<vector<int>> create_map(int N, int M, vector<int> A, vector<int> B) {
vector<vector<int>> G(N+1);
for (int i = 0; i < M; i++) {
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
// --- Step 1: DFS order to linearize the adjacency graph ---
vector<int> order;
vector<int> vis(N+1, 0);
function<void(int)> dfs = [&](int u) {
vis[u] = 1;
order.push_back(u);
for (int v : G[u]) if (!vis[v]) dfs(v);
};
// Graph might be disconnected → start DFS from all nodes.
for (int i = 1; i <= N; i++)
if (!vis[i]) dfs(i);
// Build reverse mapping: newLabel[country] = position in DFS order
vector<int> newLabel(N+1);
for (int i = 0; i < N; i++)
newLabel[order[i]] = i + 1; // 1..N
// --- Step 2: K = N ---
int K = N;
vector<vector<int>> C(K, vector<int>(K));
// --- Step 3: Fill torus grid with cyclic pattern ---
for (int r = 0; r < K; r++) {
for (int c = 0; c < K; c++) {
int id = 1 + (r + c) % N; // id in 1..N
// Map id back to original country
int country = order[id - 1]; // inverse of newLabel
C[r][c] = country;
}
}
return C;
}
| # | 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... |