<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

172. eXam
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard
output: standard



In Russia school pupils must do some exams before leaving school. Among others, they must do two "selective" exams. This means that school provides a list of available subjects; each pupil selects two different subjects from this list and is going to do this exams. According to rules, pupil isn't allowed to do both exams at the same day, so the school must schedule the exams, i.e. provide some days when pupils will be able to do exams.

One school does not want to warn teachers too much. They want to schedule all the exams into two days in such way that exams on some subjects are on the first day, and exams on all other (and only on them) are on second. You are to write a program, which will determine, if it is possible to schedule exams in this way so that all pupils will be able to do all their selected exams.

Input
On the first line of input there are two integers N and M (1<=N<=200, 1<=M<=30000) - the number of available subjects and the number of pupils. Then M lines follows; on i-th of them there are two integers - the numbers of exams, which were selected by i-th pupil. Exams are numerated from 1 to N.

Output
If the solution exists, write on the first line of output only one word "yes". On the second line write the total number of exams, which must be held on first day, and on the third line - the numbers of subjects of this exams. If there exist several solutions, output any. If no solution exists, write to output only one word "no".

Sample test(s)

Input
4 4
1 2
3 4
2 4
1 3

Output
yes
2
1 4
Author:	NNSU#2 team
Resource:	Lazurny olympiad in informatics
Date:	July-August 2002

<|response|>
1. Abridged problem statement  
   Given N subjects (numbered 1…N) and M pupils, each pupil chooses exactly two different subjects. We must assign each subject to one of two days (Day 1 or Day 2) so that no pupil has both of their chosen exams on the same day. If such an assignment exists, print “yes,” the number of subjects on Day 1, and the list of those subjects; otherwise print “no.”

2. Key observations  
   • Each subject can be viewed as a vertex in an undirected graph.  
   • Each pupil selecting subjects u and v imposes an edge (u,v) meaning u and v must be on different days.  
   • We need to label vertices with two “colors” (day 1 vs. day 2) so that every edge joins vertices of opposite colors.  
   • A graph is 2-colorable in this way exactly when it is bipartite.  
   • Checking bipartiteness and constructing a 2-coloring can be done by BFS or DFS in O(N + M).

3. Full solution approach  
   a) Read N and M.  
   b) Build an adjacency list adj of size N, then for each pupil’s pair (u,v) add v to adj[u] and u to adj[v], converting to 0-based indices.  
   c) Create an array color[0…N−1], initialized to −1 (meaning “unvisited”).  
   d) For each vertex i from 0 to N−1, if color[i] is −1, do a BFS from i:  
      – Assign color[i] = 0 and push i into a queue.  
      – While the queue is not empty, pop a vertex u. For each neighbor v in adj[u]:  
        • If color[v] is −1, set color[v] = 1 − color[u] and enqueue v.  
        • If color[v] == color[u], there is a conflict → graph is not bipartite → print “no” and exit.  
   e) If all components are processed with no conflict, the graph is bipartite. Collect all vertices i with color[i] == 0 (these will go on Day 1).  
   f) Print “yes,” then the size of this Day-1 list, then the list of these subject numbers in 1-based form.

4. C++ implementation
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m;
vector<vector<int>> adj;

void read() {
    cin >> n >> m;
    adj.assign(n, {});
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

bool is_bipartite(vector<int>& color) {
    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(color[i] != -1) {
            continue;
        }
        color[i] = 0;
        q.push(i);
        while(!q.empty()) {
            int u = q.front();
            q.pop();
            for(int v: adj[u]) {
                if(color[v] == -1) {
                    color[v] = 1 - color[u];
                    q.push(v);
                } else if(color[v] == color[u]) {
                    return false;
                }
            }
        }
    }
    return true;
}

void solve() {
    // Each pupil's two subjects must fall on different days, so model subjects
    // as vertices and pupils as edges: a valid two-day split is exactly a
    // 2-colouring of this graph. BFS-colour every component; if any edge joins
    // two same-coloured subjects the graph is not bipartite and no schedule
    // exists. Otherwise the subjects coloured 0 form the first day's exams.

    vector<int> color(n, -1);
    if(is_bipartite(color)) {
        cout << "yes\n";
        vector<int> a;
        for(int i = 0; i < n; i++) {
            if(color[i] == 0) {
                a.push_back(i + 1);
            }
        }

        cout << a.size() << '\n';
        cout << a << '\n';
    } else {
        cout << "no\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

5. Python implementation with detailed comments  
```python
import sys
from collections import deque

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    # Number of subjects, number of pupils
    n = int(next(it))
    m = int(next(it))

    # Build adjacency list (0-based)
    adj = [[] for _ in range(n)]
    for _ in range(m):
        u = int(next(it)) - 1
        v = int(next(it)) - 1
        adj[u].append(v)
        adj[v].append(u)

    # color[i] = -1 means unvisited; 0/1 are the two days
    color = [-1] * n

    # BFS to check bipartiteness from a given start vertex
    def bfs(start):
        queue = deque([start])
        color[start] = 0
        while queue:
            u = queue.popleft()
            for v in adj[u]:
                if color[v] == -1:
                    color[v] = 1 - color[u]
                    queue.append(v)
                elif color[v] == color[u]:
                    # Conflict found
                    return False
        return True

    # Process each connected component
    for i in range(n):
        if color[i] == -1:
            if not bfs(i):
                print("no")
                return

    # If bipartite, gather all subjects colored 0 for Day 1
    day1 = [i + 1 for i in range(n) if color[i] == 0]
    print("yes")
    print(len(day1))
    print(*day1)

if __name__ == "__main__":
    main()
```