# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1264845 | namhh | Robot (JOI21_ho_t4) | C++20 | 94 ms | 23092 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e5+5;
int n,m,d[N],rem[N],sum[N],check[N];
struct edges{
int v,p,w;
};
vector<edges>adj[N];
void dijkstra(){
for(int i = 2; i <= n; i++) d[i] = 1e18;
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({0,1});
while(!pq.empty()){
auto[c,u] = pq.top();
pq.pop();
if(c > d[u] || check[u]) continue;
check[u] = 1;
for(auto[v,p,w]: adj[u]){
sum[p] = 0;
rem[p] = 1e18;
}
for(auto[v,p,w]: adj[u]) sum[p] += w;
for(auto[v,p,w]: adj[u]) rem[p] = min(rem[p],d[v]+sum[p]);
for(auto[v,p,w]: adj[u]){
if(d[v] > min({d[u]+w,d[u]+sum[p]-w,rem[p]-w})){
d[v] = min({d[u]+w,d[u]+sum[p]-w,rem[p]-w});
pq.push({d[v],v});
}
}
}
if(d[n] > 1e17) cout << -1;
else cout << d[n];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= m; i++){
int u,v,c,p;
cin >> u >> v >> c >> p;
adj[u].push_back({v,c,p});
adj[v].push_back({u,c,p});
}
dijkstra();
}
//
// +.::=. .*: -.
// -- :. = -:--
// .= .. .-=++*+++=:. = :
// .= ....:=%@@@@@*: . :.
// .-+=..: :. .+##%##+. .: .+:
// :*@**%* .. :. ::..:.:. --:
// .--. +@@@@@%: .==: .###@*
// :-- -: -:@@@@# - =@@@@#. .= : +
// .: -=--==: == +- :*%*++= .:#
// -. .:. . +. -*. =@@. .-. .=
// +=.. .. -- .* .#. +@# - :==*=
// .=.+=:::: =. =- ##@+ :--+.#@%++%*
// .++@@: = + .%%%%@@@@@@@@@@@@@@%. :-@#-: -@.
// :@@@@= .+ .= *# .#@.=- =@::-:@:
// :-@@%. -- -- :@*. .%# +. - ** :=%. .*@#
// :-. .-*-. -: +. %-=::@# .* : - :%- +%.+@+@@
// .- :. **: +: = # : =* =@# -= # #@@@:-@ :*@@. %@
// -=: :: .* .= + # =..@ .*. +. *. *#=.+%@*-%* %@
// :=. :.. .: +. -= .+ # -- #. =- .+ +: =@+ .+-++ @%
// ++-=. * -- := # :- +- :* =:+: -@# :@#*%@@@%@+
// *. -- -- := # .= #@#=. +- :=+: :%@-#@@@#@+:@@#
// + +. -- := # .= := .+. +*. *@@+=@-=@*-.#@.
// = + := .+ # = .= .#.-@. -+ .%# -@@= @#
// .= .= .+ + *. = .+.. :*@ == =@. -#@#: @%
// .= .= * + =: .=.**: =--: # * *- %* =*=@+#@:
// .= := # =. .+ . .= --.#@@@@@#@@@: * -= #..@= **:@@@:
// + .= +: -- + # := +@%:@#: -:%= === #..* .#@@%@+.@@+
// * .= .* .= -:-= :- #= ++ =- =@. *: .* -*: : . .@@%//
// -: =: := .* +.-- =:-- .*.:.: # .= + *+ - :@%@=
// + * *:+. == .+ +. +.# .=-:=- -- -- =+: = -@#%*
// + -= *== *. -=-- :+-= ::: =: + %:. = %@+##
// .= +: +*- + +:+. +:*. .+ +: #.:. - .+ -@@=#%
// -. =. :=#- := =:* .-==#+- +: =- +:-..- :%* =@@:*%
// .- +. --+= .**%+-:. -* +-:*:.:. =@@* :-@@ *%
// -. += -+== -*#- =- .. .%@#@=.--@* *%
// =. .+: :+-*-=+: +%+*@@%%@-= +@- *#
// -::= :**=: :@@@@@@%@@- #@ #*
// -: +: - .@@#%@@%@@: :@# .#+
// :- :#= -- :@@@#@-=@#. =@- .%=
// =:.@@%= =# .+.=. +@@@@* -*: #% :@:
// .+ *@@@@@@@@* :@@*@@@* .@+ -@.
// .+=%@*%@@@@@#: =@@@%:.: +@: +%
// .=%@%#@@@@##@*: =%@@@#: @# ##
// :#@%@@@@#@@@@+ :*. @: =@- .@+
// .+@%#%@@:=-.. .=: %*==+. @% -@-
// =. =: :-:.:: .-- .= -: =@- -
// .- :-. :: .- =-:
// .=+-.=-.*- = -..+*: .-:.- = .+*# ....
// =. -= -: .. -. +. -. +. -+ -*=: +.
// .- +- * -.* #+ .+ =. :=
// :- --=*: -+ *= -# - -##+-.. .:+#: +.
// :- = --=:==+*. =: .: .= =**= = .+
// .= + =-- :- .=. -- .- =
// = .- --: .-+*@%*# +. + :-
// + +- -:- :*@@@@@@*@#*@@%*=: =: - -.
// .* - ::+ =@@@@#-.-@@%%@@+=%@@@%= -:: = :-
// .+ :. +-. #@@@= +@@@-#@@%. +@@@+ .:= .- +:
// .--. -. :=- :@@+ :@@@@# =@@@# -%@# -= :: :-+-
// * - + --. +@@#=%@@@@@. :@@@@% :%@ := =. -=+
// .-**- -. -- .%@@@@+%@+ @@+%@@*-+@@@. :=. - :+*-
// :===-==. .-= *@% *@= +%%##=. :=: :. .::-==-.
// .::-=+=+=-:. #%: -#: .-*#+===-:.
// ..::---====---::.
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |