Advertisement
T-D-K

Untitled

Dec 27th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace prD {
  6.     class Program {
  7. #if ONLINE_JUDGE
  8.         private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
  9.         private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
  10. #else
  11.         private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
  12.         private static readonly StreamReader reader = new StreamReader(@"..\..\input");
  13. #endif
  14.  
  15.         static void Main(string[] args) {
  16.             int n = NextInt();
  17.             int[] ans = new int[n];
  18.             int[,] a = new int[n, 2];
  19.             int i1 = 0;
  20.             for (int i = 0; i < n; i++) {
  21.                 a[i, 0] = NextInt();
  22.                 a[i, 1] = NextInt();
  23.                 if (i == 0)
  24.                     continue;
  25.                 if (a[i, 0] == 1) {
  26.                     if (a[i, 1] == a[0, 0] || a[i, 1] == a[0, 1]) {
  27.                         i1 = i;
  28.                     }
  29.                 }
  30.                 else if (a[i, 1] == 1) {
  31.                     if (a[i, 0] == a[0, 0] || a[i, 0] == a[0, 1]) {
  32.                         i1 = i;
  33.                     }
  34.                 }
  35.             }
  36.             ans[0] = 1;
  37.             ans[1] = a[i1, 0] == 1 ? a[i1, 1] : a[i1, 0];
  38.             for (int i = 0; i < n - 2; i++) {
  39.                 int a0 = a[ans[i] - 1, 0];
  40.                 int a1 = a[ans[i] - 1, 1];
  41.                 ans[i + 2] = a0 == ans[i + 1] ? a1 : a0;
  42.             }
  43.             for (int i = 0; i < n; i++) {
  44.                 writer.Write(ans[i]);
  45.                 writer.Write(' ');
  46.             }
  47.             writer.Flush();
  48. #if !ONLINE_JUDGE
  49.             writer.Close();
  50. #endif
  51.         }
  52.         private static int NextInt() {
  53.             int c;
  54.             int res = 0;
  55.             do {
  56.                 c = reader.Read();
  57.                 if(c == -1)
  58.                     return res;
  59.             } while(c != '-' && (c < '0' || c > '9'));
  60.             int sign = 1;
  61.             if(c == '-') {
  62.                 sign = -1;
  63.                 c = reader.Read();
  64.             }
  65.             res = c - '0';
  66.             while(true) {
  67.                 c = reader.Read();
  68.                 if(c < '0' || c > '9')
  69.                     return res * sign;
  70.                 res *= 10;
  71.                 res += c - '0';
  72.             }
  73.         }
  74.         private static long NextLong() {
  75.             int c;
  76.             long res = 0;
  77.             do {
  78.                 c = reader.Read();
  79.                 if(c == -1)
  80.                     return res;
  81.             } while(c != '-' && (c < '0' || c > '9'));
  82.             int sign = 1;
  83.             if(c == '-') {
  84.                 sign = -1;
  85.                 c = reader.Read();
  86.             }
  87.             res = c - '0';
  88.             while(true) {
  89.                 c = reader.Read();
  90.                 if(c < '0' || c > '9')
  91.                     return res * sign;
  92.                 res *= 10;
  93.                 res += c - '0';
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement