Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 17th, 2018 86 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. // 1358 TIMUS
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <cmath>
  10. #include <ctime>
  11. #include <cstdlib>
  12.  
  13. using namespace std;
  14. #define pi 3.1415926535897932384626433832795
  15. int n;
  16. vector <vector <int> > g;
  17. vector <bool> b(1001, false);
  18. vector <int> x, y, h;
  19. void dfs(int v, int px, int py)
  20. {
  21.     b[v] = true;
  22.     x[v] = px;
  23.     y[v] = py;
  24.     int cnt = 0, j = 0;
  25.     for (int i = 0; i < g[v].size(); i++)      
  26.         if (!b[g[v][i]]) cnt++;
  27.     for (int i = 0; i < g[v].size(); i++)
  28.         if (!b[g[v][i]])
  29.         {
  30.             int alpha = 2 * pi / j;
  31.             dfs(g[v][i], round(cos(alpha) * cnt), round(sin(alpha) * cnt));
  32.             j++;
  33.         }
  34. };
  35. int main()
  36. {
  37.     scanf("%d", &n);
  38.     g.resize(n);
  39.     x.resize(n);
  40.     y.resize(n);
  41.    
  42.     for (int i = 0; i < n - 1; i++){
  43.         int u, v;
  44.         scanf("%d%d", &u, &v);
  45.         --u; --v;
  46.         g[u].push_back(v);
  47.         g[v].push_back(u);
  48.     }
  49.     dfs(0, 0, 0);
  50.     for (int i = 0; i < n; i++)
  51.     cout << x[i] << " " << y[i] << "\n";
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top