Submission #1115766

#TimeUsernameProblemLanguageResultExecution timeMemory
1115766staszic_ojuzCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
1496 ms262144 KiB
#include <iostream> #include <vector> #include <utility> #include <queue> using namespace std; enum EdgeState{ NORMAL, DIJKSTRA, DONE }; vector<vector<pair<int, int>>> graph; vector<vector<EdgeState>> states; vector<int> times; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, s, t, u, v; cin>>n>>m>>s>>t>>u>>v; graph.resize(n+7); states.resize(n+7); times.resize(n+7, -1); for (int i=0;i<m;i++){ int v1, v2, w; cin>>v1>>v2>>w; graph[v1].push_back({v2, w}); graph[v2].push_back({v1, w}); states[v1].push_back(NORMAL); states[v2].push_back(NORMAL); } priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> dijkstrapq; dijkstrapq.push({0, {s, 0}}); while (!dijkstrapq.empty()){ pair<int, pair<int, int>> p=dijkstrapq.top(); dijkstrapq.pop(); if (times[p.second.first]!=-1) continue; for (int i=0;i<graph[p.second.first].size();i++){ if (graph[p.second.first][i].first==p.second.second){ states[p.second.first][i]=DIJKSTRA; } } if (p.second.first==t) break; times[p.second.first]=p.first; for (int i=0;i<graph[p.second.first].size();i++){ if (times[graph[p.second.first][i].first]==-1||times[graph[p.second.first][i].first]==p.first+graph[p.second.first][i].second){ dijkstrapq.push({p.first+graph[p.second.first][i].second, {graph[p.second.first][i].first, p.second.first}}); } } } /*for (int i=1;i<=n;i++){ for (int j=0;j<graph[i].size();j++){ cout<<graph[i][j].first<<" "<<(states[i][j]==DIJKSTRA?"DIJKSTRA ":""); } cout<<'\n'; }*/ queue<int> bfsq; bfsq.push(t); while (!bfsq.empty()){ int ve=bfsq.front(); bfsq.pop(); for (int i=0;i<graph[ve].size();i++){ if (states[ve][i]!=DIJKSTRA) continue; states[ve][i]=DONE; for (int j=0;j<graph[graph[ve][i].first].size();j++){ if (graph[graph[ve][i].first][j].first==ve){ states[graph[ve][i].first][j]=DONE; } } bfsq.push(graph[ve][i].first); } } /*for (int i=1;i<=n;i++){ for (int j=0;j<graph[i].size();j++){ cout<<graph[i][j].first<<" "<<(states[i][j]==DONE?"DONE ":""); } cout<<'\n'; }*/ for (int i=0;i<times.size();i++) times[i]=0; while (!dijkstrapq.empty()) dijkstrapq.pop(); dijkstrapq.push({0, {v, 0}}); while (!dijkstrapq.empty()){ pair<int, pair<int, int>> p=dijkstrapq.top(); dijkstrapq.pop(); times[p.second.first]=1; for (int i=0;i<graph[p.second.first].size();i++){ if (states[p.second.first][i]==DONE){ cout<<p.first<<'\n'; return 0; } if (times[graph[p.second.first][i].first]==0){ dijkstrapq.push({p.first+graph[p.second.first][i].second, {graph[p.second.first][i].first, 0}}); } } } return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i=0;i<graph[p.second.first].size();i++){
      |                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int i=0;i<graph[p.second.first].size();i++){
      |                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i=0;i<graph[ve].size();i++){
      |                      ~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for (int j=0;j<graph[graph[ve][i].first].size();j++){
      |                          ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for (int i=0;i<times.size();i++) times[i]=0;
      |                  ~^~~~~~~~~~~~~
commuter_pass.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for (int i=0;i<graph[p.second.first].size();i++){
      |                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...