Submission #705441

# Submission time Handle Problem Language Result Execution time Memory
705441 2023-03-04T11:26:29 Z blacktulip Olympic Bus (JOI20_ho_t4) C++17
37 / 100
197 ms 12060 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long lo; 
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define int long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 10000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;

int n,m,k,flag,t,y[li],z[li],c[li],d[li],dist[1005][1005],cur1[li],value,par[li],ekstra1,ekstra2,ekstra3;
int cev;
bool vis[li],yolda[li],yolda1[li],yasak[li];
string s;
vector<pair<int,pair<int,int>>> v[li],rv[li];

inline int in(){
    int x;
    scanf("%lld",&x);
    return x;
}

inline void sp(bool cont){
	priority_queue<pair<int,int>> pq;
	pq.push({0,1});
	for(int i=1;i<=n;i++){vis[i]=0;cur1[i]=inf;}
	while(pq.size()){
		int node=pq.top().se;
		int co=-pq.top().fi;
		pq.pop();
		if(vis[node])continue;
		vis[node]=1;
		cur1[node]=co;
		for(auto go:v[node]){
			if(!vis[go.fi] && yasak[go.se.se]==0 && go.se.fi+co<cur1[go.fi]){cur1[go.fi]=go.se.fi+co;par[go.fi]=node;pq.push({-co-go.se.fi,go.fi});}
		}
		if(node==ekstra1){
			if(!vis[ekstra2] && co+ekstra3<cur1[ekstra2]){cur1[ekstra2]=ekstra3+co;pq.push({-co-ekstra3,ekstra2});}
		}
	}
	if(cont){value=cur1[n];return ;}
	if(vis[n]==0)return ;
	int node=n;
	while(node!=1){
		for(auto go:rv[node]){
			if(go.fi==par[node]){node=go.fi;yolda[go.se.se]=1;break;}
		}
	}
}

inline void sp1(bool cont){
	priority_queue<pair<int,int>> pq;
	pq.push({0,n});
	for(int i=1;i<=n;i++){vis[i]=0;cur1[i]=inf;}
	while(pq.size()){
		int node=pq.top().se;
		int co=-pq.top().fi;
		pq.pop();
		if(vis[node])continue;
		vis[node]=1;
		cur1[node]=co;
		for(auto go:v[node]){
			if(!vis[go.fi] && yasak[go.se.se]==0 && go.se.fi+co<cur1[go.fi]){cur1[go.fi]=go.se.fi+co;par[go.fi]=node;pq.push({-co-go.se.fi,go.fi});}
		}
		if(node==ekstra1){
			if(!vis[ekstra2] && co+ekstra3<cur1[ekstra2]){cur1[ekstra2]=ekstra3+co;pq.push({-co-ekstra3,ekstra2});}
		}
	}
	if(cont){value=cur1[1];return ;}
	if(vis[1]==0)return ;
	int node=1;
	while(node!=n){
		for(auto go:rv[node]){
			if(go.fi==par[node]){node=go.fi;yolda1[go.se.se]=1;break;}
		}
	}
}

int32_t main(void){
    n=in(),m=in();
    FOR{
		for(int j=1;j<=n;j++){dist[i][j]=inf;}
		dist[i][i]=0;
	}
    for(int i=1;i<=m;i++){
		y[i]=in(),z[i]=in(),c[i]=in(),d[i]=in();
		dist[y[i]][z[i]]=min(dist[y[i]][z[i]],c[i]);
		v[y[i]].pb({z[i],{c[i],i}});
		rv[z[i]].pb({y[i],{c[i],i}});
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int jj=1;jj<=n;jj++){
				dist[j][jj]=min(dist[j][jj],dist[j][i]+dist[i][jj]);
			}
		}
	}
	sp(0);
	sp1(0);
	//~ cout<<"**\n";
	cev=min(inf,dist[1][n]+dist[n][1]);
	for(int i=1;i<=m;i++){
		if(yolda[i]==0 && yolda1[i]==0){
			cev=min(cev,dist[1][n]+dist[n][z[i]]+dist[y[i]][1]+d[i]+c[i]);
			cev=min(cev,dist[n][1]+dist[1][z[i]]+dist[y[i]][n]+d[i]+c[i]);
			cev=min(cev,dist[n][z[i]]+c[i]+dist[y[i]][1]+dist[1][z[i]]+dist[y[i]][n]+d[i]+c[i]);
			continue;
		}
		//~ if(yolda[i] && yolda1[i]){
			yasak[i]=1;
			ekstra1=z[i];
			ekstra2=y[i];
			ekstra3=c[i];
			sp(1);
			yasak[i]=0;
			int val=value;
			ekstra1=z[i];
			ekstra2=y[i];
			ekstra3=c[i];
			yasak[i]=1;
			sp1(1);
			yasak[i]=0;
			cev=min(cev,val+value+d[i]);
			continue;
		//~ }
		if(yolda[i]){
			yasak[i]=1;
			ekstra1=z[i];
			ekstra2=y[i];
			ekstra3=c[i];
			sp(1);
			yasak[i]=0;
			cev=min(cev,min(dist[n][1],dist[n][z[i]]+dist[y[i]][1]+c[i])+value+d[i]);
			continue;
		}
		ekstra1=z[i];
		ekstra2=y[i];
		ekstra3=c[i];
		yasak[i]=1;
		sp1(1);
		yasak[i]=0;
		cev=min(cev,min(dist[1][n],dist[1][z[i]]+dist[y[i]][n]+c[i])+value+d[i]);
	}
	if(cev>=inf)cev=-1;
	printf("%lld\n",cev);
    return 0;
}

Compilation message

ho_t4.cpp: In function 'long long int in()':
ho_t4.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%lld",&x);
      |     ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6228 KB Output is correct
2 Correct 11 ms 6100 KB Output is correct
3 Correct 12 ms 6244 KB Output is correct
4 Correct 13 ms 6228 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 11 ms 6052 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 29 ms 6276 KB Output is correct
11 Correct 33 ms 6228 KB Output is correct
12 Correct 30 ms 6252 KB Output is correct
13 Correct 12 ms 6228 KB Output is correct
14 Correct 12 ms 6228 KB Output is correct
15 Correct 12 ms 6236 KB Output is correct
16 Correct 12 ms 6244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11340 KB Output is correct
2 Correct 36 ms 11704 KB Output is correct
3 Correct 37 ms 11316 KB Output is correct
4 Correct 12 ms 6348 KB Output is correct
5 Correct 12 ms 6228 KB Output is correct
6 Correct 11 ms 6184 KB Output is correct
7 Correct 14 ms 6224 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 33 ms 11540 KB Output is correct
10 Correct 32 ms 11520 KB Output is correct
11 Correct 36 ms 11640 KB Output is correct
12 Correct 35 ms 11528 KB Output is correct
13 Correct 35 ms 11236 KB Output is correct
14 Correct 36 ms 12060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6228 KB Output is correct
2 Correct 11 ms 6152 KB Output is correct
3 Correct 28 ms 10116 KB Output is correct
4 Correct 13 ms 6152 KB Output is correct
5 Correct 34 ms 11220 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4996 KB Output is correct
8 Correct 33 ms 11504 KB Output is correct
9 Correct 31 ms 11464 KB Output is correct
10 Correct 32 ms 11220 KB Output is correct
11 Correct 32 ms 11256 KB Output is correct
12 Correct 31 ms 11328 KB Output is correct
13 Correct 4 ms 5040 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 35 ms 11464 KB Output is correct
20 Correct 36 ms 11188 KB Output is correct
21 Correct 36 ms 11440 KB Output is correct
22 Correct 34 ms 11424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6228 KB Output is correct
2 Correct 11 ms 6100 KB Output is correct
3 Correct 12 ms 6244 KB Output is correct
4 Correct 13 ms 6228 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 11 ms 6052 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 29 ms 6276 KB Output is correct
11 Correct 33 ms 6228 KB Output is correct
12 Correct 30 ms 6252 KB Output is correct
13 Correct 12 ms 6228 KB Output is correct
14 Correct 12 ms 6228 KB Output is correct
15 Correct 12 ms 6236 KB Output is correct
16 Correct 12 ms 6244 KB Output is correct
17 Correct 38 ms 11340 KB Output is correct
18 Correct 36 ms 11704 KB Output is correct
19 Correct 37 ms 11316 KB Output is correct
20 Correct 12 ms 6348 KB Output is correct
21 Correct 12 ms 6228 KB Output is correct
22 Correct 11 ms 6184 KB Output is correct
23 Correct 14 ms 6224 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 33 ms 11540 KB Output is correct
26 Correct 32 ms 11520 KB Output is correct
27 Correct 36 ms 11640 KB Output is correct
28 Correct 35 ms 11528 KB Output is correct
29 Correct 35 ms 11236 KB Output is correct
30 Correct 36 ms 12060 KB Output is correct
31 Correct 13 ms 6228 KB Output is correct
32 Correct 11 ms 6152 KB Output is correct
33 Correct 28 ms 10116 KB Output is correct
34 Correct 13 ms 6152 KB Output is correct
35 Correct 34 ms 11220 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4996 KB Output is correct
38 Correct 33 ms 11504 KB Output is correct
39 Correct 31 ms 11464 KB Output is correct
40 Correct 32 ms 11220 KB Output is correct
41 Correct 32 ms 11256 KB Output is correct
42 Correct 31 ms 11328 KB Output is correct
43 Correct 4 ms 5040 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 2 ms 4948 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 35 ms 11464 KB Output is correct
50 Correct 36 ms 11188 KB Output is correct
51 Correct 36 ms 11440 KB Output is correct
52 Correct 34 ms 11424 KB Output is correct
53 Correct 36 ms 11436 KB Output is correct
54 Correct 40 ms 11284 KB Output is correct
55 Correct 38 ms 11524 KB Output is correct
56 Correct 12 ms 6228 KB Output is correct
57 Correct 17 ms 6244 KB Output is correct
58 Correct 130 ms 10212 KB Output is correct
59 Correct 154 ms 10220 KB Output is correct
60 Correct 197 ms 10208 KB Output is correct
61 Correct 126 ms 10104 KB Output is correct
62 Incorrect 144 ms 10196 KB Output isn't correct
63 Halted 0 ms 0 KB -