제출 #1255886

#제출 시각아이디문제언어결과실행 시간메모리
1255886madamadam3World Map (IOI25_worldmap)C++20
15 / 100
1095 ms2452 KiB
#include "worldmap.h" #include <bits/stdc++.h> using namespace std; // #define int long long int using vi = vector<int>; using vvi = vector<vi>; void dfs(int u, vector<bool> &vis, vvi &adj, vi &tour) { vis[u] = true; tour.push_back(u); // sort(adj[u].begin(), adj[u].end(), [&](int a, int b) {return adj[a].size() < adj[b].size();}); for (int v : adj[u]) { if (vis[v]) continue; dfs(v, vis, adj, tour); tour.push_back(u); } } bool validate(int n, int m, vi a, vi b, vvi ret) { set<pair<int, int>> adjacencies; set<pair<int, int>> expected; for (int i = 0; i < m; i++) { expected.insert({min(a[i], b[i]), max(a[i], b[i])}); } int k = ret.size(); for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { if (i > 0 && ret[i-1][j] != ret[i][j]) adjacencies.insert({min(ret[i][j], ret[i-1][j]), max(ret[i][j], ret[i-1][j])}); if (j > 0 && ret[i][j-1] != ret[i][j]) adjacencies.insert({min(ret[i][j], ret[i][j-1]), max(ret[i][j], ret[i][j-1])}); if (i < k-1 && ret[i+1][j] != ret[i][j]) adjacencies.insert({min(ret[i][j], ret[i+1][j]), max(ret[i][j], ret[i+1][j])}); if (j < k-1 && ret[i][j+1] != ret[i][j]) adjacencies.insert({min(ret[i][j], ret[i][j+1]), max(ret[i][j], ret[i][j+1])}); } } for (auto &el : adjacencies) { if (!expected.count(el)) return false; } for (auto &el :expected) { if (!adjacencies.count(el)) return false; } return true; } vvi create_map(int n, int m, vi a, vi b) { vvi adj(n+1, vi()); for (int i = 0; i < m; i++) adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]); int ladj = 1; for (int i = 2; i <= n; i++) if (adj[i].size() > adj[ladj].size()) ladj = i; int K = 2*n; // cerr << "Using K = " << K << "\n"; vector<set<pair<int, int>>> diags(2*K-1); for (int i = 0; i < K; i++) { for (int j = 0; j < K; j++) { int md = i + j; diags[md].insert({i, j}); } } vector<bool> vis(n+1, false); vi tour; set<int> seen; dfs(1, vis, adj,tour); vvi ans(K, vi(K, 1)), dgs(n+1); set<pair<int, int>> used_edges; int cdx = 0; set<int> used; for (int i = 0; i < tour.size(); i++) { for (auto &el : diags[cdx]) { ans[el.first][el.second] = tour[i]; } cdx++; if (used.count(tour[i]) || tour[i] == ladj) continue; used.insert(tour[i]); int radj = 0; for (auto &el : adj[tour[i]]) if (!used_edges.count({min(tour[i], el), max(tour[i], el)})) radj++; for (auto &el : adj[tour[i]]) used_edges.insert({min(tour[i], el), max(tour[i], el)}); int cnt = 0; while (cnt < radj) { cnt += diags[cdx].size(); dgs[tour[i]].push_back(cdx); cdx++; for (auto &el : diags[cdx]) { ans[el.first][el.second] = tour[i]; } cdx++; } } used_edges.clear(); for (int i = 1; i <= n; i++) { int aidx = 0; for (auto &gd : dgs[i]) { for (auto &el : diags[gd]) { ans[el.first][el.second] = i; if (aidx >= adj[i].size()) { continue; } int cedge = adj[i][aidx++]; if (used_edges.count({min(i, cedge), max(i, cedge)})) continue; used_edges.insert({min(i, cedge), max(i, cedge)}); ans[el.first][el.second] = cedge; } } } // cerr << "Is the answer valid? " << validate(n, m, a, b, ans) << "\n"; return ans; }
#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...