Submission #733511

# Submission time Handle Problem Language Result Execution time Memory
733511 2023-05-01T01:11:43 Z pcc Olympic Bus (JOI20_ho_t4) C++14
5 / 100
1000 ms 3928 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 202;
const int mxn2 = 5e4+10;
const ll inf = 1e18;
ll dist[mxn];

struct edge{
	ll from,to,val,id,cost;
	edge(){}
	edge(ll ff,ll tt,ll vv,ll cc,ll ii){
		from = ff,to = tt,val = vv,cost = cc;
		id = ii;
	}
};

vector<edge> paths[mxn];
edge edges[mxn2];
int n,m;

ll dijkstra(int s,int no){
	priority_queue<pll,vector<pll>,greater<pll>> pq;
	fill(dist,dist+mxn,inf);
	dist[s] = 0;
	pq.push({0,s});
	while(!pq.empty()){
		auto now = pq.top();
		pq.pop();
		if(now.fs != dist[now.sc])continue;
		for(auto &nxt:paths[now.sc]){
			if(nxt.id == no)continue;
			if(nxt.val+dist[now.sc]<dist[nxt.to]){
				dist[nxt.to] = nxt.val+dist[now.sc];
				pq.push({dist[nxt.to],nxt.to});
			}
		}
	}
	if(s == 1)return dist[n];
	else return dist[1];
}

void solve(){
	cin>>n>>m;
	ll ans = inf;
	if(m>1000){
		for(int i = 2;i<=m;i+=2){
			ll c;
			edges[i].id = i>>1;
			cin>>edges[i].from>>edges[i].to>>edges[i].val>>edges[i].cost;
			cin>>c>>c>>c>>c;
			edges[i].cost = min(edges[i].cost,c);
			paths[edges[i].from].push_back(edges[i]);
		}
		m>>=1;
	}
	else{
		for(int i = 1;i<=m;i++){
			ll c;
			edges[i].id = i;
			cin>>edges[i].from>>edges[i].to>>edges[i].val>>edges[i].cost;
			paths[edges[i].from].push_back(edges[i]);
		}
	}
	ans = dijkstra(1,0)+dijkstra(n,0);
	for(int i = 1;i<=m;i++){
		paths[edges[i].to].push_back(edge(edges[i].to,edges[i].from,edges[i].val,edges[i].cost,-edges[i].id));
		ll tmp = edges[i].cost+dijkstra(1,i)+dijkstra(n,i);
		ans = min(ans,tmp);
		paths[edges[i].to].pop_back();
	}
	cout<<(ans>=inf?-1:ans)<<'\n';
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	while(t--)solve();
}

Compilation message

ho_t4.cpp: In function 'void solve()':
ho_t4.cpp:65:7: warning: unused variable 'c' [-Wunused-variable]
   65 |    ll c;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 25 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 40 ms 452 KB Output is correct
4 Correct 46 ms 452 KB Output is correct
5 Correct 17 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 66 ms 440 KB Output is correct
11 Correct 60 ms 340 KB Output is correct
12 Correct 74 ms 436 KB Output is correct
13 Correct 20 ms 340 KB Output is correct
14 Correct 28 ms 444 KB Output is correct
15 Correct 23 ms 456 KB Output is correct
16 Correct 27 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 3928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 456 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Execution timed out 1077 ms 2900 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 40 ms 452 KB Output is correct
4 Correct 46 ms 452 KB Output is correct
5 Correct 17 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 66 ms 440 KB Output is correct
11 Correct 60 ms 340 KB Output is correct
12 Correct 74 ms 436 KB Output is correct
13 Correct 20 ms 340 KB Output is correct
14 Correct 28 ms 444 KB Output is correct
15 Correct 23 ms 456 KB Output is correct
16 Correct 27 ms 452 KB Output is correct
17 Execution timed out 1075 ms 3928 KB Time limit exceeded
18 Halted 0 ms 0 KB -