Submission #864719

# Submission time Handle Problem Language Result Execution time Memory
864719 2023-10-23T13:41:29 Z mychecksedad Drawing (CEOI22_drawing) C++17
100 / 100
200 ms 61328 KB
/* 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

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 time Memory Grader output
1 Correct 74 ms 34132 KB Output is correct
2 Correct 80 ms 39428 KB Output is correct
3 Correct 77 ms 37200 KB Output is correct
4 Correct 93 ms 41300 KB Output is correct
5 Correct 82 ms 41812 KB Output is correct
6 Correct 73 ms 34048 KB Output is correct
7 Correct 79 ms 34900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27480 KB Output is correct
2 Correct 9 ms 27484 KB Output is correct
3 Correct 8 ms 27484 KB Output is correct
4 Correct 8 ms 27740 KB Output is correct
5 Correct 8 ms 27748 KB Output is correct
6 Correct 8 ms 27488 KB Output is correct
7 Correct 7 ms 27480 KB Output is correct
8 Correct 8 ms 27404 KB Output is correct
9 Correct 8 ms 27896 KB Output is correct
10 Correct 9 ms 27484 KB Output is correct
11 Correct 8 ms 27740 KB Output is correct
12 Correct 8 ms 27704 KB Output is correct
13 Correct 7 ms 27484 KB Output is correct
14 Correct 8 ms 27480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27480 KB Output is correct
2 Correct 9 ms 27484 KB Output is correct
3 Correct 8 ms 27484 KB Output is correct
4 Correct 8 ms 27740 KB Output is correct
5 Correct 8 ms 27748 KB Output is correct
6 Correct 8 ms 27488 KB Output is correct
7 Correct 7 ms 27480 KB Output is correct
8 Correct 8 ms 27404 KB Output is correct
9 Correct 8 ms 27896 KB Output is correct
10 Correct 9 ms 27484 KB Output is correct
11 Correct 8 ms 27740 KB Output is correct
12 Correct 8 ms 27704 KB Output is correct
13 Correct 7 ms 27484 KB Output is correct
14 Correct 8 ms 27480 KB Output is correct
15 Correct 11 ms 27736 KB Output is correct
16 Correct 11 ms 28252 KB Output is correct
17 Correct 12 ms 27996 KB Output is correct
18 Correct 12 ms 28508 KB Output is correct
19 Correct 12 ms 28508 KB Output is correct
20 Correct 13 ms 27740 KB Output is correct
21 Correct 12 ms 27996 KB Output is correct
22 Correct 11 ms 27740 KB Output is correct
23 Correct 12 ms 27996 KB Output is correct
24 Correct 11 ms 27996 KB Output is correct
25 Correct 11 ms 28512 KB Output is correct
26 Correct 11 ms 28504 KB Output is correct
27 Correct 11 ms 27740 KB Output is correct
28 Correct 12 ms 27992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27480 KB Output is correct
2 Correct 9 ms 27484 KB Output is correct
3 Correct 8 ms 27484 KB Output is correct
4 Correct 8 ms 27740 KB Output is correct
5 Correct 8 ms 27748 KB Output is correct
6 Correct 8 ms 27488 KB Output is correct
7 Correct 7 ms 27480 KB Output is correct
8 Correct 8 ms 27404 KB Output is correct
9 Correct 8 ms 27896 KB Output is correct
10 Correct 9 ms 27484 KB Output is correct
11 Correct 8 ms 27740 KB Output is correct
12 Correct 8 ms 27704 KB Output is correct
13 Correct 7 ms 27484 KB Output is correct
14 Correct 8 ms 27480 KB Output is correct
15 Correct 11 ms 27736 KB Output is correct
16 Correct 11 ms 28252 KB Output is correct
17 Correct 12 ms 27996 KB Output is correct
18 Correct 12 ms 28508 KB Output is correct
19 Correct 12 ms 28508 KB Output is correct
20 Correct 13 ms 27740 KB Output is correct
21 Correct 12 ms 27996 KB Output is correct
22 Correct 11 ms 27740 KB Output is correct
23 Correct 12 ms 27996 KB Output is correct
24 Correct 11 ms 27996 KB Output is correct
25 Correct 11 ms 28512 KB Output is correct
26 Correct 11 ms 28504 KB Output is correct
27 Correct 11 ms 27740 KB Output is correct
28 Correct 12 ms 27992 KB Output is correct
29 Correct 53 ms 32004 KB Output is correct
30 Correct 75 ms 38484 KB Output is correct
31 Correct 58 ms 36948 KB Output is correct
32 Correct 60 ms 39764 KB Output is correct
33 Correct 62 ms 38996 KB Output is correct
34 Correct 55 ms 34384 KB Output is correct
35 Correct 58 ms 35412 KB Output is correct
36 Correct 50 ms 33612 KB Output is correct
37 Correct 60 ms 37200 KB Output is correct
38 Correct 58 ms 37456 KB Output is correct
39 Correct 66 ms 38880 KB Output is correct
40 Correct 65 ms 37420 KB Output is correct
41 Correct 52 ms 33620 KB Output is correct
42 Correct 58 ms 35664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 34132 KB Output is correct
2 Correct 80 ms 39428 KB Output is correct
3 Correct 77 ms 37200 KB Output is correct
4 Correct 93 ms 41300 KB Output is correct
5 Correct 82 ms 41812 KB Output is correct
6 Correct 73 ms 34048 KB Output is correct
7 Correct 79 ms 34900 KB Output is correct
8 Correct 7 ms 27480 KB Output is correct
9 Correct 9 ms 27484 KB Output is correct
10 Correct 8 ms 27484 KB Output is correct
11 Correct 8 ms 27740 KB Output is correct
12 Correct 8 ms 27748 KB Output is correct
13 Correct 8 ms 27488 KB Output is correct
14 Correct 7 ms 27480 KB Output is correct
15 Correct 8 ms 27404 KB Output is correct
16 Correct 8 ms 27896 KB Output is correct
17 Correct 9 ms 27484 KB Output is correct
18 Correct 8 ms 27740 KB Output is correct
19 Correct 8 ms 27704 KB Output is correct
20 Correct 7 ms 27484 KB Output is correct
21 Correct 8 ms 27480 KB Output is correct
22 Correct 11 ms 27736 KB Output is correct
23 Correct 11 ms 28252 KB Output is correct
24 Correct 12 ms 27996 KB Output is correct
25 Correct 12 ms 28508 KB Output is correct
26 Correct 12 ms 28508 KB Output is correct
27 Correct 13 ms 27740 KB Output is correct
28 Correct 12 ms 27996 KB Output is correct
29 Correct 11 ms 27740 KB Output is correct
30 Correct 12 ms 27996 KB Output is correct
31 Correct 11 ms 27996 KB Output is correct
32 Correct 11 ms 28512 KB Output is correct
33 Correct 11 ms 28504 KB Output is correct
34 Correct 11 ms 27740 KB Output is correct
35 Correct 12 ms 27992 KB Output is correct
36 Correct 53 ms 32004 KB Output is correct
37 Correct 75 ms 38484 KB Output is correct
38 Correct 58 ms 36948 KB Output is correct
39 Correct 60 ms 39764 KB Output is correct
40 Correct 62 ms 38996 KB Output is correct
41 Correct 55 ms 34384 KB Output is correct
42 Correct 58 ms 35412 KB Output is correct
43 Correct 50 ms 33612 KB Output is correct
44 Correct 60 ms 37200 KB Output is correct
45 Correct 58 ms 37456 KB Output is correct
46 Correct 66 ms 38880 KB Output is correct
47 Correct 65 ms 37420 KB Output is correct
48 Correct 52 ms 33620 KB Output is correct
49 Correct 58 ms 35664 KB Output is correct
50 Correct 86 ms 38740 KB Output is correct
51 Correct 192 ms 55120 KB Output is correct
52 Correct 164 ms 51536 KB Output is correct
53 Correct 200 ms 55376 KB Output is correct
54 Correct 177 ms 61328 KB Output is correct
55 Correct 144 ms 45924 KB Output is correct
56 Correct 174 ms 47496 KB Output is correct
57 Correct 33 ms 31060 KB Output is correct
58 Correct 181 ms 51312 KB Output is correct
59 Correct 159 ms 50508 KB Output is correct
60 Correct 191 ms 60244 KB Output is correct
61 Correct 178 ms 54076 KB Output is correct
62 Correct 32 ms 31056 KB Output is correct
63 Correct 160 ms 47444 KB Output is correct