Submission #869399

#TimeUsernameProblemLanguageResultExecution timeMemory
869399vjudge1Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
314 ms34480 KiB
//In His Name #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll typedef pair<int, int> pii; typedef pair<long long, int> pli; typedef pair<long long, long long> pll; #define F first #define S second #define pb push_back #define bug(x) cout << "Ah shit , here we go again : " << x <<endl #define all(x) x.begin() , x.end() #define ceil(x,y) x/y + min(1ll,x%y) const int maxn = 2e5 + 10, MOD = 1e9 + 7; const ll INF = 1e18; int n , m , s , t , u , v , dis[maxn]; vector<pli> adj[maxn]; vector<int> par[maxn]; set<int> path; bool mark[maxn]; void dijkstra(int root){ fill(dis , dis+n+1 , INF); dis[root] = 0; set<pli> st; st.insert({0,root}); while(!st.empty()){ int a = (*st.begin()).S; st.erase(st.begin()); for(pii i : adj[a]){ if(dis[i.S] >= dis[a] + i.F){ st.erase({dis[i.S] , i.S}); dis[i.S] = dis[a] + i.F; st.insert({dis[i.S] , i.S}); par[i.S].pb(a); } } } } signed main(){ ios_base::sync_with_stdio(false); cin >> n >> m >> s >> t >> u >> v; for(int i = 1 ; i <= m ; i ++){ int a , b , w; cin >> a >> b >> w; adj[a].pb({w , b}); adj[b].pb({w , a}); } dijkstra(s); queue<int> q; q.push(t); while(!q.empty()){ if(mark[q.front()]){ q.pop(); continue; } mark[q.front()] = true; for(int i : par[q.front()]){ path.insert(i); if(!mark[i]) q.push(i); } q.pop(); } int ans = dis[v]; dijkstra(v); for(int i : path) ans = min(ans, dis[i]); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...