L2-023. 图着色问题

https://www.patest.cn/contests/gplt/L2-023

#include<bits/stdc++.h>

using namespace std;

int main()

{

    int ma[505][505],v,e,k,bb[505];

    set<int>st;

    memset(ma,0,sizeof(ma));

    cin>>v>>e>>k;

    for(int i = 0;i < e;i++)

    {

        int a,b;

        cin>>a>>b;

        ma[a][b] = 1;

        ma[b][a] = 1;

    }

    int m;

    cin>>m;

    while(m–)

    {

        int flag = 1;

        for(int i = 1;i <= v;i++)

        {

            cin>>bb[i];

            st.insert(bb[i]);

        }

        if(st.size() != k)

        {

            flag = 0;

        }

        else

        {

                for(int i = 1;i <= v && flag;i++)

                {

                    for(int j = i + 1;j <= v &&flag;j++)

                    {

                        if(ma[i][j] == 1)

                        {

                            if(bb[i] == bb[j])

                            flag = 0;

                        }

                    }

                }

        }

        if(flag == 0)

        {

            cout<<“No”<<endl;

        }

        else

        {

            cout<<“Yes”<<endl;

        }

        st.clear();

    }

    return 0;

}

点赞