Submission #483988

#TimeUsernameProblemLanguageResultExecution timeMemory
483988MilosMilutinovicCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
471 ms43412 KiB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1010000;
int n,m,s,t,u,v;
ll d[4][N],dp[N],ans;
vector<PII> e[N];
void dijkstra(int u,ll* d) {
	rep(i,1,n+1) d[i]=(1LL<<59);
	set<pair<ll,int>> q;
	q.insert(mp(0,u)); d[u]=0;
	while (!q.empty()) {
		auto x=*(q.begin()); q.erase(q.begin());
		for (auto v:e[x.se]) {
			if (d[v.fi]>d[x.se]+v.se) {
				if (d[v.fi]!=(1LL<<59)) q.erase(q.find(mp(d[v.fi],v.fi)));
				d[v.fi]=d[x.se]+v.se;
				q.insert(mp(d[v.fi],v.fi));
			}
		}
	}
}
void dfs(int u,bool sd) {
	if (dp[u]!=-1) return;
	if (d[0][u]+d[1][u]!=d[0][t]) {
		dp[u]=(1LL<<59); return;
	}
	dp[u]=d[3][u];
	for (auto x:e[u]) {
		if (sd) {
			if (d[0][x.fi]==d[0][u]+x.se) {
				dfs(x.fi,sd); dp[u]=min(dp[u],dp[x.fi]);
			}
		} else {
			if (d[1][x.fi]==d[1][u]+x.se) {
				dfs(x.fi,sd); dp[u]=min(dp[u],dp[x.fi]);
			}
		}
		ans=min(ans,dp[u]+d[2][u]);
	}
}
int main() {
	scanf("%d%d%d%d%d%d",&n,&m,&s,&t,&u,&v);
	rep(i,0,m) {
		int x,y,w;
		scanf("%d%d%d",&x,&y,&w);
		e[x].pb(mp(y,w));
		e[y].pb(mp(x,w));
	}
	dijkstra(s,d[0]);
	dijkstra(t,d[1]);
	dijkstra(u,d[2]);
	dijkstra(v,d[3]);
	ans=d[2][v];
	rep(i,1,n+1) dp[i]=-1; dfs(s,1);
	rep(i,1,n+1) dp[i]=-1; dfs(t,0);
	printf("%lld",ans);
}

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:3:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define rep(i,a,n) for (int i=a;i<n;i++)
      |                    ^~~
commuter_pass.cpp:73:2: note: in expansion of macro 'rep'
   73 |  rep(i,1,n+1) dp[i]=-1; dfs(s,1);
      |  ^~~
commuter_pass.cpp:73:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |  rep(i,1,n+1) dp[i]=-1; dfs(s,1);
      |                         ^~~
commuter_pass.cpp:3:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define rep(i,a,n) for (int i=a;i<n;i++)
      |                    ^~~
commuter_pass.cpp:74:2: note: in expansion of macro 'rep'
   74 |  rep(i,1,n+1) dp[i]=-1; dfs(t,0);
      |  ^~~
commuter_pass.cpp:74:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   74 |  rep(i,1,n+1) dp[i]=-1; dfs(t,0);
      |                         ^~~
commuter_pass.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d%d%d%d%d%d",&n,&m,&s,&t,&u,&v);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%d%d%d",&x,&y,&w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...