Algorithm


B. PFAST Inc.
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.

To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

Input

The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m () — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.

Output

The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.

Examples
input
Copy
3 1
Petya
Vasya
Masha
Petya Vasya
output
Copy
2
Masha
Petya
input
Copy
3 0
Pasha
Lesha
Vanya
output
Copy
3
Lesha
Pasha
Vanya



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <vector>
#include <map>
#include <set>

std::vector<bool> getBinaryVector(long x){
    std::vector<bool> v;
    while(x > 0){v.push_back(x % 2); x /= 2;}
    return v;
}

int countOnes(std::vector<bool> v){
    int cnt(0);
    for(int p = 0; p < v.size(); p++){cnt += v[p];}
    return cnt;
}

int main(){

    int n, m; std::cin >> n >> m;
    std::map<std::string, int> nmp;
    std::vector<std::string> nmv(n);
    for(int p = 0; p < n; p++){std::string x; std::cin >> x; nmp[x] = p; nmv[p] = x;}
    std::set < std::pair<int, int> > enset;
    for(int p = 0; p < m; p++){
        std::string x, y; std::cin >> x >> y;
        int u = nmp[x], v = nmp[y];
        enset.insert(std::make_pair(u, v));
        enset.insert(std::make_pair(v, u));
    }


    std::set<std::string> clique;
    long B = (1 << n);
    for(long p = 1; p < B; p++){
        std::vector<bool> bv = getBinaryVector(p);
        bool possible(true);
        for(int x = 0; x < bv.size(); x++){
            if(!possible){break;}
            if(!bv[x]){continue;}
            for(int y = x + 1; y < bv.size(); y++){
                if(!bv[y]){continue;}
                if(enset.count(std::make_pair(x, y))){possible = false; break;}
            }
        }

        if(possible){
            int cnt = countOnes(bv);
            if(cnt > clique.size()){
                clique.clear();
                for(int p = 0; p < bv.size(); p++){
                    if(!bv[p]){continue;}
                    clique.insert(nmv[p]);
                }
            }
        }
    }


    std::cout << clique.size() << std::endl;
    for(std::set<std::string>::iterator it = clique.begin(); it != clique.end(); it++){std::cout << (*it) << std::endl;}

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 1
Petya
Vasya
Masha
Petya Vasya

Output

x
+
cmd
2
Masha
Petya
Advertisements

Demonstration


Codeforces Solution-B. PFAST Inc.-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+