Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <queue>
- using namespace std;
- ifstream is("p1.in");
- ofstream os("p1.out");
- int N, X, Y, x, y, z;
- vector <pair<int,int> > V[500];
- int Cost[500];
- int Nr[500];
- priority_queue <pair<int,int>, vector <pair<int,int> > , greater <pair<int,int> > > P;
- void Input();
- void Dijkstra();
- int main()
- {
- Input();
- Dijkstra();
- /* for ( int i = 1; i <= N; ++i )
- os << Cost[i] << " "; */
- os << Nr[Y];
- is.close();
- os.close();
- }
- void Input()
- {
- is >> N >> X >> Y;
- while ( is >> x )
- {
- is >> y >> z;
- V[x].push_back(make_pair(y,z));
- V[y].push_back(make_pair(x,z));
- }
- for ( int i = 2; i <= N; ++i )
- Cost[i] = 0x3f3f3f3f;
- }
- void Dijkstra()
- {
- P.push(make_pair(0,X));
- int node;
- while ( !P.empty() )
- {
- node = P.top().second;
- P.pop();
- for ( const auto& v : V[node] )
- {
- if ( Cost[v.first] > Cost[node] + v.second )
- {
- Cost[v.first] = Cost[node] + v.second;
- Nr[v.first] = 1;
- P.push(make_pair(Cost[v.first],v.first));
- }
- else
- if ( Cost[v.first] == Cost[node] + v.second )
- Nr[v.first]++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement