답안 #879495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879495 2023-11-27T14:38:43 Z KN200711 Cities (BOI16_cities) C++14
14 / 100
306 ms 25820 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

vector< pair<int, ll> > edge[100001];
ll dist[100001], mn[5][100001];
bool vis[100001];

int main() {
	int N, K, M;
	scanf("%d %d %d", &N, &K, &M);
	vector<int> ipr(K);
	for(int i=0;i<K;i++) {
		scanf("%d", &ipr[i]);
	}
	
	for(int i=0;i<M;i++) {
		int a, b;
		ll c;
		scanf("%d %d %lld", &a, &b, &c);
		edge[a].push_back(make_pair(b, c));
		edge[b].push_back(make_pair(a, c));
	}
	
	for(int i=0;i<K;i++) {
		priority_queue< pair<ll, int> > PQ;
		PQ.push(make_pair(0ll, ipr[i]));
		for(int c=1;c<=N;c++) vis[c] = 0;
		while(!PQ.empty()) {
			ll a = PQ.top().fi;
			int b = PQ.top().se;
			PQ.pop();
			if(vis[b]) continue;
			vis[b] = 1;
			mn[i][b] = -a;
			dist[b] -= a;
			for(int c=0;c<edge[b].size();c++) {
				if(!vis[edge[b][c].fi]) PQ.push(make_pair(a - 1ll * edge[b][c].se, edge[b][c].fi));
			}
		}
	}
	ll ans = 1e18;
	for(int d=1;d<=N;d++) {
		ll as = 0ll;
		for(int c=0;c<K;c++) {
			as += mn[c][d];
		}
		ans = min(ans, as);
	}
	if(K == 4) {
		for(int i=1;i<=N;i++) {
			for(int c=0;c<4;c++) {
				ll as = 0ll, v=  1e18;
				for(int d=0;d<4;d++) {
					if(c == d) continue;
					v = min(v, mn[d][ipr[c]]);
					as += mn[d][i];
				}
				as += v;
				ans = min(ans, as);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for(int c=0;c<edge[b].size();c++) {
      |                ~^~~~~~~~~~~~~~~
cities.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d %d %d", &N, &K, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d", &ipr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
cities.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d %d %lld", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7392 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 7256 KB Output is correct
4 Incorrect 1 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 23844 KB Output is correct
2 Correct 235 ms 25060 KB Output is correct
3 Correct 61 ms 14880 KB Output is correct
4 Correct 162 ms 25016 KB Output is correct
5 Correct 196 ms 25820 KB Output is correct
6 Correct 118 ms 22160 KB Output is correct
7 Correct 3 ms 7516 KB Output is correct
8 Correct 3 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 246 ms 25616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 306 ms 25468 KB Output isn't correct
2 Halted 0 ms 0 KB -