Advertisement
Guest User

Untitled

a guest
May 25th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. ifstream is("p1.in");
  7. ofstream os("p1.out");
  8.  
  9. int N, X, Y, x, y, z;
  10. vector <pair<int,int> > V[500];
  11. int Cost[500];
  12. int Nr[500];
  13. priority_queue <pair<int,int>, vector <pair<int,int> > , greater <pair<int,int> > > P;
  14.  
  15. void Input();
  16. void Dijkstra();
  17.  
  18. int main()
  19. {
  20. Input();
  21. Dijkstra();
  22. /* for ( int i = 1; i <= N; ++i )
  23. os << Cost[i] << " "; */
  24.  
  25. os << Nr[Y];
  26.  
  27. is.close();
  28. os.close();
  29. }
  30.  
  31. void Input()
  32. {
  33. is >> N >> X >> Y;
  34. while ( is >> x )
  35. {
  36. is >> y >> z;
  37. V[x].push_back(make_pair(y,z));
  38. V[y].push_back(make_pair(x,z));
  39. }
  40. for ( int i = 2; i <= N; ++i )
  41. Cost[i] = 0x3f3f3f3f;
  42.  
  43.  
  44. }
  45.  
  46. void Dijkstra()
  47. {
  48. P.push(make_pair(0,X));
  49. int node;
  50. while ( !P.empty() )
  51. {
  52. node = P.top().second;
  53. P.pop();
  54. for ( const auto& v : V[node] )
  55. {
  56. if ( Cost[v.first] > Cost[node] + v.second )
  57. {
  58. Cost[v.first] = Cost[node] + v.second;
  59. Nr[v.first] = 1;
  60. P.push(make_pair(Cost[v.first],v.first));
  61. }
  62. else
  63. if ( Cost[v.first] == Cost[node] + v.second )
  64. Nr[v.first]++;
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement