답안 #170581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170581 2019-12-25T17:26:28 Z ZwariowanyMarcin Commuter Pass (JOI18_commuter_pass) C++14
100 / 100
499 ms 18944 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)

using namespace std;	

const int nax = 1e5 + 11;
const ll INF = 1e18;

int n, m, a, b, c;
int s, t;
int uu, vv;
vector <pair<int,int>> v[nax];
ll dis[3][nax];

priority_queue <pair<ll, int>> q;
bool odw[nax];

void dij(int pocz, int cnt) {
	for(int i = 1; i <= n; ++i) {
		dis[cnt][i] = INF;
		odw[i] = 0;
	}
	dis[cnt][pocz] = 0;
	q.push(mp(0, pocz));
	while(!q.empty()) {
		int ja = q.top().se;
		q.pop();
		if(odw[ja]) continue;
		odw[ja] = 1;
		for(auto it : v[ja]) {
			ll nowa = dis[cnt][ja] + it.se;
			if(nowa < dis[cnt][it.fi]) {
				dis[cnt][it.fi] = nowa;
				q.push(mp(-nowa, it.fi));
			}
		}
	}
}
	
ll ans = INF;
ll path[nax];
ll odl[nax];

void algo() {
	for(int i = 1; i <= n; ++i) {
		odw[i] = 0;
		odl[i] = INF;
		path[i] = INF;
	}
	q.push(mp(0, t));
	odl[t] = 0;
	while(!q.empty()) {
		int ja = q.top().se;
		q.pop();
		if(odw[ja]) continue;
		odw[ja] = 1;
		path[ja] = min(path[ja], dis[0][ja]);
		if(odl[ja] + dis[2][ja] == dis[2][t])
			ans = min(ans, dis[1][ja] + path[ja]);
		for(auto it : v[ja]) {
			ll nowa = odl[ja] + it.se;
			if(nowa < odl[it.fi]) {
				odl[it.fi] = nowa;
				path[it.fi] = path[ja];
				q.push(mp(-nowa, it.fi));
			}
			else if(nowa == odl[it.fi]) {
				path[it.fi] = min(path[it.fi], path[ja]);
			}
		}
	}
}
				
	
	

int main() {
	scanf("%d %d", &n, &m);
	scanf("%d %d", &s, &t);
	scanf("%d %d", &uu, &vv);
	for(int i = 1; i <= m; ++i) {
		scanf("%d %d %d", &a, &b, &c);
		v[a].pb(mp(b, c));
		v[b].pb(mp(a, c));
	}
	dij(uu, 0);
	dij(vv, 1);
	dij(s, 2);
	
	ans = min(ans, dis[0][vv]);
	algo();
	for(int i = 1; i <= n; ++i)
		swap(dis[0][i], dis[1][i]);
	algo();
	printf("%lld\n", ans);
	
	
	
	return 0;
}

Compilation message

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &s, &t);
  ~~~~~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &uu, &vv);
  ~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 18156 KB Output is correct
2 Correct 404 ms 17516 KB Output is correct
3 Correct 409 ms 18944 KB Output is correct
4 Correct 405 ms 17980 KB Output is correct
5 Correct 419 ms 17224 KB Output is correct
6 Correct 447 ms 18116 KB Output is correct
7 Correct 433 ms 17644 KB Output is correct
8 Correct 390 ms 17484 KB Output is correct
9 Correct 427 ms 18280 KB Output is correct
10 Correct 344 ms 18100 KB Output is correct
11 Correct 214 ms 11896 KB Output is correct
12 Correct 443 ms 18152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 17772 KB Output is correct
2 Correct 437 ms 17504 KB Output is correct
3 Correct 450 ms 17384 KB Output is correct
4 Correct 434 ms 17400 KB Output is correct
5 Correct 437 ms 17564 KB Output is correct
6 Correct 429 ms 17876 KB Output is correct
7 Correct 499 ms 17552 KB Output is correct
8 Correct 454 ms 17536 KB Output is correct
9 Correct 447 ms 17448 KB Output is correct
10 Correct 437 ms 17384 KB Output is correct
11 Correct 144 ms 11984 KB Output is correct
12 Correct 417 ms 17836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3708 KB Output is correct
2 Correct 4 ms 2808 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Correct 23 ms 4856 KB Output is correct
5 Correct 13 ms 3704 KB Output is correct
6 Correct 5 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 6 ms 2908 KB Output is correct
9 Correct 5 ms 2812 KB Output is correct
10 Correct 14 ms 3704 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 18156 KB Output is correct
2 Correct 404 ms 17516 KB Output is correct
3 Correct 409 ms 18944 KB Output is correct
4 Correct 405 ms 17980 KB Output is correct
5 Correct 419 ms 17224 KB Output is correct
6 Correct 447 ms 18116 KB Output is correct
7 Correct 433 ms 17644 KB Output is correct
8 Correct 390 ms 17484 KB Output is correct
9 Correct 427 ms 18280 KB Output is correct
10 Correct 344 ms 18100 KB Output is correct
11 Correct 214 ms 11896 KB Output is correct
12 Correct 443 ms 18152 KB Output is correct
13 Correct 440 ms 17772 KB Output is correct
14 Correct 437 ms 17504 KB Output is correct
15 Correct 450 ms 17384 KB Output is correct
16 Correct 434 ms 17400 KB Output is correct
17 Correct 437 ms 17564 KB Output is correct
18 Correct 429 ms 17876 KB Output is correct
19 Correct 499 ms 17552 KB Output is correct
20 Correct 454 ms 17536 KB Output is correct
21 Correct 447 ms 17448 KB Output is correct
22 Correct 437 ms 17384 KB Output is correct
23 Correct 144 ms 11984 KB Output is correct
24 Correct 417 ms 17836 KB Output is correct
25 Correct 14 ms 3708 KB Output is correct
26 Correct 4 ms 2808 KB Output is correct
27 Correct 4 ms 2808 KB Output is correct
28 Correct 23 ms 4856 KB Output is correct
29 Correct 13 ms 3704 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
31 Correct 5 ms 2808 KB Output is correct
32 Correct 6 ms 2908 KB Output is correct
33 Correct 5 ms 2812 KB Output is correct
34 Correct 14 ms 3704 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2808 KB Output is correct
38 Correct 5 ms 2808 KB Output is correct
39 Correct 5 ms 2808 KB Output is correct
40 Correct 404 ms 18536 KB Output is correct
41 Correct 403 ms 18204 KB Output is correct
42 Correct 402 ms 18280 KB Output is correct
43 Correct 146 ms 11924 KB Output is correct
44 Correct 137 ms 11932 KB Output is correct
45 Correct 339 ms 17000 KB Output is correct
46 Correct 368 ms 16900 KB Output is correct
47 Correct 408 ms 17920 KB Output is correct
48 Correct 225 ms 11544 KB Output is correct
49 Correct 386 ms 18164 KB Output is correct
50 Correct 377 ms 17164 KB Output is correct
51 Correct 357 ms 16996 KB Output is correct