All pastes #918533 Raw Edit

Mine

public text v1 · immutable
#918533 ·published 2008-02-26 04:31 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace S3
{
	class Program
	{
		class Friendship
		{
			public int friender;
			public int friendee;

			public Friendship(int friender, int friendee)
			{
				this.friender = friender;
				this.friendee = friendee;
			}
		}

		static void Main(string[] args)
		{
			List<Friendship> friends = new List<Friendship>();

			int students = int.Parse(Console.ReadLine());

			for (int i = 0; i < students; i++) {
				string[] assignments = Console.ReadLine().Split(' ');
				friends.Add(new Friendship(int.Parse(assignments[0]), int.Parse(assignments[1])));
			}

			// Generate circle list
			List<List<int>> circles = new List<List<int>>();
			foreach (Friendship friend in friends) {
				// Stop repeated instances of the same circles from popping up
				if (circles.SingleOrDefault(c => c.Contains(friend.friender)) != null)
					continue;
				//nvm, that screws things up
				//nvm*2, that takes for-fucking-ever

				List<int> circle = new List<int>();
				circle.Add(friend.friender);
				circle.Add(friend.friendee);
				ContinueCircle(friends, circle);
				circles.Add(circle);
			}

			do {
				string[] checksS = Console.ReadLine().Split(' ');
				int[] checks = new int[2];
				checks[0] = int.Parse(checksS[0]);
				checks[1] = int.Parse(checksS[1]);
				if (checks[0] == 0 && checks[1] == 0)
					break;

				//List<int> circle = circles.Single(c => c[0] == checks[0]);
				List<int> circle = circles.Single(c => c.Contains(checks[0]));

				RearrangeCircle(circle, checks[0], out circle);

				if (!circle.Contains(checks[1]))
					Console.WriteLine("No");
				else {
					Console.Write("Yes ");

					bool working = true;
					Console.WriteLine(circle.Count(i => {
						if (working && i == checks[1]) {
							working = false;
						}

						return working;
					}) - 1);
				}

			} while (true);
		}

		static void RearrangeCircle(List<int> circle, int num, out List<int> ret)
		{
			int index = circle.IndexOf(num);
			ret = new List<int>();

			for (int i = 0; i < circle.Count; i++) {
				ret.Add(circle[(i + index) % circle.Count]);
			}
		}

		static void ContinueCircle(List<Friendship> friends, List<int> circle)
		{
			foreach (Friendship friend in friends) {
				if (circle[circle.Count - 1] == friend.friender) {
					if (circle[0] == friend.friendee)
						return;

					circle.Add(friend.friendee);

					ContinueCircle(friends, circle);
				}
			}
		}
	}
}