Submission #41173

#TimeUsernameProblemLanguageResultExecution timeMemory
41173IvanCCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
1073 ms31740 KiB
#include <bits/stdc++.h> #define MT make_tuple using namespace std; const int MAXN = 1e5 + 10; typedef long long ll; typedef tuple<ll,ll,ll> trinca; typedef pair<ll,ll> ii; vector<ii> grafo[MAXN]; ll N,M,processado[MAXN][8],dist[MAXN][8],ans,S,T,U,V,menorcaminho; void Dijskra(ll origem,ll idx){ priority_queue<ii, vector<ii> , greater<ii> > pq; pq.push(ii(0,origem)); while(!pq.empty()){ ll percorrido = pq.top().first, v = pq.top().second; pq.pop(); if(processado[v][idx]) continue; processado[v][idx] = 1; dist[v][idx] = percorrido; for(int i = 0;i<grafo[v].size();i++){ ll u = grafo[v][i].first, w = grafo[v][i].second; if(!processado[u][idx]) pq.push(ii(w + percorrido,u)); } } } void solve(ll origem,ll qualsoma,ll idx, ll qualminimiza, ll qualtenta ){ priority_queue<trinca, vector<trinca> , greater<trinca> > pq; pq.push(MT(0,(ll)1e18,origem)); while(!pq.empty()){ trinca davez = pq.top(); pq.pop(); ll percorrido = get<0>(davez), menor = get<1>(davez) , v = get<2>(davez); if(processado[v][idx]) continue; processado[v][idx] = 1; dist[v][idx] = percorrido; if(percorrido + dist[v][qualsoma] == menorcaminho){ ans = min(ans, menorcaminho + menor + dist[v][qualtenta] ); } menor = min(menor,dist[v][qualminimiza]); for(int i = 0;i<grafo[v].size();i++){ ll u = grafo[v][i].first, w = grafo[v][i].second; if(!processado[u][idx]) pq.push(MT(w + percorrido,menor,u)); } } } int main(){ cin.tie(0);ios_base::sync_with_stdio(0); cin >> N >> M >> S >> T >> U >> V; for(int i = 1;i<=M;i++){ ll u,v,w; cin >> u >> v >> w; grafo[u].push_back(ii(v,w)); grafo[v].push_back(ii(u,w)); } Dijskra(S,0); Dijskra(T,1); Dijskra(U,2); Dijskra(V,3); ans = dist[T][0] + dist[V][2]; menorcaminho = dist[T][0]; solve(S,1,4,2,3); solve(S,1,5,3,2); solve(T,0,6,2,3); solve(T,0,7,3,2); cout << ans - menorcaminho << endl; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void Dijskra(ll, ll)':
commuter_pass.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<grafo[v].size();i++){
                  ^
commuter_pass.cpp: In function 'void solve(ll, ll, ll, ll, ll)':
commuter_pass.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<grafo[v].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...