Created
November 5, 2019 05:47
-
-
Save shiponcs/1630ac45be79e6edef77a03664f88b6e to your computer and use it in GitHub Desktop.
Timus- 1106. Two Teams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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