답안 #860202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860202 2023-10-12T06:08:32 Z pcc Olympic Bus (JOI20_ho_t4) C++14
100 / 100
193 ms 2728 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


struct Edge{
	int to,cost,price;
	Edge(){}
	Edge(int tt,int cc,int pp){
		to = tt,cost = cc,price = pp;
	}
};

const ll inf = 1e18;
const int mxn = 1e5+10;
int n,m;
bitset<mxn> del,tree,vis;
vector<int> g[220],rg[220];
ll d1[220],d2[220],pid[220],d3[220],d4[220],d5[220],d6[220],d7[220],d8[220];
vector<Edge> edges;

void add_edge(int a,int b,int c,int d){
	g[a].push_back(edges.size());
	edges.push_back(Edge(b,c,d));
	rg[b].push_back(edges.size());
	edges.push_back(Edge(a,c,d));
	return;
}

void DIJKSTRA(int st,vector<int> paths[],ll dist[]){
	fill(dist,dist+220,inf);
	memset(pid,-1,sizeof(pid));
	vis.reset();
	dist[st] = 0;
	int now = st;
	for(int i = 0;i<n-1;i++){
		vis[now] = true;
		for(auto eid:paths[now]){
			int nxt = edges[eid].to;
			if(del[eid])continue;
			if(dist[nxt]>dist[now]+edges[eid].cost){
				dist[nxt] = dist[now]+edges[eid].cost;
				pid[nxt] = eid;
			}
		}
		pll tmp = {inf,-1};
		for(int j = 1;j<=n;j++){
			if(vis[j])continue;
			tmp = min(tmp,make_pair(dist[j],1ll*j));
		}
		if(tmp.sc == -1)break;
		now = tmp.sc;
	}
	return;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i = 0;i<m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		add_edge(a,b,c,d);
	}
	DIJKSTRA(1,g,d1);
	for(int i = 1;i<=n;i++){
		if(pid[i] != -1)tree[pid[i]>>1] = true;
	}
	DIJKSTRA(n,g,d2);
	for(int i = 1;i<=n;i++){
		if(pid[i] != -1)tree[pid[i]>>1] = true;
	}
	DIJKSTRA(1,rg,d3);
	DIJKSTRA(n,rg,d4);
	ll ans = inf;
	ans = min(ans,d1[n]+d2[1]);
	/*
	cout<<"d1:";for(int i = 1;i<=n;i++)cout<<d1[i]<<' ';cout<<endl;
	cout<<"d2:";for(int i = 1;i<=n;i++)cout<<d2[i]<<' ';cout<<endl;
	cout<<"d3:";for(int i = 1;i<=n;i++)cout<<d3[i]<<' ';cout<<endl;
	cout<<"d4:";for(int i = 1;i<=n;i++)cout<<d4[i]<<' ';cout<<endl;

   */

	for(int i = 0;i<edges.size();i+=2){
		if(tree[i>>1]){
			del[i] = del[i^1] = true;
			add_edge(edges[i].to,edges[i^1].to,edges[i].cost,edges[i].price);
			DIJKSTRA(1,g,d5);
			DIJKSTRA(n,g,d6);
			g[edges[i].to].pop_back();
			rg[edges[i^1].to].pop_back();
			edges.pop_back();edges.pop_back();
			del[i] = del[i^1] = false;
			ans = min(ans,d5[n]+d6[1]+edges[i].price);
			//cout<<i<<":"<<edges[i^1].to<<' '<<edges[i].to<<":"<<d5[n]<<' '<<d6[1]<<' '<<edges[i].price<<endl;
		}
		else{
			ll tans = min(d1[edges[i].to]+d4[edges[i^1].to]+edges[i].cost,d1[n]);
			tans += min(d2[edges[i].to]+d3[edges[i^1].to]+edges[i].cost,d2[1]);
			tans += edges[i].price;
			ans = min(ans,tans);
		}
	}
	cout<<(ans>=inf?-1:ans);
}

Compilation message

ho_t4.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |  for(int i = 0;i<edges.size();i+=2){
      |                ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 47 ms 532 KB Output is correct
4 Correct 47 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 36 ms 348 KB Output is correct
11 Correct 50 ms 348 KB Output is correct
12 Correct 46 ms 348 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 30 ms 348 KB Output is correct
15 Correct 28 ms 840 KB Output is correct
16 Correct 25 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 2380 KB Output is correct
2 Correct 149 ms 2384 KB Output is correct
3 Correct 141 ms 2324 KB Output is correct
4 Correct 42 ms 604 KB Output is correct
5 Correct 32 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 40 ms 2324 KB Output is correct
10 Correct 37 ms 2316 KB Output is correct
11 Correct 108 ms 2380 KB Output is correct
12 Correct 95 ms 2320 KB Output is correct
13 Correct 83 ms 2320 KB Output is correct
14 Correct 74 ms 2456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 116 ms 2324 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 147 ms 2476 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 42 ms 2324 KB Output is correct
9 Correct 49 ms 2320 KB Output is correct
10 Correct 106 ms 2564 KB Output is correct
11 Correct 86 ms 2324 KB Output is correct
12 Correct 97 ms 2324 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 111 ms 2688 KB Output is correct
20 Correct 92 ms 2324 KB Output is correct
21 Correct 93 ms 2324 KB Output is correct
22 Correct 96 ms 2324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 47 ms 532 KB Output is correct
4 Correct 47 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 36 ms 348 KB Output is correct
11 Correct 50 ms 348 KB Output is correct
12 Correct 46 ms 348 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 30 ms 348 KB Output is correct
15 Correct 28 ms 840 KB Output is correct
16 Correct 25 ms 536 KB Output is correct
17 Correct 142 ms 2380 KB Output is correct
18 Correct 149 ms 2384 KB Output is correct
19 Correct 141 ms 2324 KB Output is correct
20 Correct 42 ms 604 KB Output is correct
21 Correct 32 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 40 ms 2324 KB Output is correct
26 Correct 37 ms 2316 KB Output is correct
27 Correct 108 ms 2380 KB Output is correct
28 Correct 95 ms 2320 KB Output is correct
29 Correct 83 ms 2320 KB Output is correct
30 Correct 74 ms 2456 KB Output is correct
31 Correct 30 ms 344 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 116 ms 2324 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 147 ms 2476 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 42 ms 2324 KB Output is correct
39 Correct 49 ms 2320 KB Output is correct
40 Correct 106 ms 2564 KB Output is correct
41 Correct 86 ms 2324 KB Output is correct
42 Correct 97 ms 2324 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 111 ms 2688 KB Output is correct
50 Correct 92 ms 2324 KB Output is correct
51 Correct 93 ms 2324 KB Output is correct
52 Correct 96 ms 2324 KB Output is correct
53 Correct 136 ms 2348 KB Output is correct
54 Correct 157 ms 2320 KB Output is correct
55 Correct 140 ms 2324 KB Output is correct
56 Correct 52 ms 348 KB Output is correct
57 Correct 41 ms 356 KB Output is correct
58 Correct 92 ms 2728 KB Output is correct
59 Correct 96 ms 2320 KB Output is correct
60 Correct 139 ms 2324 KB Output is correct
61 Correct 87 ms 2324 KB Output is correct
62 Correct 108 ms 2324 KB Output is correct
63 Correct 143 ms 2320 KB Output is correct
64 Correct 144 ms 2324 KB Output is correct
65 Correct 152 ms 2320 KB Output is correct
66 Correct 193 ms 2324 KB Output is correct
67 Correct 10 ms 2324 KB Output is correct
68 Correct 41 ms 2324 KB Output is correct
69 Correct 42 ms 2324 KB Output is correct
70 Correct 100 ms 2320 KB Output is correct
71 Correct 100 ms 2324 KB Output is correct
72 Correct 99 ms 2328 KB Output is correct
73 Correct 106 ms 2320 KB Output is correct
74 Correct 96 ms 2324 KB Output is correct