Submission #864719

#TimeUsernameProblemLanguageResultExecution timeMemory
864719mychecksedadDrawing (CEOI22_drawing)C++17
100 / 100
200 ms61328 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; struct P{ ll x, y; void read(){ cin >> x >> y; } ll operator * (const P &other) const{ return x * other.y - y * other.x; } P operator - (const P &other) const{ return P{x-other.x, y-other.y}; } bool operator < (const P&other)const{ return array<ll,2>{y,-x}>array<ll,2>{other.y,-other.x}; } }; struct Poly{ vector<pair<P, int>> poly; Poly(int n){ poly.resize(n); for(int i = 0; i < n; ++i) poly[i].first.read(), poly[i].second = i; } void ch(){ sort(all(poly)); vector<pair<P, int>> c; for(int i = 0; i < poly.size(); ++i){ while(c.size() > 1 && (poly[i].first - c[c.size() - 2].first) * (c.back().first - c[c.size() - 2].first) < 0) c.pop_back(); c.pb(poly[i]); } c.pop_back(); reverse(all(poly)); for(int i = 0; i < poly.size(); ++i){ while(c.size() > 1 && (poly[i].first - c[c.size() - 2].first) * (c.back().first - c[c.size() - 2].first) < 0) c.pop_back(); c.pb(poly[i]); } c.pop_back(); poly = c; } }; int n, s[N], pos[N]; vector<int> g[N]; vector<bool> vis, used; void dfs(int v, int p){ s[v] = 1; for(int u: g[v]){ if(u != p) dfs(u, v), s[v] += s[u]; } } // int cen(int v, int p){ // for(int u: g[v]){ // if(u==p||used[u]) continue // if(s[u] > s[v]-s[u]) return cen(u, v); // } // return v; // } // void centroid(int v, vector<pair<P, int>> &v){ // pre(v, v); // int centro = cen(v, v); // sort(all(v)); // pos[v[0].second] = v; // sort(v.begin() + 1, v.end(), [&](const pair<P, int> &x, const pair<P, int> &y){ // return (x.first - v[0].first) * (y.first - v[0].first) < 0; // }); // } void dfs2(int v, int par, vector<pair<P, int>> &p, int &l){ pos[p[l].second] = v; vis[p[l].second] = 1; // cout << v << ' ' << par << '\n'; // cout << p.poly[l].second << '\n'; for(int u: g[v]){ if(u==par) continue; // int po = -1; // for(int i = 0; i < n; ++i){ // if(!vis[p.poly[i].second]){ // if(po == -1) po = i; // else{ // if((p.poly[po].first - p.poly[l].first) * (p.poly[i].first - p.poly[l].first) > 0){ // po = i; // } // } // } // } ++l; dfs2(u, v, p, l); } } void solve(){ cin >> n; for(int i = 0; i < n-1; ++i){ int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } vector<pair<P, int>> v(n); for(int i = 0; i < n; ++i){ v[i].first.read(); v[i].second = i; } vis.resize(n); sort(all(v)); sort(v.begin() + 1, v.end(), [&](const pair<P, int> &x, const pair<P, int> &y){ return (x.first - v[0].first) * (y.first - v[0].first) < 0; }); dfs(1, 1); int c = 0; dfs2(1, 1, v, c); for(int i = 0; i < n; ++i) cout << pos[i] << ' '; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

Main.cpp: In member function 'void Poly::ch()':
Main.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<P, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 0; i < poly.size(); ++i){
      |                    ~~^~~~~~~~~~~~~
Main.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<P, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < poly.size(); ++i){
      |                    ~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:131:15: warning: unused variable 'aa' [-Wunused-variable]
  131 |   int tt = 1, aa;
      |               ^~
#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...