Submission #513285

#TimeUsernameProblemLanguageResultExecution timeMemory
513285vinnipuh01Commuter Pass (JOI18_commuter_pass)C++17
15 / 100
775 ms54640 KiB
#include <iostream> #include <bits/stdc++.h> #include <cmath> #include <algorithm> #include <vector> #include <deque> #include <set> #include <stack> #include <string> #include <map> #include <queue> #define int long long using namespace std; const long long oo = 1000000000000000000; long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos; /* ViHHiPuh (( `'-""``""-'` )) )-__-_.._-__-( / --- (o _ o) --- \ \ .-* ( .0. ) *-. / _'-. ,_ '=' _, .-'_ / `;#'#'# - #'#'#;` \ \_)) -----'#'----- ((_/ # --------- # '# ------- ------ #' /..-'# ------- #'-.\ _\...-\'# -- #'/-.../_ ((____)- '#' -(____)) cout << fixed << setprecision(6) << x; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen ( "sum.in", "r", stdin ) */ vector <pair<int, int> > v[ 100001 ], vv[ 100001 ]; set <pair<int, int> > st; int d[ 100001 ], p[ 100001 ], dd[ 100001 ]; map <pair<int, int>, bool> mp; main () { int n, m; cin >> n >> m; int s, t; cin >> s >> t; int ss, tt; cin >> ss >> tt; int x[ m + 1 ], y[ m + 1 ], z[ m + 1 ]; for ( int i = 1; i <= n; i ++ ) d[ i ] = oo; for ( int i = 1; i <= m; i ++ ) { cin >> x[ i ] >> y[ i ] >> z[ i ]; v[ x[ i ] ].push_back( { y[ i ], z[ i ] } ); v[ y[ i ] ].push_back( { x[ i ], z[ i ] } ); } d[ s ] = 0; st.insert( { d[ s ], s } ); p[ s ] = -1; while ( st.size() ) { num = st.begin()->second; st.erase( st.begin() ); for ( auto to : v[ num ] ) { if ( d[ to.first ] > to.second + d[ num ] ) { st.erase( { d[ to.first ], to.first } ); d[ to.first ] = d[ num ] + to.second; p[ to.first ] = num; st.insert( { d[ to.first ], to.first } ); } } } for ( int i = t; i != s; i = p[ i ] ) { mp[ { i, p[ i ] } ] = mp[ { p[ i ], i } ] = 1; } for ( int i = 1; i <= m; i ++ ) { if ( mp[ { x[ i ], y[ i ] } ] ) { // cout << x[ i ] << " " << y[ i ] << "\n"; z[ i ] = 0; } vv[ x[ i ] ].push_back( { y[ i ], z[ i ] } ); vv[ y[ i ] ].push_back( { x[ i ], z[ i ] } ); } for ( int i = 1; i <= n; i ++ ) dd[ i ] = oo; dd[ ss ] = 0; st.insert( { dd[ ss ], ss } ); while ( st.size() ) { num = st.begin()->second; st.erase( st.begin() ); for ( auto to : vv[ num ] ) { if ( dd[ to.first ] > to.second + dd[ num ] ) { st.erase( { dd[ to.first ], to.first } ); dd[ to.first ] = to.second + dd[ num ]; st.insert( { dd[ to.first ], to.first } ); } } } cout << dd[ tt ]; }

Compilation message (stderr)

commuter_pass.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...