Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. /*
  2. $$$$$$$\ $$\ $$$$$$$\
  3. $$ __$$\ \__| $$ __$$\
  4. $$ | $$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\
  5. $$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ _____|$$$$$$$\ | \____$$\ $$ __$$\ $$ _____|\____$$\
  6. $$ __$$\ $$ / $$ |$$ | \__|$$ |\$$$$$$\ $$ __$$\ $$$$$$$ |$$ | \__|$$ / $$$$$$$ |
  7. $$ | $$ |$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ __$$ |$$ | $$ | $$ __$$ |
  8. $$$$$$$ |\$$$$$$ |$$ | $$ |$$$$$$$ |$$$$$$$ |\$$$$$$$ |$$ | \$$$$$$$\\$$$$$$$ |
  9. \_______/ \______/ \__| \__|\_______/ \_______/ \_______|\__| \_______|\_______|
  10. */
  11. #include <bits/stdc++.h>
  12.  
  13. typedef long long ll;
  14. #define pb push_back
  15. #define mp make_pair
  16. #define pii pair <int,int>
  17. #define in insert
  18. #define X first
  19. #define Y second
  20. #define frn front
  21. #define bc back
  22. #define rep(i,a,b)for (ll (i) = (a); (i) < b(); ++(i))
  23. #define _ << " " <<
  24. #define sz(x) (int)x.size()
  25. #define all(a) (a).begin(),(a).end()
  26.  
  27. using namespace std;
  28.  
  29. const int MAXN = 100;
  30.  
  31. int a, b, c, x, y, sol = 10000;
  32.  
  33. map <pii, int> m;
  34.  
  35. vector <int> graph[MAXN];
  36.  
  37. void bfs(){
  38. bool bio[100];
  39. memset(bio, 0, sizeof bio);
  40. queue <int> q;
  41. q.push(x);
  42. q.push(0);
  43. while (!q.empty()){
  44. x = q.frn();
  45. q.pop();
  46. int t = q.frn();
  47. q.pop();
  48. cout <<x _ t<<endl;
  49. if (x == y){
  50. sol = min(sol, t);
  51. continue;
  52. }
  53. if (bio[x])
  54. continue;
  55. bio[x]++;
  56. for (auto u : graph[x]){
  57. q.push(u);
  58. q.push(t + m[mp(x, u)]);
  59. }
  60. }
  61. }
  62.  
  63. int main () {
  64. ios_base::sync_with_stdio(false);
  65. cin >>a>>b>>c;
  66. graph[1] = {8, 7, 2};
  67. graph[2] = {1, 3, 9};
  68. graph[3] = {2, 10, 4};
  69. graph[4] = {3, 5, 11};
  70. graph[5] = {6, 4, 12};
  71. graph[6] = {7, 13, 5};
  72. graph[7] = {6, 1, 14};
  73. graph[8] = {14, 9, 1};
  74. graph[9] = {8, 10, 2};
  75. graph[10] = {9, 11, 3};
  76. graph[11] = {10, 12, 4};
  77. graph[12] = {11, 13, 5};
  78. graph[13] = {12, 14, 6};
  79. graph[14] = {13, 8, 7};
  80. for (int i = 1; i < 8; ++i)
  81. for (int j = 1; j < 8; ++j)
  82. m[mp(i, j)] = a;
  83. for (int i = 8; i < 15; ++i)
  84. for (int j = 8; j < 15; ++j)
  85. m[mp(i, j)] = b;
  86. for (int i = 1; i < 8; ++i)
  87. m[mp(i, i + 7)] = c;
  88. for (int i = 8; i < 15; ++i)
  89. m[mp(i, i - 7)] = c;
  90. cin >>x>>y;
  91. bfs();
  92. cout <<sol<<endl;
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement