Submission #248630

#TimeUsernameProblemLanguageResultExecution timeMemory
248630tleontest1Olympic Bus (JOI20_ho_t4)C++17
0 / 100
584 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; typedef pair< lo,PII > PIII; typedef pair< lo,PIII > PIIII; typedef pair< lo,PIIII > PIIIII; typedef pair< lo,PIIIII > PIIIIII; #define fi first #define se second #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) #define int long long const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 205; const lo mod = 1000000007; int n,m,k,flag,t,vis[li][50005],vis1[li][50005],yasak,mn,ans1,ans2,cev,x,y,z,dp[50005],dp1[50005],d[50005]; string s; vector<PIIII> v[li]; //~ inline void sp2(){ //~ priority_queue<PIIIII> pq; //~ pq.push({0,{n,{0,{0,0}}}}); //~ FOR vis[i][0]=0; //~ FOR vis[i][1]=0; //~ mn=inf; //~ while(pq.size()){ //~ int co=-pq.top().fi; //~ int node=pq.top().se.fi; //~ int hak=pq.top().se.se.fi; //~ int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se; //~ pq.pop(); //~ if(vis[node][hak])continue; //~ vis[node][hak]=1; //~ if(node==1)mn=min(mn,co); //~ for(int i=0;i<(int)v[node].size();i++){ //~ int go=v[node][i].fi; //~ if(node==xx && go==yy)continue; //~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}}); //~ else{ //~ if(hak)continue; //~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}}); //~ } //~ } //~ } //~ } //~ inline void sp3(int xxx,int yyy){ //~ priority_queue<PIIIII> pq; //~ pq.push({0,{n,{1,{xxx,yyy}}}}); //~ FOR vis[i][0]=0; //~ FOR vis[i][1]=0; //~ mn=inf; //~ while(pq.size()){ //~ int co=-pq.top().fi; //~ int node=pq.top().se.fi; //~ int hak=pq.top().se.se.fi; //~ int xx=pq.top().se.se.se.fi; //~ int yy=pq.top().se.se.se.se; //~ pq.pop(); //~ if(vis[node][hak])continue; //~ vis[node][hak]=1; //~ if(node==1)mn=min(mn,co); //~ cout<<xx<<" : : "<<yy<<endl; //~ for(int i=0;i<(int)v[node].size();i++){ //~ int go=v[node][i].fi; //~ if(node==xx && go==yy)continue; //~ if(v[node][i].se.se==0)pq.push({-co-v[node][i].se.fi,{go,{hak,{xx,yy}}}}); //~ else{ //~ if(hak)continue; //~ pq.push({-co-v[node][i].se.fi,{go,{1,{go,node}}}}); //~ } //~ } //~ } //~ } inline void sp(){ priority_queue<PIII> pq; for(int i=0;i<=m;i++) pq.push({d[i],{1,i}}); //~ FOR vis[i]=0; while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int ban=pq.top().se.se; pq.pop(); if(vis[node][ban])continue; //~ cout<<node<<" : ; "<<ban<<endl; vis[node][ban]=1; if(node==n)dp[ban]=co; for(int i=0;i<(int)v[node].size();i++){ //~ if(v[node][i].se.se.se==yasak && v[node][i].se.se.fi==0)continue; //~ if(v[node][i].se.se.se!=yasak && v[node][i].se.se.fi==1)continue; if(ban!=v[node][i].se.se.se && v[node][i].se.se.fi==1)continue; if(ban==v[node][i].se.se.se && v[node][i].se.se.fi==0)continue; pq.push({-co-v[node][i].se.fi,{v[node][i].fi,ban}}); } } } inline void sp1(){ priority_queue<PIII> pq; for(int i=0;i<=m;i++) pq.push({d[i],{n,i}}); //~ FOR vis[i]=0; ans1=-1; ans2=-1; while(pq.size()){ int co=-pq.top().fi; int node=pq.top().se.fi; int ban=pq.top().se.se; pq.pop(); if(vis1[node][ban])continue; vis1[node][ban]=1; if(node==1)dp1[ban]=co; for(int i=0;i<(int)v[node].size();i++){ //~ if(v[node][i].se.se.se==yasak && v[node][i].se.se.fi==0)continue; //~ if(v[node][i].se.se.se!=yasak && v[node][i].se.se.fi==1)continue; if(ban!=v[node][i].se.se.se && v[node][i].se.se.fi==1)continue; if(ban==v[node][i].se.se.se && v[node][i].se.se.fi==0)continue; pq.push({-co-v[node][i].se.fi,{v[node][i].fi,ban}}); } } } main(void){ scanf("%lld %lld",&n,&m); for(int i=1;i<=m;i++){ //~ int z; scanf("%lld %lld %lld %lld",&x,&y,&z,&d[i]); v[x].pb({y,{z,{0,i}}}); v[y].pb({x,{z,{1,i}}}); } //~ FOR{ //~ for(int j=1;j<=n;j++)dp[i][j]=inf; //~ } for(int i=0;i<=m;i++) dp[i]=inf; for(int i=0;i<=m;i++) dp1[i]=inf; sp(); sp1(); int ans=inf; //~ cout<<dp[0]<<" : : "<<dp1[0]<<endl; //~ FOR dp[i]=min(dp[i],dp[0]); //~ FOR dp1[i]=min(dp1[i],dp1[0]); for(int i=1;i<=m;i++){ //~ cout<<dp[i]<<" : : "<<dp1[i]<<endl; ans=min(ans,dp[i]+dp1[i]); //~ ans=min(ans,dp[i]+dp1[0]); //~ ans=min(ans,dp[0]+dp1[i]); } ans=min(ans,dp[0]+dp1[0]); if(ans==inf)ans=-1; printf("%lld\n",ans); return 0; }

Compilation message (stderr)

ho_t4.cpp:139:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:140:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t4.cpp:143:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld %lld",&x,&y,&z,&d[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...