Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #define NMax 101
- using namespace std;
- ifstream fin("bipartit1.in");
- ofstream fout("bipartit1.out");
- vector <int> a[NMax];
- int uz[NMax];
- int n;
- void Citire()
- {
- int m, x, y;
- fin >> n >> m;
- while(fin >> x >> y)
- {
- a[x].push_back(y);
- a[y].push_back(x);
- }
- }
- void DFS(int x)
- {
- for(int i = 0; i < a[x].size(); i++)
- if(uz[a[x][i]] == 0)
- {
- uz[a[x][i]] = 3 - uz[x];
- DFS(a[x][i]);
- }
- }
- int main()
- {
- Citire();
- uz[1] = 1;
- DFS(1);
- for(int i = 1; i <= n; i++)
- for(int j = 0; j < a[i].size(); j++)
- if(uz[i] == uz[a[i][j]])
- {
- fout << "NU";
- return 0;
- }
- fout << "DA\n";
- for(int i = 1; i <= n; i++)
- if(uz[i] == 1)
- fout << i << " ";
- fout << "\n";
- for(int i = 1; i <= n; i++)
- if(uz[i] == 2)
- fout << i << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment