Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main() {
- int n,m,k;
- cin>>n>>m>>k;
- vector<vector<pair<int,int>>> edges(n);
- vector<int> fish(n);
- vector<int> goal(1<<k,-1);
- vector<vector<bool> > visited(n, vector<bool>(1<<k,false));
- for(int i=0;i<n;i++) {
- int t;
- cin>>t;
- for(int j=0;j<t;j++) {
- int f;
- cin>>f;
- fish[i] |= 1<<(f-1);
- }
- }
- for(int j=0;j<m;j++) {
- int a,b,c;
- cin>>a>>b>>c;a--;b--;
- edges[a].push_back(make_pair(b,c));
- edges[b].push_back(make_pair(a,c));
- }
- priority_queue<tuple<int,int,int>> q;
- q.push(make_tuple(0,0,fish[0]));
- while(!q.empty()) {
- int shop,mask,cost;
- tie(cost,shop,mask) = q.top();
- q.pop();
- if(visited[shop][mask]) continue;
- if(shop==n-1) goal[mask] = -cost;
- visited[shop][mask] = true;
- for(auto edge : edges[shop]) {
- q.push(make_tuple(cost - edge.second, edge.first, mask | fish[edge.first]));
- }
- }
- int best = INT_MAX;
- for(int i=0;i<(1<<k);i++) {
- for(int j=0;j<(1<<k);j++) {
- if((i|j) == (1<<k)-1 && goal[i]>=0 && goal[j]>=0) {
- best = min(best,max(goal[i],goal[j]));
- }
- }
- }
- cout<<best<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement