Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - using System;
 - using System.Collections.Generic;
 - using System.IO;
 - namespace prD {
 - class Program {
 - #if ONLINE_JUDGE
 - private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
 - private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
 - #else
 - private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
 - private static readonly StreamReader reader = new StreamReader(@"..\..\input");
 - #endif
 - static void Main(string[] args) {
 - int n = NextInt();
 - int[] ans = new int[n];
 - int[,] a = new int[n, 2];
 - int i1 = 0;
 - for (int i = 0; i < n; i++) {
 - a[i, 0] = NextInt();
 - a[i, 1] = NextInt();
 - if (i == 0)
 - continue;
 - if (a[i, 0] == 1) {
 - if (a[i, 1] == a[0, 0] || a[i, 1] == a[0, 1]) {
 - i1 = i;
 - }
 - }
 - else if (a[i, 1] == 1) {
 - if (a[i, 0] == a[0, 0] || a[i, 0] == a[0, 1]) {
 - i1 = i;
 - }
 - }
 - }
 - ans[0] = 1;
 - ans[1] = a[i1, 0] == 1 ? a[i1, 1] : a[i1, 0];
 - for (int i = 0; i < n - 2; i++) {
 - int a0 = a[ans[i] - 1, 0];
 - int a1 = a[ans[i] - 1, 1];
 - ans[i + 2] = a0 == ans[i + 1] ? a1 : a0;
 - }
 - for (int i = 0; i < n; i++) {
 - writer.Write(ans[i]);
 - writer.Write(' ');
 - }
 - writer.Flush();
 - #if !ONLINE_JUDGE
 - writer.Close();
 - #endif
 - }
 - private static int NextInt() {
 - int c;
 - int res = 0;
 - do {
 - c = reader.Read();
 - if(c == -1)
 - return res;
 - } while(c != '-' && (c < '0' || c > '9'));
 - int sign = 1;
 - if(c == '-') {
 - sign = -1;
 - c = reader.Read();
 - }
 - res = c - '0';
 - while(true) {
 - c = reader.Read();
 - if(c < '0' || c > '9')
 - return res * sign;
 - res *= 10;
 - res += c - '0';
 - }
 - }
 - private static long NextLong() {
 - int c;
 - long res = 0;
 - do {
 - c = reader.Read();
 - if(c == -1)
 - return res;
 - } while(c != '-' && (c < '0' || c > '9'));
 - int sign = 1;
 - if(c == '-') {
 - sign = -1;
 - c = reader.Read();
 - }
 - res = c - '0';
 - while(true) {
 - c = reader.Read();
 - if(c < '0' || c > '9')
 - return res * sign;
 - res *= 10;
 - res += c - '0';
 - }
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment