Submission #231638

# Submission time Handle Problem Language Result Execution time Memory
231638 2020-05-14T08:44:47 Z _7_7_ Olympic Bus (JOI20_ho_t4) C++14
100 / 100
691 ms 6264 KB
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e18, maxn = 208, mod = 1e9 + 7, N = 5e4 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, m, a[N], b[N], c[N], d[N], p[maxn], Bad, F[maxn][maxn], D[maxn]; 
priority_queue < pii, vpii, greater < pii > > q;
vpii g[2][maxn];
bool I[4][N];

 
 
void Floyd () {
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)	
		    if (i != j)
				F[i][j] = inf;
 
	for (int i = 1; i <= m; ++i)
		F[a[i]][b[i]] = min(F[a[i]][b[i]], c[i]);
 
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
 
}
 
int Dijkstra (int s, int f, int j, int x = -1) {
	memset(p, -1, sizeof(p));

	for (int i = 1; i <= n; ++i)
		D[i] = inf;

	while (sz(q))
		q.pop();

	D[s] = 0;
	q.push(mp(0, s));
	while (sz(q)) {
		int v = q.top().s, w = q.top().f;
		if (Bad && v == f)
			return D[f];
		q.pop();

		if (w > D[v])
			continue;

		for (auto X : g[j][v]) {			
			int to = X.f, i = X.s;
			if (i != Bad && D[to] > D[v] + c[i]) {
				D[to] = D[v] + c[i];
				p[to] = i;
				q.push(mp(D[to], to));
			}
		}
	}

	if (x > -1) {
		for (int i = 1; i <= n; ++i)
			if (p[i] > -1)
				I[x][p[i]] = 1;
	}

	return inf;
}
 
 
main () {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
		g[0][a[i]].pb({b[i], i});
		g[1][b[i]].pb({a[i], i});
	}
 
	Floyd();
	Dijkstra(1, n, 0, 0);
	Dijkstra(n, 1, 0, 1);
	Dijkstra(1, n, 1, 2);
	Dijkstra(n, 1, 1, 3);
 

	int ans = min(inf, F[1][n] + F[n][1]);

	for (int i = 1; i <= m; ++i) {
		Bad = i;
		g[0][b[i]].pb({a[i], m + 1});
		c[m + 1] = c[i];
	
		int d1, d2;
		if (I[0][i] || I[3][i])
			d1 = Dijkstra(1, n, 0);
		else
			d1 = min(F[1][n], F[1][b[i]] + F[a[i]][n] + c[i]);
		
		if (I[1][i] || I[2][i])
			d2 = Dijkstra(n, 1, 0);
		else
			d2 = min(F[n][1], F[n][b[i]] + F[a[i]][1] + c[i]);
		
		g[0][b[i]].ppb();
		ans = min(ans, d1 + d2 + d[i]);		
	}
 
	if (ans == inf)
		ans = -1;
	printf("%d\n", ans);			
}

Compilation message

ho_t4.cpp:103:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:104:22: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  scanf("%d%d", &n, &m);
                ~~    ^
ho_t4.cpp:104:22: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
ho_t4.cpp:106:47: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
                     ~~~~~                     ^
ho_t4.cpp:106:47: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
ho_t4.cpp:106:47: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
ho_t4.cpp:106:47: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'long long int*' [-Wformat=]
ho_t4.cpp:142:20: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n", ans);   
                    ^
ho_t4.cpp:104:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
ho_t4.cpp:106:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 768 KB Output is correct
2 Correct 13 ms 640 KB Output is correct
3 Correct 26 ms 768 KB Output is correct
4 Correct 30 ms 768 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 13 ms 768 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 29 ms 768 KB Output is correct
11 Correct 28 ms 768 KB Output is correct
12 Correct 29 ms 888 KB Output is correct
13 Correct 17 ms 768 KB Output is correct
14 Correct 23 ms 768 KB Output is correct
15 Correct 19 ms 768 KB Output is correct
16 Correct 24 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 4992 KB Output is correct
2 Correct 125 ms 5112 KB Output is correct
3 Correct 117 ms 4988 KB Output is correct
4 Correct 18 ms 896 KB Output is correct
5 Correct 18 ms 768 KB Output is correct
6 Correct 14 ms 768 KB Output is correct
7 Correct 13 ms 768 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 69 ms 4856 KB Output is correct
10 Correct 67 ms 4856 KB Output is correct
11 Correct 102 ms 5108 KB Output is correct
12 Correct 99 ms 5240 KB Output is correct
13 Correct 114 ms 5112 KB Output is correct
14 Correct 104 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 768 KB Output is correct
2 Correct 14 ms 768 KB Output is correct
3 Correct 75 ms 3840 KB Output is correct
4 Correct 14 ms 768 KB Output is correct
5 Correct 89 ms 4960 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 68 ms 5112 KB Output is correct
9 Correct 58 ms 5112 KB Output is correct
10 Correct 94 ms 5112 KB Output is correct
11 Correct 63 ms 5112 KB Output is correct
12 Correct 59 ms 5240 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 99 ms 5496 KB Output is correct
20 Correct 66 ms 5240 KB Output is correct
21 Correct 59 ms 5368 KB Output is correct
22 Correct 67 ms 5244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 768 KB Output is correct
2 Correct 13 ms 640 KB Output is correct
3 Correct 26 ms 768 KB Output is correct
4 Correct 30 ms 768 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 13 ms 768 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 29 ms 768 KB Output is correct
11 Correct 28 ms 768 KB Output is correct
12 Correct 29 ms 888 KB Output is correct
13 Correct 17 ms 768 KB Output is correct
14 Correct 23 ms 768 KB Output is correct
15 Correct 19 ms 768 KB Output is correct
16 Correct 24 ms 768 KB Output is correct
17 Correct 116 ms 4992 KB Output is correct
18 Correct 125 ms 5112 KB Output is correct
19 Correct 117 ms 4988 KB Output is correct
20 Correct 18 ms 896 KB Output is correct
21 Correct 18 ms 768 KB Output is correct
22 Correct 14 ms 768 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 69 ms 4856 KB Output is correct
26 Correct 67 ms 4856 KB Output is correct
27 Correct 102 ms 5108 KB Output is correct
28 Correct 99 ms 5240 KB Output is correct
29 Correct 114 ms 5112 KB Output is correct
30 Correct 104 ms 5368 KB Output is correct
31 Correct 25 ms 768 KB Output is correct
32 Correct 14 ms 768 KB Output is correct
33 Correct 75 ms 3840 KB Output is correct
34 Correct 14 ms 768 KB Output is correct
35 Correct 89 ms 4960 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 68 ms 5112 KB Output is correct
39 Correct 58 ms 5112 KB Output is correct
40 Correct 94 ms 5112 KB Output is correct
41 Correct 63 ms 5112 KB Output is correct
42 Correct 59 ms 5240 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 99 ms 5496 KB Output is correct
50 Correct 66 ms 5240 KB Output is correct
51 Correct 59 ms 5368 KB Output is correct
52 Correct 67 ms 5244 KB Output is correct
53 Correct 142 ms 5240 KB Output is correct
54 Correct 145 ms 5240 KB Output is correct
55 Correct 114 ms 5248 KB Output is correct
56 Correct 28 ms 768 KB Output is correct
57 Correct 24 ms 768 KB Output is correct
58 Correct 114 ms 4216 KB Output is correct
59 Correct 112 ms 4216 KB Output is correct
60 Correct 117 ms 4216 KB Output is correct
61 Correct 106 ms 4216 KB Output is correct
62 Correct 109 ms 4216 KB Output is correct
63 Correct 112 ms 4216 KB Output is correct
64 Correct 691 ms 4808 KB Output is correct
65 Correct 636 ms 4728 KB Output is correct
66 Correct 611 ms 4724 KB Output is correct
67 Correct 26 ms 3956 KB Output is correct
68 Correct 90 ms 6264 KB Output is correct
69 Correct 72 ms 6032 KB Output is correct
70 Correct 135 ms 6136 KB Output is correct
71 Correct 125 ms 6012 KB Output is correct
72 Correct 115 ms 6136 KB Output is correct
73 Correct 135 ms 6140 KB Output is correct
74 Correct 124 ms 6264 KB Output is correct