fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. int M[1000][1000];
  4. int Path[10000];
  5. typedef struct
  6. {
  7. char name[3];
  8. int bfs;
  9. int path;
  10.  
  11. }Graph;
  12. Graph node[1000];
  13. int nodes;
  14. int source,dest;
  15. int Q[100000];
  16. int V[101];
  17. int rear,front;
  18. int empty;
  19. int line;
  20. void enqueue(int x)
  21. {
  22. V[x] = 1;
  23. rear = (rear+1)%100000;
  24. Q[rear] = x;
  25. }
  26. int dequeue()
  27. {
  28. if(!isEmpty())
  29. {
  30. front = (front+1)%100000;
  31. return Q[front];
  32. }
  33. }
  34. int isEmpty()
  35. {
  36. return front==rear;
  37. }
  38. int find(char str[5])
  39. {
  40. int i;
  41. for(i=0;i < nodes;i++)
  42. if(!strcmp(str,node[i].name))
  43. return i;
  44. return -1;
  45. }
  46. int BFS(int start)
  47. {
  48. int v;
  49. int i;
  50. int find = 0;
  51. enqueue(start);
  52. V[start] = 1;
  53. while(!isEmpty())
  54. {
  55. v = dequeue();
  56. if(v==dest)
  57. {
  58. return node[v].bfs;
  59. break;
  60. }
  61. for(i = 0;i < nodes;i++)
  62. {
  63. if(M[v][i]&&!V[i])
  64. {
  65. V[i] = 1;
  66. node[i].bfs = node[v].bfs + 1;
  67. node[i].path = v;
  68. enqueue(i);
  69.  
  70.  
  71. }
  72. }
  73. }
  74. return 0;
  75.  
  76. }
  77. int main()
  78. {
  79. int n;
  80. int i,j,k=1;
  81. char t1[5];
  82. char t2[5];
  83. char from[5];
  84. char to[5];
  85. int x,y;
  86. int d = 0;
  87. int prev;
  88. int num;
  89.  
  90.  
  91. while(scanf("%d",&n)==1)
  92. {
  93. if(line!=0)
  94. printf("\n");
  95. line++;
  96.  
  97. for(i=0; i< n;i++)
  98. {
  99. scanf("%s %s",t1,t2);
  100. if(find(t1)==-1)
  101. strcpy(node[nodes++].name,t1);
  102. if(find(t2)==-1)
  103. strcpy(node[nodes++].name,t2);
  104.  
  105. M[find(t1)][find(t2)] = M[find(t2)][find(t1)] = 1;
  106.  
  107. }
  108. scanf("%s %s",from,to);
  109.  
  110. source = find(from);
  111. dest = find(to);
  112. node[source].bfs = 0;
  113.  
  114. if(BFS(source))
  115. {
  116.  
  117. Path[d++] = dest;
  118. num = node[dest].path;
  119.  
  120. while(num!=source)
  121. {
  122. Path[d++] = num;
  123. num = node[num].path;
  124.  
  125. }
  126. Path[d++] = source;
  127. for(i=d-1;i>0;i--)
  128. printf("%s %s\n",node[Path[i]].name,node[Path[i-1]].name);
  129. }
  130. else if(source==dest)
  131. {
  132.  
  133. }
  134. else
  135. printf("No route\n");
  136.  
  137.  
  138. for(i = 0;i < nodes;i++)
  139. for(j = 0;j < nodes;j++)
  140. M[i][j] = 0;
  141. for(i = 0;i < nodes;i++)
  142. {
  143. node[i].bfs = 0;
  144. node[i].path = 0;
  145. strcpy(node[i].name,"");
  146. V[i]=0;
  147. }
  148. for(i = 0;i < d;i++)
  149. Path[i]=0;
  150. for(i = 0;i < 100000;i++)
  151. Q[i] = 0;
  152. source = 0;
  153. dest = 0;
  154. prev = 0;
  155. d = 0;
  156. nodes = 0;
  157. front = rear = 0;
  158. num = 0;
  159. }
  160. return 0;
  161. }
  162.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int dequeue()’:
prog.cpp:28: error: ‘isEmpty’ was not declared in this scope
prog.cpp: In function ‘int BFS(int)’:
prog.cpp:50: warning: unused variable ‘find’
prog.cpp: In function ‘int main()’:
prog.cpp:80: warning: unused variable ‘k’
prog.cpp:85: warning: unused variable ‘x’
prog.cpp:85: warning: unused variable ‘y’
prog.cpp:99: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:108: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
Standard output is empty