QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#255613#5540. City Hallsentheta#TL 1ms7192kbC++202.0kb2023-11-18 16:28:292023-11-18 16:28:30

Judging History

你现在查看的是最新测评结果

  • [2023-11-18 16:28:30]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7192kb
  • [2023-11-18 16:28:29]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define pb emplace_back
#define rep(i,a,b) for(int i=a; i < b; ++i)
#define owo ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define cerr if(1) cout
#define dbg(x) cerr << "?" << #x << " : " << x << endl;

void solve();
signed main(){
	owo
	int t = 1; //cin >> t
	while(t--) solve();
}

double dist[100005][2];
vector<int> adj[100005];

void solve(){
	int n, m, s, t; cin >> n >> m >> s >> t;
	vector<int> H(n + 1);
	for(int i = 1; i <= n; ++i){
		cin >> H[i];
		dist[i][0] = dist[i][1] = 1e18;
	}
	dist[s][0] = dist[s][1] = 0;
	for(int i = 1; i <= m; ++i){
		int u, v; cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	priority_queue<pair<double ,pii>, vector<pair<double, pii>>, greater<pair<double, pii>>> pq;
	pq.push(make_pair(0, pii(s, 0)));
	while(pq.size()){
		auto [d, P] = pq.top();
		pq.pop();
		auto [u, p] = P;
		if(u < 0 && d > dist[-u][1]) continue;
		if(u < 0 && d <= dist[-u][1]){
			for(auto v:adj[-u]){
				double w = H[-u] - H[v];
				w *= w;
				if(w + d < dist[v][1]){
					dist[v][1] = w + d;
					pq.push(make_pair(dist[v][1], pii(-v, u)));
				}
			}
			continue;
		}
		double tw = (H[u] - H[p]);
		tw *= tw;
		if(d <= dist[u][0]){
			for(auto v:adj[u]){
				double w = H[u] - H[v];
				w *= w;
				if(w + d < dist[v][0]){
					dist[v][0] = w + d;
					dist[v][1] = min(dist[v][1], w + d);
					pq.push(make_pair(dist[v][0], pii(v, u)));
				}
			}
		}
		if(d - tw <= dist[p][0]){
			for(auto v:adj[u]){
				double w = (H[p] - H[v]);
				w *= w;
				w /= 2.0;
				double w2 = H[u] - H[v];
				w2 *= w2;
				double nd = min(dist[u][0], min(w, w2) + dist[p][0]);
				if(dist[u][1] + w2 <= nd){
					dist[v][1] = dist[u][1] + w2;
					continue;
				}
				if(nd < dist[v][1]){	
					dist[v][1] = nd;
					pq.push(make_pair(dist[v][1], pii(-v, u)));
				}
			}
		}
	}
	cout << fixed << setprecision(6) << dist[t][1] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6644kb

input:

5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5

output:

4.500000

result:

ok found '4.5000000', expected '4.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7192kb

input:

5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5

output:

3.000000

result:

ok found '3.0000000', expected '3.0000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 6256kb

input:

5 4 1 4
8 8 8 8 100
1 2
2 3
3 4
4 5

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 6140kb

input:

2 1 1 2
0 100000
1 2

output:

0.000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: -100
Time Limit Exceeded

input:

632 199396 167 549
22513 93521 41403 35441 97617 53210 62622 4751 81863 14470 2994 93092 40432 30872 34423 36577 92540 92961 4110 14691 83321 10680 89112 80890 31108 24492 8973 42636 33792 27400 82361 85003 68940 31221 48625 276 52755 6649 34381 54399 6063 22628 17715 54052 58175 86609 82622 29917 9...

output:


result: