Submission #1083879

#TimeUsernameProblemLanguageResultExecution timeMemory
1083879kokoueEvacuation plan (IZhO18_plan)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int n,m,k,q; bool is_npp[100001]; vector<pair<int,int>> edges[100001]; vector<long long> sp(100001,INT_MAX); vector<int> npp; map<pair<int,int>,bool> is; void dijkstra() { priority_queue<pair<long long,int>> q; vector<long long> dist(n+1,INT_MAX); for(int i=0;i<npp.size();i++) { q.push({0,npp[i]}); dist[npp[i]]=0; sp[npp[i]]=0; } while(!q.empty()) { int curr=q.top().second; long long currDist=-q.top().first; q.pop(); if(dist[curr]<currDist) continue; for(auto edge:edges[curr]) { int next=edge.first; int weight=edge.second; if(dist[curr]+weight<dist[next]) { dist[next]=dist[curr]+weight; sp[next]=min(sp[next],dist[next]); q.push({-dist[next],next}); } } } } int dijkstra(int start,int finish) { priority_queue<pair<long long,int>> q; vector<long long> away(n+1,0); q.push({sp[start],start}); away[start]=sp[start]; while(!q.empty()) { int curr=q.top().second; long long currAway=q.top().first; q.pop(); if(away[curr]>currAway) continue; for(auto edge:edges[curr]) { int next=edge.first; long long len=sp[next]; if(away[next]<min(len,away[curr])) { away[next]=min(len,away[curr]); q.push({away[next],next}); } } } return away[finish]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m; int ai,bi,wi; for(int i=0;i<m;i++) { cin>>ai>>bi>>wi; if(a>b) swap(a,b); is[ai][bi]=1; edges[ai].push_back({bi,wi}); edges[bi].push_back({ai,wi}); } cin>>k; for(int i=0;i<k;i++) { int npp1; cin>>npp1; is_npp[npp1]=true; npp.push_back(npp1); } dijkstra(); cin>>q; int si,ti; for(int i=0;i<q;i++) { cin>>si>>ti; if(is_npp[si]==true || is_npp[ti]==true) {printf("0\n");continue;} if(si>ti) swap(si,ti); if(is[{si,ti}]) {printf("%lld\n",min(sp[si],sp[ti]));continue;} printf("%lld\n",dijkstra(si,ti)); } }

Compilation message (stderr)

plan.cpp: In function 'void dijkstra()':
plan.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<npp.size();i++)
      |                 ~^~~~~~~~~~~
plan.cpp: In function 'int main()':
plan.cpp:72:11: error: 'a' was not declared in this scope
   72 |        if(a>b) swap(a,b);
      |           ^
plan.cpp:72:13: error: 'b' was not declared in this scope
   72 |        if(a>b) swap(a,b);
      |             ^
plan.cpp:73:10: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, bool>' and 'int')
   73 |        is[ai][bi]=1;
      |          ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from plan.cpp:1:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = bool; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, bool> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = bool; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from 'int' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::pair<int, int>; _Tp = bool; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, bool> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = bool; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from 'int' to 'std::map<std::pair<int, int>, bool>::key_type&&' {aka 'std::pair<int, int>&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
plan.cpp:94:20: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   94 |         printf("%lld\n",dijkstra(si,ti));
      |                 ~~~^    ~~~~~~~~~~~~~~~
      |                    |            |
      |                    |            int
      |                    long long int
      |                 %d