#include #include #include #include #define INF 99999999 using namespace std; typedef int weight; typedef vector arr; typedef vector matrix; weight OPT[(1 << 20)][40]; weight minimum_steiner_tree(const vector& T, const matrix &g) { const int n = g.size(); const int numT = T.size(); if (numT <= 1) return 0; matrix d(g); // all-pair shortest for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) d[i][j] = min( d[i][j], d[i][k] + d[k][j] ); for (int S = 0; S < (1 << numT); ++S) for (int x = 0; x < n; ++x) OPT[S][x] = INF; for (int p = 0; p < numT; ++p) // trivial case for (int q = 0; q < n; ++q) OPT[1 << p][q] = d[T[p]][q]; for (int S = 1; S < (1 << numT); ++S) { // DP step if (!(S & (S-1))) continue; for (int p = 0; p < n; ++p) for (int E = 0; E < S; ++E) if ((E | S) == S) OPT[S][p] = min( OPT[S][p], OPT[E][p] + OPT[S-E][p] ); for (int p = 0; p < n; ++p) for (int q = 0; q < n; ++q) OPT[S][p] = min( OPT[S][p], OPT[S][q] + d[p][q] ); } weight ans = INF; for (int S = 0; S < (1 << numT); ++S) for (int q = 0; q < n; ++q) ans = min(ans, OPT[S][q] + OPT[((1 << numT)-1)-S][q]); return ans; } #define _M 99999 int parent[_M],rank[_M],a[_M],b[_M],flags[_M]; pairnode[_M]; int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);} bool unite(int a,int b){ int x=root(a),y=root(b); if(x==y)return false; if(::rank[x] < ::rank[y]){ parent[x]=y; }else{ parent[y]=x; if(::rank[x]==::rank[y])::rank[x]++; } return true; } int main(){ int N,M,T; unordered_map>>m; scanf("%d%d%d",&N,&M,&T); for(int i=0;iv(T); for(int i=0;i imp_back,notimp_back; vectornotimp; int c=0; sort(v.begin(),v.end()); for(auto &e:v){ imp_back.emplace(e,imp_back.size()); for(;c!=e;c++){ notimp.push_back(c); notimp_back.emplace(c,notimp_back.size()); } c++; } for(;c points;//(imp_back); //for(int j=0;jR)break; } } if(j==edges){ int z=root(v[0]); bool f=true; //vだけ判定すれば良い for(auto &e:v)if(root(e)!=z){f=false;break;} if(f)R=r; } } printf("%d\n",R); } }