답안 #888019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888019 2023-12-15T19:26:44 Z hariaakas646 Olympic Bus (JOI20_ho_t4) C++14
0 / 100
39 ms 2028 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(x) scanf("%d", &x)
#define sclld(x) scanf("%lld", &x)
#define frange(i, n) for(int i=0; i<n; i++)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define all(vec) vec.begin(), vec.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<lli> vll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> seti;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int main() {
	// usaco();
	int n, m;
	scd(n);
	scd(m);

	vector<vll> cost(n+1, vll(n+1, 1e17)), chn(n+1, vll(n+1, 1e17)), dist(n+1, vll(n+1, 1e17));

	forr(i, 1, n+1) cost[i][i] = dist[i][i] = 0;
	vii edg;

	frange(i, m) {
		int u, v;
		lli c, d;
		scd(u);
		scd(v);
		sclld(c);
		sclld(d);
		// if(i%2==0)
		edg.pb(mp(u, v));

		dist[u][v] = cost[u][v] = min(c, cost[u][v]);
		chn[u][v] = min(chn[u][v], d);
	}

	frange(_, 3) {forr(k, 1, n+1) {
			forr(i, 1, n+1) {
				forr(j, 1, n+1) {
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}}

	lli mi = dist[1][n] + dist[n][1];
	// printf("%lld\n", mi);

	for(auto p : edg) {
		// printf("%d %d ", p.f, p.s);
		lli v = 0;
		v = dist[1][n] + dist[n][p.s] + dist[p.f][1] + cost[p.f][p.s] + chn[p.f][p.s];
		// printf("%lld ", v);
		mi = min(mi, v);
		v = dist[1][p.s] + dist[p.f][n] + dist[n][p.s] + dist[p.f][1] + 2*cost[p.f][p.s] + chn[p.f][p.s];
		// printf("%lld ", v);
		mi = min(mi, v);
		v = dist[1][p.s] + dist[p.f][n] + dist[n][1] + cost[p.f][p.s] + chn[p.f][p.s];
		// printf("%lld\n", v);
		mi = min(mi, v);
	}
	if(mi < 1e16)
	printf("%lld", mi);
	else printf("-1");
}

Compilation message

ho_t4.cpp: In function 'void usaco()':
ho_t4.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t4.cpp:31:2: note: in expansion of macro 'scd'
   31 |  scd(n);
      |  ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t4.cpp:32:2: note: in expansion of macro 'scd'
   32 |  scd(m);
      |  ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t4.cpp:42:3: note: in expansion of macro 'scd'
   42 |   scd(u);
      |   ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(x) scanf("%d", &x)
      |                ~~~~~^~~~~~~~~~
ho_t4.cpp:43:3: note: in expansion of macro 'scd'
   43 |   scd(v);
      |   ^~~
ho_t4.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(x) scanf("%lld", &x)
      |                  ~~~~~^~~~~~~~~~~~
ho_t4.cpp:44:3: note: in expansion of macro 'sclld'
   44 |   sclld(c);
      |   ^~~~~
ho_t4.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(x) scanf("%lld", &x)
      |                  ~~~~~^~~~~~~~~~~~
ho_t4.cpp:45:3: note: in expansion of macro 'sclld'
   45 |   sclld(d);
      |   ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 20 ms 1372 KB Output is correct
3 Correct 20 ms 1372 KB Output is correct
4 Correct 22 ms 1420 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 1408 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2008 KB Output is correct
2 Correct 34 ms 2008 KB Output is correct
3 Correct 34 ms 2012 KB Output is correct
4 Correct 23 ms 1432 KB Output is correct
5 Correct 20 ms 1372 KB Output is correct
6 Correct 24 ms 1416 KB Output is correct
7 Correct 20 ms 1664 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 35 ms 1980 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1372 KB Output is correct
2 Correct 20 ms 1372 KB Output is correct
3 Correct 31 ms 2028 KB Output is correct
4 Correct 22 ms 1400 KB Output is correct
5 Correct 35 ms 2004 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 20 ms 1372 KB Output is correct
3 Correct 20 ms 1372 KB Output is correct
4 Correct 22 ms 1420 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 1408 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -