Advertisement
DarkTXYZ

TOI10: Map

Apr 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using pii = pair<pair<int,int>,int>;
  5.  
  6. /*
  7.     0 --> no edge
  8.     1 --> left
  9.     2 --> right
  10.     3 --> up
  11.     4 --> down
  12. */
  13.  
  14. vector<pair<int,int> > G[40005];
  15. int MAP[205][205];
  16. bool visited[40005],cvisited[40005];
  17. map<int,pair<int,int> > M,CM;
  18. pii mx = {{0,0},0};
  19. int n,m;
  20.  
  21. void setmap(){
  22.     M[1] = {0,1};
  23.     M[2] = {0,-1};
  24.     M[3] = {1,0};
  25.     M[4] = {-1,0};
  26.     CM[1] = {0,-1};
  27.     CM[2] = {0,1};
  28.     CM[3] = {-1,0};
  29.     CM[4] = {1,0};
  30. }
  31.  
  32. void dfs(int x,int y,int u){
  33.     visited[u] = true;
  34.     mx = max(mx,{{x,y},u});
  35.     for(auto c : G[u]){
  36.         if(!visited[c.first]){
  37.             int vx = M[c.second].first;
  38.             int vy = M[c.second].second;
  39.             dfs(x+vx,y+vy,c.first);
  40.         }
  41.     }
  42. }
  43.  
  44. void createmap(int x,int y,int u){
  45.     cvisited[u] = true;
  46.     MAP[x][y] = u;
  47.     for(auto c : G[u]){
  48.         if(!cvisited[c.first]){
  49.             int vx = CM[c.second].first;
  50.             int vy = CM[c.second].second;
  51.             createmap(x+vx,y+vy,c.first);
  52.         }
  53.     }
  54. }
  55.  
  56. void print(){
  57.     for(int i=0;i<n;i++){
  58.         for(int j=0;j<m;j++)
  59.             printf("%d ",MAP[i][j]);
  60.         printf("\n");
  61.     }
  62. }
  63.  
  64.  
  65. int main(){
  66.     setmap();
  67.     scanf("%d%d",&n,&m);
  68.     for(int i=1;i<n*m;i++){
  69.         int u,v;
  70.         char d;
  71.         scanf("%d %c %d",&u,&d,&v);
  72.         if(d == 'L'){
  73.             G[u].push_back({v,2});
  74.             G[v].push_back({u,1});
  75.         }
  76.         else if(d == 'U'){
  77.             G[u].push_back({v,4});
  78.             G[v].push_back({u,3});
  79.         }
  80.     }
  81.     dfs(0,0,0);
  82.     int u = mx.second;
  83.     createmap(0,0,u);
  84.     print();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement