Submission #683439

#TimeUsernameProblemLanguageResultExecution timeMemory
683439Paul_Liao_1457Olympic Bus (JOI20_ho_t4)C++17
5 / 100
83 ms1876 KiB
//記得跳題 #include<iostream> #include<array> #include<vector> #include<string> #include<algorithm> #include<set> #include<queue> #include<stack> #include<math.h> #include<map> #include<unordered_map> #include<cstring> #include<iomanip> #include<bitset> #include<tuple> #define ll long long #define LL __int128_t #define DB double #define FOR(i,a,b) for(int i=a;i<b;i++) #define REP(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define mp make_pair #define INF (ll)(4e18) #define MOD (ll)(1e9+7) #define F first #define S second #define endl "\n" #define AC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; template<class T> using PQ=priority_queue<T,vector<T>,greater<T> >; void file(){ freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin); freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout); } int s[200005],seg[800005]; void build(int id,int l,int r){ if(l==r){ seg[id]=s[l]; return; } int mid=(l+r)>>1; build(id*2,l,mid); build(id*2+1,mid+1,r); seg[id]=max(seg[id*2],seg[id*2+1]); } int ask(int id,int l,int r,int L,int R){ if(l>R||r<L) return 0; if(L<=l&&r<=R) return seg[id]; int mid=(l+r)>>1; return max(ask(id*2,l,mid,L,R),ask(id*2+1,mid+1,r,L,R)); } vector<pair<int,int> > e[205]; int c[50005],d[50005],a[50005],b[50005]; ll vis[2][205]; signed main(){ AC; int n,m; cin>>n>>m; FOR(i,0,m){ cin>>a[i]>>b[i]>>c[i]>>d[i]; e[a[i]].pb({b[i],i}); e[b[i]].pb({a[i],i+m}); c[i+m]=c[i]; } FOR(j,1,n+1) vis[0][j]=vis[1][j]=INF; ll ans=INF; PQ<pair<ll,int> > Q; Q.push({0,1}); vis[0][1]=0; while(Q.size()){ auto now=Q.top(); Q.pop(); for(auto k:e[now.S])if(vis[0][k.F]>now.F+c[k.S]&&k.S<m){ vis[0][k.F]=now.F+c[k.S]; Q.push({now.F+c[k.S],k.F}); } } Q.push({0,n}); vis[1][n]=0; while(Q.size()){ auto now=Q.top(); Q.pop(); for(auto k:e[now.S])if(vis[1][k.F]>now.F+c[k.S]&&k.S<m){ vis[1][k.F]=now.F+c[k.S]; Q.push({now.F+c[k.S],k.F}); } } if(vis[0][n]!=INF&&vis[1][1]!=INF){ ans=min(ans,vis[0][n]+vis[1][1]); } //cout<<"ans="<<ans<<endl; FOR(i,0,m){ FOR(j,1,n+1) vis[0][j]=vis[1][j]=INF; Q.push({0,1}); vis[0][1]=0; while(Q.size()){ auto now=Q.top(); Q.pop(); for(auto k:e[now.S])if(vis[0][k.F]>now.F+c[k.S]&&k.S!=i&&(k.S<m||k.S==i+m)){ vis[0][k.F]=now.F+c[k.S]; Q.push({now.F+c[k.S],k.F}); } } Q.push({0,n}); vis[1][n]=0; while(Q.size()){ auto now=Q.top(); Q.pop(); for(auto k:e[now.S])if(vis[1][k.F]>now.F+c[k.S]&&k.S!=i&&(k.S<m||k.S==i+m)){ vis[1][k.F]=now.F+c[k.S]; Q.push({now.F+c[k.S],k.F}); } } if(vis[0][n]!=INF&&vis[1][1]!=INF){ ans=min(ans,d[i]+vis[0][n]+vis[1][1]); } //cout<<"ans="<<ans<<endl; } if(ans==INF) cout<<-1<<endl; else cout<<ans<<endl; } /* */

Compilation message (stderr)

ho_t4.cpp: In function 'void file()':
ho_t4.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...