답안 #255139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255139 2020-07-31T10:24:00 Z Goolakh Olympic Bus (JOI20_ho_t4) C++17
100 / 100
461 ms 5364 KB
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") 
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e2+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll n,m,V[maxm],U[maxm],C[maxm],ans[maxm];
bool mk[maxn];
void dij(ll sr,vector<ll> adj[],ll dis[],ll par[]){
	for(int i=0;i<=n;i++) dis[i]=inf, par[i]=mk[i]=0;
	dis[sr]=0;
	while(1){
		ll v=0;
		for(int i=1;i<=n;i++)if(!mk[i] && dis[i]<dis[v]) v=i;
		if(!v) return;
		mk[v]=1;
		for(auto i:adj[v]){
			ll u=V[i]^U[i]^v;
			if(dis[v]+C[i]<dis[u]) dis[u]=dis[v]+C[par[u]=i];
		}
	}
}

ll dis[3][maxn],py[3][maxn];
vector<ll> g[maxn],rg[maxn],gg[maxn];
bool dd[maxm];
void solve(ll a,ll b){
	dij(a,g,dis[0],py[0]), dij(b,rg,dis[1],py[1]);
	ans[0]+=dis[0][b];
	memset(dd,0,sizeof(dd)); for(int i=1;i<=n;i++) dd[py[0][i]]=dd[py[1][i]]=1;
	for(int i=1;i<=m;i++){
		if(dis[0][U[i]]>=inf || dis[1][V[i]]>=inf){
			ans[i]+=inf;
			continue;
		}
		if(!dd[i]) ans[i]+=min(dis[0][b],dis[0][U[i]]+C[i]+dis[1][V[i]]);
		else{
			for(int i=1;i<=n;i++) gg[i].clear();
			for(int j=1;j<=m;j++)if(i!=j) gg[V[j]].pb(j);
			gg[U[i]].pb(i);
			dij(a,gg,dis[2],py[2]);
			ans[i]+=dis[2][b];
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	//memset(ans,69,sizeof(ans));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>V[i]>>U[i]>>C[i]>>ans[i];
		g[V[i]].pb(i), rg[U[i]].pb(i);
	}
	solve(1,n), solve(n,1);
	ll jj=inf;
	for(int i=0;i<=m;i++) jj=min(jj,ans[i]);
	cout<<(jj>=inf ? -1:jj);
	
	return 0;
}




# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 640 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 59 ms 512 KB Output is correct
4 Correct 58 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 38 ms 512 KB Output is correct
11 Correct 36 ms 512 KB Output is correct
12 Correct 37 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 30 ms 512 KB Output is correct
15 Correct 30 ms 512 KB Output is correct
16 Correct 30 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 5024 KB Output is correct
2 Correct 396 ms 4856 KB Output is correct
3 Correct 401 ms 5160 KB Output is correct
4 Correct 65 ms 640 KB Output is correct
5 Correct 46 ms 632 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 35 ms 4344 KB Output is correct
10 Correct 24 ms 4352 KB Output is correct
11 Correct 224 ms 4984 KB Output is correct
12 Correct 213 ms 5240 KB Output is correct
13 Correct 217 ms 5112 KB Output is correct
14 Correct 214 ms 5364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 373 ms 3832 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 461 ms 4700 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 20 ms 4096 KB Output is correct
9 Correct 22 ms 4096 KB Output is correct
10 Correct 240 ms 4736 KB Output is correct
11 Correct 245 ms 4728 KB Output is correct
12 Correct 240 ms 4864 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 238 ms 4864 KB Output is correct
20 Correct 244 ms 4600 KB Output is correct
21 Correct 243 ms 4600 KB Output is correct
22 Correct 239 ms 4844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 640 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 59 ms 512 KB Output is correct
4 Correct 58 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 38 ms 512 KB Output is correct
11 Correct 36 ms 512 KB Output is correct
12 Correct 37 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 30 ms 512 KB Output is correct
15 Correct 30 ms 512 KB Output is correct
16 Correct 30 ms 512 KB Output is correct
17 Correct 400 ms 5024 KB Output is correct
18 Correct 396 ms 4856 KB Output is correct
19 Correct 401 ms 5160 KB Output is correct
20 Correct 65 ms 640 KB Output is correct
21 Correct 46 ms 632 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 35 ms 4344 KB Output is correct
26 Correct 24 ms 4352 KB Output is correct
27 Correct 224 ms 4984 KB Output is correct
28 Correct 213 ms 5240 KB Output is correct
29 Correct 217 ms 5112 KB Output is correct
30 Correct 214 ms 5364 KB Output is correct
31 Correct 67 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 373 ms 3832 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 461 ms 4700 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 20 ms 4096 KB Output is correct
39 Correct 22 ms 4096 KB Output is correct
40 Correct 240 ms 4736 KB Output is correct
41 Correct 245 ms 4728 KB Output is correct
42 Correct 240 ms 4864 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 238 ms 4864 KB Output is correct
50 Correct 244 ms 4600 KB Output is correct
51 Correct 243 ms 4600 KB Output is correct
52 Correct 239 ms 4844 KB Output is correct
53 Correct 411 ms 4736 KB Output is correct
54 Correct 410 ms 4728 KB Output is correct
55 Correct 406 ms 4756 KB Output is correct
56 Correct 60 ms 584 KB Output is correct
57 Correct 62 ms 512 KB Output is correct
58 Correct 202 ms 3836 KB Output is correct
59 Correct 209 ms 3840 KB Output is correct
60 Correct 212 ms 3960 KB Output is correct
61 Correct 207 ms 3860 KB Output is correct
62 Correct 200 ms 3832 KB Output is correct
63 Correct 202 ms 3840 KB Output is correct
64 Correct 284 ms 3968 KB Output is correct
65 Correct 274 ms 3968 KB Output is correct
66 Correct 256 ms 3968 KB Output is correct
67 Correct 18 ms 3956 KB Output is correct
68 Correct 24 ms 4344 KB Output is correct
69 Correct 27 ms 4344 KB Output is correct
70 Correct 216 ms 4960 KB Output is correct
71 Correct 218 ms 4856 KB Output is correct
72 Correct 216 ms 4856 KB Output is correct
73 Correct 215 ms 4984 KB Output is correct
74 Correct 216 ms 5112 KB Output is correct