Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board CCC Solution 3: Circle of Friends Download Source Code
Author Details Code Information
Cinjection ( Oleksi Derkatch )

Pinned 13 Codes
Posted 8 Coding Articles

Send A Message
View Coders Profile
Language C++
Expires Never
Length 931 Characters (72 Lines)
Password no password
Description

Enjoy Gleb. For other's interested, this solves CCC S3.
  1. #include <fstream>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9.           int friendsWith;
  10. };
  11.  
  12. int main()
  13. {
  14.           ifstream in("S3.in");
  15.           ofstream out("S3.out");
  16.  
  17.           vector<Node> allFriends(10000);
  18.  
  19.           int nFriends(0);
  20.           in>>nFriends;
  21.  
  22.           for (int i=0; i< nFriends; i++)
  23.           {
  24.                     int f1(0);
  25.                     int f2(0);
  26.  
  27.                     in>>f1;
  28.                     in>>f2;
  29.  
  30.                     allFriends[f1].friendsWith = f2;
  31.           }
  32.  
  33.           int f1(0);
  34.           int f2(0);
  35.  
  36.           in>>f1;
  37.           in>>f2;
  38.  
  39.           do
  40.           {
  41.                     int cntFri = allFriends[f1].friendsWith;
  42.  
  43.                     int seperation;
  44.                     seperation = 0;
  45.  
  46.                     for (; cntFri != f2 || cntFri == f1; seperation++)
  47.                     {
  48.                               cntFri = allFriends[cntFri].friendsWith;
  49.                               if (seperation > 10000)
  50.                                         break;
  51.                     }
  52.  
  53.                     if (cntFri != f1 && seperation < 10000)
  54.                     {
  55.                               out<<"Yes "<<seperation<<endl;
  56.                     }
  57.                     else
  58.                     {
  59.                               out<<"No"<<endl;
  60.                     }
  61.  
  62.                     in>>f1;
  63.                     in>>f2;
  64.  
  65.           } while (f1!=0 && f2!=0);
  66.  
  67.           in.close();
  68.           out.close();
  69.  
  70.           return 0;
  71.  
  72. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
 
Webcopper     Posted 148 Days Ago
 
 
wow.. I didn't even understand that... (me and my limited C++ knowledge.. I
totally don't understand this thing.. or the vecotr header either...))
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved