From 8f40c6ae9e70bf6d05131439a79f058b67ae0992 Mon Sep 17 00:00:00 2001 From: cyp0633 Date: Thu, 22 Jul 2021 21:03:33 +0800 Subject: [PATCH] =?UTF-8?q?CSP=205-3=20queen=20=E8=89=AF=E5=BF=83=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSP-Training/5/3-queen.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 CSP-Training/5/3-queen.cpp diff --git a/CSP-Training/5/3-queen.cpp b/CSP-Training/5/3-queen.cpp new file mode 100644 index 0000000..8cd772c --- /dev/null +++ b/CSP-Training/5/3-queen.cpp @@ -0,0 +1,35 @@ +//良心树 / CF1143C Queen +#include +#include +#include +using namespace std; +bool unrespectedByAll[100001], unrespectParent[100001]; +int main() +{ + int n, parent, respect, i; + bool printed = false; + memset(unrespectedByAll, 1, sizeof(unrespectedByAll)); + scanf("%d", &n); + for (i = 1; i <= n; i++) + { + scanf("%d %d", &parent, &respect); + if (parent != -1) + { + unrespectedByAll[parent] &= respect; + unrespectParent[i] = respect; + } + } + for (i = 1; i <= n; i++) + { + if (unrespectParent[i] && unrespectedByAll[i]) + { + printf("%d ", i); + printed = true; + } + } + if (!printed) + { + printf("-1"); + } + return 0; +} \ No newline at end of file