Ultraviolet A 11748-rigging elections
Question Link
N-person election: Give the priority of M-person voters for everyone. Now you want to win for the C-person and ask if you can
Idea: If a can win B for two people, build a side of a-> B. Then the question is, can c be used as the root node as a tree and directly use DFS?
Code:
# Include <cstdio> # include <cstring> # include <vector> using namespace STD; const int n = 105; int n, m, C, a [n] [N], vis [N]; vector <int> G [N]; int DFS (int u) {vis [u] = 1; int ans = 1; for (INT I = 0; I <G [u]. size (); I ++) if (! Vis [G [u] [I]) ans + = DFS (G [u] [I]); Return ans;} int main () {While (~ Scanf ("% d", & N, & M, & C) & N) {int U; For (INT I = 1; I <= N; I ++) g [I]. clear (); For (INT I = 1; I <= m; I ++) for (Int J = 1; j <= N; j ++) {scanf ("% d", & U); A [I] [u] = J ;}for (INT I = 1; I <= N; I ++) {for (Int J = I + 1; j <= N; j ++) {int CNT = 0; For (int K = 1; k <= m; k ++) {if (a [k] [I] <A [k] [J]) CNT ++; If (CNT> M/2) break ;} if (CNT> M/2) g [I]. push_back (j); else G [J]. push_back (I) ;}} memset (VIS, 0, Sizeof (VIS); printf ("% s \ n", DFS (c) = n? "Yes": "no");} return 0 ;}
Ultraviolet A 11748-rigging elections (DFS)