Submission #1253170

#TimeUsernameProblemLanguageResultExecution timeMemory
1253170dreamnguyenWorld Map (IOI25_worldmap)C++20
100 / 100
19 ms2888 KiB
#include <bits/stdc++.h> #include "worldmap.h" using namespace std; typedef vector<int> vi; vector<vi> world_map; vi adj[50], tree[50]; int vis[50], par[50]; int sz[50], depth[50]; pair<int, int> pos[50]; void DFS(int node, int prev, int d) { vis[node] = 1; depth[node] = d; sz[node] = 1; for (int v : adj[node]) { if (v == prev || vis[v]) continue; par[v] = node; tree[node].push_back(v); tree[v].push_back(node); DFS(v, node, d + 1); sz[node] += sz[v]; } } void Build(int node, int prev, int left, int right, int level) { for (int i = left; i <= right; ++i) { world_map[level * 2][i] = node; } for (int i = left; i <= right; ++i) if ((i - left) % 2 == 1) { world_map[level * 2 + 1][i] = node; if (level > 0) world_map[level * 2 - 1][i] = node; } pos[node] = {level * 2, left + 1}; for (int child : tree[node]) { if (child == prev) continue; ++left; Build(child, node, left, left + sz[child] * 2 - 2, level + 1); left += sz[child] * 2 - 1; } } vector<vi> create_map(int n, int m, vi a, vi b) { world_map.assign(n * 2 - 1, vi(n * 2 - 1, 0)); for (int i = 1; i <= n; ++i) { adj[i].clear(); tree[i].clear(); vis[i] = 0; } for (int i = 0; i < m; ++i) { adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); } DFS(1, 0, 0); Build(1, 0, 0, 2 * n - 2, 0); for (int i = 1; i <= n; ++i) for (int v : adj[i]) { if (depth[v] > depth[i] && par[v] != i) { auto &[x, y] = pos[i]; world_map[x][y] = v; y += 2; } } for (int i = 0; i < 2 * n - 1; ++i) for (int j = 0; j < 2 * n - 1; ++j) if (world_map[i][j] == 0) { if (i > 0) world_map[i][j] = world_map[i - 1][j]; else world_map[i][j] = world_map[i][j - 1]; } return world_map; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...