제출 #107690

#제출 시각아이디문제언어결과실행 시간메모리
107690KepperoniCities (BOI16_cities)C++14
74 / 100
6112 ms245476 KiB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const int MAXN = 1e5 + 10;

ll n, m, kk;
vector<pii> k[MAXN];

ll di[MAXN][40];
bool vis[MAXN][40];

int main(){
	scanf(" %lld %lld %lld", &n, &kk, &m);
	for(int i=0; i<=n; i++)
		for(int j=0; j<40; j++)
			di[i][j] = 1e16;
	
	priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> q;
	for(int i=0; i<kk; i++){
		int cu; scanf(" %d", &cu);
		di[cu][1<<i] = 0;
		q.push({0, {cu, 1<<i}});
	}

	for(int i=0; i<m; i++){
		ll fr, to, co; scanf(" %lld %lld %lld", &fr, &to, &co);
		k[fr].pb({to, co});
		k[to].pb({fr, co});
	}

	while(!q.empty()){
		auto x = q.top();
		q.pop();
		if(vis[x.y.x][x.y.y]) continue;
		vis[x.y.x][x.y.y] = 1;

		//cout << x.y.x << " " << bitset<3>(x.y.y) << " " << x.x << endl;
		int oma = ~x.y.y;
		int i = 0;
		while(i < (1<<kk)){
			int a = i ^ oma;				
			a = a & -a;
			i ^= a;
			i &= -a;
			//cout << i << " " << x.y.y << endl;
			int nm = i | x.y.y;
			if(di[x.y.x][nm] > x.x + di[x.y.x][i]){
				di[x.y.x][nm] = x.x + di[x.y.x][i];
				q.push({di[x.y.x][nm], {x.y.x, nm}});
			}
		}

		for(auto u : k[x.y.x]){
			if(di[u.x][x.y.y] > x.x + u.y){
				di[u.x][x.y.y] = x.x + u.y;
				q.push({x.x+u.y, {u.x, x.y.y}});
			}
		}

	}

	ll ans = 1e16;
	for(int i=1; i<=n; i++)
		ans = min(ans, di[i][(1<<kk)-1]);
	
	cout << ans << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

cities.cpp: In function 'int main()':
cities.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %lld %lld %lld", &n, &kk, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:27:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int cu; scanf(" %d", &cu);
           ~~~~~^~~~~~~~~~~~
cities.cpp:33:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll fr, to, co; scanf(" %lld %lld %lld", &fr, &to, &co);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...