Skip to content

Instantly share code, notes, and snippets.

@shiponcs
Created November 5, 2019 05:47
Show Gist options
  • Save shiponcs/1630ac45be79e6edef77a03664f88b6e to your computer and use it in GitHub Desktop.
Save shiponcs/1630ac45be79e6edef77a03664f88b6e to your computer and use it in GitHub Desktop.
Timus- 1106. Two Teams
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, t, tt;
cin >> n;
vector< int > friends[n + 1];
for(int i = 1; i <= n; i++){
while(cin >> t){
if(t) friends[i].push_back(t);
else break;
}
}
int st[n + 1] = {0};
for(int i = 1; i <= n; i++){
if(st[i] == 0){
st[i] = 1;
for(int x: friends[i])
if(st[x] == 0)
st[x] = 2;
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
if(st[i] == 1){
ans++;
}
}
cout << ans << '\n';
for(int i = 1; i <= n; i++)
if(st[i] == 1)
cout << i << ' ';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment