Submission #487354

# Submission time Handle Problem Language Result Execution time Memory
487354 2021-11-15T10:08:39 Z Koosha_mv Cities (BOI16_cities) C++14
0 / 100
5132 ms 246384 KB
#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=2e5+99,K=5,inf=1000;

int n,k,m,ans=inf,a[N],imp[N],col[N],dp[N][(1<<K)];
vector<pair<int,int> > g[N];
set<pair<int,pair<int,int> > > s;

void upd(int u,int mask,int x){
	//cout<<u<<" "<<mask<<" : "<<x<<endl;
	if(dp[u][mask]<=x) return ;
	s.erase(mp(dp[u][mask],mp(u,mask)));
	dp[u][mask]=x;
	s.insert(mp(dp[u][mask],mp(u,mask)));	
}

main(){
	fill(col,col+N,-1);
	cin>>n>>k>>m;
	f(i,0,k){
		cin>>imp[i];
		col[imp[i]]=i;
	}
	f(i,0,m){
		int u,v,c;
		cin>>u>>v>>c;
		g[u].pb(mp(v,c));
		g[v].pb(mp(u,c));
	}
	f(i,1,n+1){
		f(mask,0,(1<<k)){
			dp[i][mask]=inf;
		}
	}
	f(i,1,n+1){
		if(col[i]==-1){
			dp[i][0]=0;
		}
		else{
			dp[i][(1<<col[i])]=0;
		}
	}
	f(i,1,n+1){
		f(mask,0,(1<<k)){
			s.insert(mp(dp[i][mask],mp(i,mask)));
		}
	}
	while(s.size()){
		pair<int,pair<int,int> > p=*s.begin();
		int u=p.S.F,mask=p.S.S;
		//cout<<"NEW : "<<endl;
		//cout<<u<<" "<<mask<<" : "<<p.F<<endl;
		s.erase(p);
		f(i,0,g[u].size()){
			f(nmask,0,(1<<k)){
				upd(u,mask|nmask,dp[u][mask]+dp[g[u][i].F][nmask]+g[u][i].S);
				upd(g[u][i].F,mask|nmask,dp[u][mask]+dp[g[u][i].F][nmask]+g[u][i].S);
			}
		}
		//cout<<endl;
	}
	f(i,1,n+1){
		minm(ans,dp[i][(1<<k)-1]);
	}
	cout<<ans;
}

Compilation message

cities.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~
cities.cpp: In function 'int main()':
cities.cpp:7:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   72 |   f(i,0,g[u].size()){
      |     ~~~~~~~~~~~~~~~            
cities.cpp:72:3: note: in expansion of macro 'f'
   72 |   f(i,0,g[u].size()){
      |   ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Incorrect 3 ms 6576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 856 ms 95968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 7960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1803 ms 145920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5132 ms 246384 KB Output isn't correct
2 Halted 0 ms 0 KB -