제출 #884530

#제출 시각아이디문제언어결과실행 시간메모리
884530ReLiceCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
289 ms33032 KiB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag=false;
    if(x>y){
        x=y;flag|=true;
    }
    return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
vector<vector<pair<ll,ll>>> g(N),g2(N);
ll i,j,n,m,u,v,s,t;
ll d[N];
bool f[N];
void bfs(ll st){
	set<pair<ll,ll>> q;
	for(i=1;i<=n;i++)d[i]=inf;
	d[st]=0;
	q.ins({d[st],st});
	while(q.sz){
		ll x=q.begin()->sc;
		q.erase(q.begin());
		for(auto i : g[x]){
			if(d[i.fr]>d[x]+i.sc){
				d[i.fr]=d[x]+i.sc;
				q.ins({d[i.fr],i.fr});
			}
		}
	}
}
void ba(ll st){
	queue<ll> q;
	q.push(st);
	f[st]=true;
	while(q.sz){
		ll x=q.front();
		q.pop();
		for(auto i : g[x]){
			if(d[i.fr]==d[x]-i.sc && !f[i.fr]){
				g2[i.fr].pb({x,i.sc});
				f[i.fr]=true;
				q.push(i.fr);
			}
		}
	}
}
ll dp[N][2];
void solve(){
	cin>>n>>m;
	cin>>s>>t;
	cin>>u>>v;
	ll a,b,c;
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		g[a].pb({b,c});
		g[b].pb({a,c});
	}
	bfs(s);
	ba(t);
	bfs(u);
	set<pair<ll,ll>> q;
	for(i=1;i<=n;i++)dp[i][0]=dp[i][1]=inf;
	dp[s][0]=d[s];
	q.ins({dp[s][0],s});
	while(q.sz){
		ll x=q.begin()->sc;
		q.erase(q.begin());
		for(auto i : g2[x]){
			if(dp[i.fr][0]>min(dp[x][0],d[i.fr])){
				dp[i.fr][0]=min(dp[x][0],d[i.fr]);
				q.ins({dp[i.fr][0],i.fr});
			}
		}
	}
	bfs(v);
	dp[s][1]=d[s];
	q.ins({dp[s][1],s});
	while(q.sz){
		ll x=q.begin()->sc;
		q.erase(q.begin());
		for(auto i : g2[x]){
			if(dp[i.fr][1]>min(dp[x][1],d[i.fr])){
				dp[i.fr][1]=min(dp[x][1],d[i.fr]);
				q.ins({dp[i.fr][1],i.fr});
			}
		}
	}
	ll ans=inf;
	for(i=1;i<=n;i++)ans=min(ans,dp[i][0]+dp[i][1]);
	cout<<ans<<endl;
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*








*/

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'void fre(std::string)':
commuter_pass.cpp:41:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:41:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"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...