Looksery Party
Solution:
Careful analysis will find that everyone will send a message to themselves this condition is very important!
This condition guarantees that there will be a solution, and the solution must start here.
When we get a sequence of guessing answers, assuming that the sequence is not 0, we don't need to invite anyone.
There is a 0 of the time to invite the answer is 0 people, and then to the person in its contact list of the answer to reduce one action, so that the operation may reduce some number to 0, but because everyone can contact themselves, it is necessary to lose all 0, so there must be a solution. Just keep a record of the people we choose.
#include <bits/stdc++.h>using namespacestd;Const intN =109;d eque<int>Q;intA[n], g[n][n], use[n];intN;vector<int>ans;stringSt;intMain () {CIN>>N; for(inti =1; I <= N; ++i) {cin>>St; for(intj =0; J < N; ++j) {G[i][j+1] = (St[j] = ='1' ); } } for(inti =1; I <= N; ++i) {cin>>A[i]; if(A[i] = =0) Q.push_back (i); } while( !Q.empty ()) { intx =Q.front (); Q.pop_front (); if(Use[x])Continue; USE[X]=1; Ans.push_back (x); for(inti =1; I <= N; i++ ) { if(!use[i] &&G[x][i]) { if(--a[i] = =0) Q.push_back (i); } }} cout<< ans.size () <<Endl; for(int&I:ans) {cout<< I <<" "; }}
View Code
Codeforces 549B Looksery Party