제출 #1229093

#제출 시각아이디문제언어결과실행 시간메모리
1229093Ludissey분수 공원 (IOI21_parks)C++20
0 / 100
1 ms324 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() vector<int> sz,parent; int getParent(int a){ if(parent[a]==a) return a; return parent[a]=getParent(parent[a]); } bool same(int a, int b){ a=getParent(a); b=getParent(b); return (a==b); } void unite(int a, int b){ a=getParent(a); b=getParent(b); if(a==b) return; if(sz[a]<sz[b]){ swap(a,b); } sz[a]+=sz[b]; parent[b]=a; } int construct_roads(std::vector<int> x, std::vector<int> y) { int n=sz(x); vector<pair<int,int>> f(n); sz.resize(n,1); parent.resize(n); for (int i = 0; i < n; i++) parent[i]=i; for (int i = 0; i < n; i++) f[i]={x[i],y[i]}; map<pair<int,int>, int> mp; for (int i = 0; i < n; i++) mp[{x[i],y[i]}]=i; std::vector<int> u, v, a, b; for (int i = 0; i < n; i++) { pair<int,int> und={f[i].first,f[i].second+2}; if(mp.find(und)!=mp.end()){ if(!same(i,mp[und])){ unite(i,mp[und]); u.push_back(i); v.push_back(mp[und]); a.push_back(f[i].first-1); b.push_back(f[i].second+1); } } pair<int,int> rgt={f[i].first+2,f[i].second}; if(mp.find(rgt)!=mp.end()){ if(!same(i,mp[rgt])){ unite(i,mp[rgt]); u.push_back(i); v.push_back(mp[rgt]); a.push_back(f[i].first+1); b.push_back(f[i].second-1); } } } if (sz[getParent(0)] != n) { build({}, {}, {}, {}); return 1; } 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...