l2-023. Graph coloring Issues

Source: Internet
Author: User

A water problem, O (n^2) walk through the graph again to see if there are any vertex colors that are connected together.
PS: The number of colors needs to be equal to K.
really do not know such a water problem, last year when the game was not full of brain smoke ...

#include <stdio.h> #include <iostream> #include <string.h> using namespace std;
#define MAX 505 int Map[max][max];
int V[max];
int Tc[max];
int V, E, K;
    void check () {int flag = 0;
        for (int i = 1; I <= v; i + +) {if (flag) break;
                for (int j = 0; J <= V; j + +) {if (map[i][j]==1) {if (v[i] = = V[j])
                    {flag = 1;
                Break
    }}}} if (flag) printf ("no\n");
else printf ("yes\n");
    } int main () {scanf ("%d%d%d", &v, &e, &k);
    memset (map, 0, sizeof (map));
    int A, B;
        for (int i = 0; i < e; i + +) {scanf ("%d%d", &a, &b);
        MAP[A][B] = 1;
    Map[b][a] = 1;
    } int flag, NNN;
    scanf ("%d", &nnn);
        for (int i = 0; i < nnn; i + +) {memset (TC, 0, sizeof (TC));
        Flag = 0; for (int j = 1; J <= V ;
            J + +) {scanf ("%d", &v[j]);
                if (tc[v[j]] = = 0) {Tc[v[j]] = 1;
            Flag + +;
        }} if (flag! = k) printf ("no\n");
        else {check ();
}} 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.