Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PairArr removeAt(PairArr arr, int i){
- for(; i<size(arr); i++){
- arr.first[i] = arr.first[i+1];
- arr.second[i] = arr.second[i+1];
- }
- arr.n--;
- return arr;
- }
- int main(){
- int n=5;
- int connect = 1;
- Arr main = createArr();
- PairArr pending = createPairArr();
- for(int i=0; i<n; i++){
- int from, to;
- cin >> from;
- cin >> to;
- pending = pushPairArr(pending, from, to);
- }
- int prevSize = size(pending);
- for(int i=0; i<size(pending) && prevSize > 0; i++){
- if(contains(main, pending.first[i]) && ! contains(main, pending.second[i])){
- main = pushArr(main, pending.second[i]);
- pending = removeAt(pending, i);
- i--;
- }
- if(contains(main, pending.second[i]) && ! contains(main, pending.first[i])){
- main = pushArr(main, pending.first[i]);
- pending = removeAt(pending, i);
- i--;
- }
- if(prevSize == size(pending)){
- connect = 0;
- break;
- }
- prevSize = size(pending);
- }
- if(connect){
- "yes"
- }
- else{
- "no"
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement