Submission #1063126

#TimeUsernameProblemLanguageResultExecution timeMemory
1063126fv3Fountain Parks (IOI21_parks)C++17
15 / 100
152 ms39912 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; vector<int> visited; int DFS(int index) { int sz = 1; visited[index] = 1; for (auto node : adj[index]) { if (visited[node]) continue; sz += DFS(node); } return sz; } int construct_roads(vector<int> x, vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } // x[i] = 2 const int N = x.size(); vector<pair<int, int>> l = {}, r = {}; for (int i = 0; i < N; i++) { if (x[i] == 2) l.push_back({y[i], i}); else r.push_back({y[i], i}); } sort(l.begin(), l.end()); sort(r.begin(), r.end()); adj = vector<vector<int>>(N); vector<int> U, V, A, B; for (int i = 0; i < (int)l.size() - 1; i++) { if (l[i].first + 2 != l[i+1].first) continue; int a = l[i].second; int b = l[i+1].second; adj[a].push_back(b); adj[b].push_back(a); U.push_back(a); V.push_back(b); A.push_back(1); B.push_back(l[i].first + 1); } for (int i = 0; i < (int)r.size() - 1; i++) { if (r[i].first + 2 != r[i+1].first) continue; int a = r[i].second; int b = r[i+1].second; adj[a].push_back(b); adj[b].push_back(a); U.push_back(a); V.push_back(b); A.push_back(5); B.push_back(r[i].first + 1); } if (r.size()) l.insert(l.end(), r.begin(), r.end()); sort(l.begin(), l.end()); for (int i = 0; i < N - 1; i++) { if (l[i].first != l[i+1].first) continue; int a = l[i].second; int b = l[i+1].second; adj[a].push_back(b); adj[b].push_back(a); U.push_back(a); V.push_back(b); A.push_back(3); B.push_back(l[i].first + 1); } visited = vector<int>(N); int sz = DFS(0); if (sz != N) return 0; build(U, V, A, B); return 1; }
#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...