fork download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <cstdio>
  16. #include <cmath>
  17. #include <cstdlib>
  18. #include <ctime>
  19.  
  20. using namespace std;
  21.  
  22. class PalindromePath {
  23. public:
  24. int shortestLength(int, vector <int>, vector <int>, string);
  25. };
  26.  
  27. char am[25][25];
  28. bool visit[25][25];
  29. int memo[25][25];
  30.  
  31. int dp(int a, int b)
  32. {
  33. visit[a][b] = true;
  34. if(am[a][b] != 'N')
  35. return 1;
  36. if(a == b)
  37. return 0;
  38. int ans = -1;
  39. for(int i = 0;i < 25;i++)
  40. {
  41. for(int j = 0;j < 25;j++)
  42. {
  43. if(!visit[i][j] && am[a][i] != 'N' && am[b][j] != 'N' && am[a][i] == am[b][j])
  44. {
  45. int len = dp(i,j);
  46. if(len != -1)
  47. {
  48. if(ans == -1)
  49. ans = len+2;
  50. else
  51. ans = min(ans, len+2);
  52. }
  53. }
  54. }
  55. }
  56. return ans;
  57. }
  58.  
  59. int PalindromePath::shortestLength(int n, vector <int> a, vector <int> b, string c) {
  60. for(int i = 0;i < 25;i++)
  61. {
  62. for(int j = 0;j < 25;j++)
  63. {
  64. am[i][j] = 'N';
  65. visit[i][j] = false;
  66. }
  67. }
  68. for(int i = 0;i < a.size();i++)
  69. {
  70. am[a[i]][b[i]] = c[i];
  71. am[b[i]][a[i]] = c[i];
  72. }
  73. return dp(0,1);
  74. }
  75.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty