Submission #565623

#TimeUsernameProblemLanguageResultExecution timeMemory
565623almothana05Evacuation plan (IZhO18_plan)C++14
54 / 100
409 ms31724 KiB
#include<bits/stdc++.h> #define mod 1000000007 ////////////////////////////////////////////////////////// #define inf 100000000000000000 using namespace std; vector<pair<int , int > >gr[300000]; priority_queue<pair<int , int> >q; vector<int>best[300000]; int dis[300000]; int menge , numm , nummer , que , ed , npp; void bfs(){ while(q.size()){ int jet = q.top().second , cmp = -q.top().first; q.pop(); for(int i = 0 ; i < gr[jet].size() ; i++){ if(cmp + gr[jet][i].second < dis[gr[jet][i].first]){ dis[gr[jet][i].first] = cmp + gr[jet][i].second; q.push({-dis[gr[jet][i].first] , gr[jet][i].first}); } } } } void dij(int x){ for(int i = 0 ; i <= menge ; i++){ best[x].push_back(0); } best[x][x] = dis[x]; q.push({best[x][x] , x}); while(q.size()){ int jet = q.top().second , cmp = q.top().first; q.pop(); for(int i = 0 ; i < gr[jet].size() ; i++){ if(min(cmp , dis[gr[jet][i].first]) > best[x][gr[jet][i].first]){ best[x][gr[jet][i].first] = min(cmp , dis[gr[jet][i].first]); q.push({best[x][gr[jet][i].first] , gr[jet][i].first}); } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); for(int i = 0 ; i < 300000 ; i++){ dis[i] = mod; } cin >> menge >> ed; for(int i = 0 ; i < ed ; i++){ cin >> numm >> nummer >> que; gr[numm].push_back({nummer , que}); gr[nummer].push_back({numm , que}); } cin >> npp; for(int i = 0 ; i < npp ; i++){ cin >> numm; dis[numm] = 0; q.push({0 , numm}); } bfs(); for(int i = 1 ; i <= menge ; i++){ // cout << dis[i] << ' '; } cin >> que; if(que == 1){ cin >> numm >> nummer; dij(numm); cout << best[numm][nummer] << "\n"; return 0; } if(menge < 20){ for(int i = 1; i <= menge ; i++){ dij(i); // for(int j = 1 ; j <= menge ; j++){ // cout << best[i][j] << " "; // } // cout << "\n"; } while(que--){ cin >> numm >> nummer; cout << best[numm][nummer] << " "; } return 0; } while(que--){ cin >> numm >> nummer; cout << min(dis[numm] , dis[nummer]) << "\n"; } }

Compilation message (stderr)

plan.cpp: In function 'void bfs()':
plan.cpp:15:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |       for(int i = 0 ; i < gr[jet].size() ; i++){
      |                       ~~^~~~~~~~~~~~~~~~
plan.cpp: In function 'void dij(int)':
plan.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |       for(int i = 0 ; i < gr[jet].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...
#Verdict Execution timeMemoryGrader output
Fetching results...