Submission #1326797

#TimeUsernameProblemLanguageResultExecution timeMemory
1326797Ahmed_SolymanCommuter Pass (JOI18_commuter_pass)C++20
16 / 100
358 ms24716 KiB
/* In the name of Allah made by: Ahmed_Solyman */ #include <bits/stdc++.h> #include <ext/rope> using namespace std; using namespace __gnu_cxx; #pragma GCC optimize("-Ofast") #pragma GCC optimize("-O1") //-------------------------------------------------------------// typedef long long ll; typedef unsigned long long ull; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define PI acos(-1) #define lb lower_bound #define ub upper_bound #define endl '\n' #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define sum_to(n) (n*(n+1))/2 #define pb push_back #define pf push_front #define fil(arr,x) memset(arr,x,sizeof(arr)) #define REP(i,a,b) for (int i=a;i<=b;i++) #define F first #define S second #define MP make_pair const ll mod=1e9+7; int dx[8]={0,1,0,-1,1,1,-1,-1}; int dy[8]={1,0,-1,0,1,-1,-1,1}; //-------------------------------------------------------------// ll lcm(ll a,ll b) { return (max(a,b)/__gcd(a,b))*min(a,b); } void person_bool(bool x) { cout<<(x?"YES":"NO")<<endl; } const int N=1e5+5; int n,m,s,t,u,v; vector<pair<int,int>>adj[N]; vector<ll>dijkstra(int node){ vector<ll>dist(n+1,4e18); dist[node]=0; priority_queue<pair<ll,int>>pq; pq.push({0,node}); while(pq.size()){ ll w=pq.top().first; int node=pq.top().second; pq.pop(); if(-w>dist[node])continue; for(auto i:adj[node]){ if(-w+i.second<dist[i.first]){ dist[i.first]=-w+i.second; pq.push({-dist[i.first],i.first}); } } } return dist; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); fast cin>>n>>m>>s>>t>>u>>v; for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } vector<ll>dist1=dijkstra(s); vector<ll>dist2=dijkstra(t); vector<vector<ll>>dist(n+1,vector<ll>(3,4e18)); dist[s][0]=0; dist[s][1]=0; dist[s][2]=0; priority_queue<pair<pair<ll,int>,int>>pq; pq.push({{0,s},0}); pq.push({{0,s},1}); pq.push({{0,s},2}); while(pq.size()){ ll w=-pq.top().first.first; int node=pq.top().first.second; int type=pq.top().second; pq.pop(); if(w>dist[node][type])continue; for(auto i:adj[node]){ if(type==0){ if(dist[i.first][0]>w+i.second){ dist[i.first][0]=w+i.second; pq.push({{-dist[i.first][0],i.first},0}); } if(dist[i.first][1]>w && dist1[i.first] + dist2[i.first] == dist1[t] && dist1[node] + i.second == dist1[i.first]){ dist[i.first][1]=w; pq.push({{-dist[i.first][1],i.first},1}); } } if(type==1){ if(dist[i.first][2]>w+i.second){ dist[i.first][2]=w+i.second; pq.push({{-dist[i.first][2],i.first},2}); } if(dist[i.first][1]>w && dist1[i.first] + dist2[i.first] == dist1[t] && dist1[node] + i.second == dist1[i.first]){ dist[i.first][1]=w; pq.push({{-dist[i.first][1],i.first},1}); } } if(type==2){ if(dist[i.first][2]>w+i.second){ dist[i.first][2]=w+i.second; pq.push({{-dist[i.first][2],i.first},2}); } } } } cout<<min({dist[v][0],dist[v][1],dist[v][2]})<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...