Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <set>
- #include <map>
- #include <vector>
- #include <string>
- #include <cmath>
- #include <cstring>
- #include <queue>
- #include <stack>
- #include <algorithm>
- #include <sstream>
- using namespace std;
- #define f first
- #define s second
- #define mp make_pair
- #define sz(a) int((a).size())
- #define pb push_back
- #define all(c) (c).begin(),(c).end()
- #define inf int(2e9)
- #define forit(it,S) for(__typeof(S.begin()) it = S.begin(); it != S.end(); ++it)
- #ifdef WIN32
- #define I64d "%I64d"
- #else
- #define I64d "%lld"
- #endif
- typedef pair <int, int> pi;
- int n, m, k, a[60][60], q[60];
- bool u[30], d[60];
- void dfs(int mask, int v){
- u[v] = true;
- if(u[1] ) return;
- for(int i =0; i < n; ++i)
- if((mask & a[v][i]))
- if(!u[i]) dfs(mask, i);
- }
- int main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cin >> k >> n >> m;
- while(m--){
- int u, v, c;
- cin >> u >> v >> c;
- a[u][v] |= (1 << c);
- a[v][u] |= (1 << c);
- }
- int mask = 0, ans = inf;
- for(int i = 0; i < (1 << k); ++i) {
- memset(u, 0, sizeof(u));
- dfs(i, 0);
- if(u[1]){
- int cost = __builtin_popcount(i);
- if(cost < ans) ans = cost, mask = i;
- }
- }
- cout << ans << endl;
- for(int i = 0; i < k; ++i)
- if((mask & (1 << i))) cout << i << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment