10004-bicoloring // BFS

Source: Internet
Author: User

Analysis:Because this question only gives two colors, we can use BFS as an opportunistic method to determine that the level of two knots in wood is the same. But it seems like this is the case.Four color map theorem,Therefore, four colors can be dropped. Three colors are considered. Who can tell me! (Think about it in the evening, okay)

The following is an example of ACCode:

# Include <cstdio> # include <cstring> using namespace STD; const int maxn = 210; int map [maxn] [maxn]; int nodelevel [maxn]; bool vis [maxn] [maxn]; bool vis [maxn]; int Q [maxn * maxn]; int n, m; void BFS (INT s) {int front = 1; int rear = 1; Q [Front] = s; vis [s] = true; while (front <= rear) {int v = Q [Front ++]; for (INT I = 0; I <n; I ++) {If (Map [v] [I]) {If (! Vis [I]) {vis [I] = true; vis [v] [I] = true; nodelevel [I] = nodelevel [v] + 1; Q [++ rear] = I;} If (nodelevel [v] = nodelevel [I] &! Vis [I] [v]) {printf ("not bicolorable. \ n "); Return ;}}} printf (" bicolorable. \ n "); return;} int main () {While (scanf (" % d ", & N) {memset (VIS, false, sizeof (VIS); memset (VIS, false, sizeof (VIS); memset (MAP, 0, sizeof (MAP); memset (nodelevel, 0, sizeof (nodelevel); scanf ("% d", & M); For (INT I = 0; I <m; I ++) {int p, q; scanf ("% d", & P, & Q); map [p] [Q] = map [Q] [p] = 1 ;} BFS (0);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.