Submission #1182693

#TimeUsernameProblemLanguageResultExecution timeMemory
1182693Zbyszek99Olympic Bus (JOI20_ho_t4)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define vl vector<long long> #define vi vector<int> #define pii pair<int,int> #define pll pair<long long, long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace std; //mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll rand(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; pii edge[50001]; ll cost[50001]; ll swap_cost[50001]; vector<pii> dij_graph[201]; ll ans = 1e18; ll dist[50001][6]; pii nxt[50001]; int n,m; void dij(int start, int type) { vi mam; mam.pb(start); vi nie_mam; rep2(i,1,n) if(i != start) nie_mam.pb(i); rep2(i,1,n) dist[i][type] = 1e18; rep2(i,1,n) nxt[i] = 0; dist[start][type] = 0; rep(i,n-1) { // cout << i << " " << start << " " << type << " " << siz(mam) << " iter\n"; pair<pll,pii> best = {{1e18,1},{1,1}}; forall(it,mam) { // cout << it << " mam\n"; forall(e,dij_graph[it]) { // cout << e.ff << " " << e.ss << " edges\n"; if(dist[e.ff][type] != 1e18) continue; best = min(best,{{dist[it][type] + cost[e.ss],it},{e.ff,e.ss}}); } } // cout << best.ff.ff << " " << best.ff.ss << " " << best.ss.ff << " " << best.ss.ss << " best\n"; if(best.ff.ff == 1e18) break; dist[best.ss.ff][type] = best.ff.ff; nxt[best.ss.ff] = {best.ff.ss,best.ss.ss}; mam.pb(best.ss.ff); rep(i,siz(nie_mam)) { if(nie_mam[i] == best.ss.ff) { swap(nie_mam[i],nie_mam[siz(nie_mam)-1]); nie_mam.pop_back(); break; } } } } void solve(int s, int t) { rep2(i,1,n) dij_graph[i] = {}; rep(i,m) { dij_graph[edge[i].ss].pb({edge[i].ff,i}); } dij(t,1); dij(s,5); rep2(i,1,n) dij_graph[i] = {}; rep(i,m) { dij_graph[edge[i].ff].pb({edge[i].ss,i}); } dij(s,0); dij(t,4); ans = min(ans,dist[s][4] + dist[t][0]); vi path; set<int> path_set; int cur = s; while(cur != t && cur != 0) { path.pb(nxt[cur].ss); path_set.insert(nxt[cur].ss); cur = nxt[cur].ff; } //forall(it,path) cout << it << " path\n"; //cout << "\n"; rep(i,m) { if(path_set.find(i) == path_set.end()) { ans = min(ans,swap_cost[i] + dist[edge[i].ss][0] + dist[edge[i].ff][1] + cost[i] + min(dist[s][4],dist[edge[i].ss][4] + cost[i] + dist[edge[i].ff][5])); // cout << i << " " << edge[i].ff << " " << edge[i].ss << " " << ans << " " << dist[edge[i].ss][0] << " " << dist[edge[i].ff][1] << " " << cost[i] << " " << min(dist[s][4],dist[edge[i].ss][1] + cost[i] + dist[edge[i].ff][0])<< " not_path_edge\n"; } else { swap(edge[i].ff,edge[i].ss); rep2(j,1,n) dij_graph[j] = {}; rep(j,m) { dij_graph[edge[i].ff].pb({edge[i].ss,i}); } dij(s,2); rep2(j,1,n) dij_graph[j] = {}; rep(j,m) { dij_graph[edge[i].ff].pb({edge[i].ss,i}); } dij(t,3); swap(edge[i].ff,edge[i].ss); ans = min(ans,dist[t][2] + dist[s][3] + swap_cost[i]); // cout << i << " " << ans << " path_edge\n"; } } //cout << "\n\n"; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random(); cin >> n >> m; rep(i,m) { int a,b; cin >> a >> b >> cost[i] >> swap_cost[i]; edge[i] = {a,b}; } solve(1,n); solve(n,1); if(ans != 1e18) { cout << ans << "\n"; } else cout << "-1\n"; }

Compilation message (stderr)

ho_t4.cpp: In function 'void dij(int, int)':
ho_t4.cpp:41:26: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and 'int')
   41 |     rep2(i,1,n) nxt[i] = 0;
      |                          ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from ho_t4.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:418:9: note: candidate: 'template<class _U1, class _U2> constexpr typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  418 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:418:9: note:   template argument deduction/substitution failed:
ho_t4.cpp:41:26: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   41 |     rep2(i,1,n) nxt[i] = 0;
      |                          ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from ho_t4.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:430:9: note: candidate: 'template<class _U1, class _U2> constexpr typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]'
  430 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:430:9: note:   template argument deduction/substitution failed:
ho_t4.cpp:41:26: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   41 |     rep2(i,1,n) nxt[i] = 0;
      |                          ^
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from ho_t4.cpp:1:
/usr/include/c++/11/bits/stl_pair.h:390:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<int, int>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:393:55: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, const std::pair<int, int>&, const std::__nonesuch&>::type' {aka 'const std::pair<int, int>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~                  
  391 |                 __and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |                        is_copy_assignable<_T2>>::value,
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |                 const pair&, const __nonesuch&>::type __p)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_pair.h:401:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = int; _T2 = int; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<int, int>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_pair.h:404:45: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, std::pair<int, int>&&, std::__nonesuch&&>::type' {aka 'std::pair<int, int>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~        
  402 |                 __and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |                        is_move_assignable<_T2>>::value,
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |                 pair&&, __nonesuch&&>::type __p)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~