Problem:


パトロール

文久２（1862）年、会津の殿様が京都守護職を命ぜられました。京都守護職とは治安の悪化した幕末の京都を守る大切な役目です。幕府や他の藩と分担して市中をパトロールしなければなりません。ところがいざ分担ルートを決める段になって、家臣の中でも有名な頑固者の古老から以下のような注文がつきました。

大変なことになりました。殿様といえどもこの家臣の言い分を無視するわけにはいきません。分担ルートの選択によっては、「武士の面目が立たない」ということになってしまいます。

ということで、スタート地点、ゴール地点、交差点の情報を入力として、上の三つの条件を満たすかどうかを判定するプログラムを作って、殿様に献上してください。

スタート地点を 1、ゴール地点を2、その他の交差点を 3 以上の整数で表します。1つの道路は、その道が結ぶ1組の交差点番号で表します。なお、交差点の数は 100 以下とし、全ての交差点からスタート地点およびゴール地点への経路がそれぞれ一つ以上あるものとします。

入力

複数のデータセットが与えられます。各データセットは以下の形式で与えられます。

a1 b1
a2 b2
：
：
0 0

各行の２つの整数は、交差点 ai と交差点 bi とをつなぐ道路が存在することを示します。
ai と bi がともに 0 のとき交差点情報の入力の終わりを示します。

データセットの数は50を超えません。

出力

各データセットに対して、武士の面目が立つ場合（三つの条件を満たす場合）OK、それ以外の場合（三つの条件を満たさない場合）NG と１行に出力してください。

Sample Input

1 3
3 4
3 5
3 6
4 6
4 7
4 7
5 6
6 7
5 8
5 8
6 8
6 9
7 9
8 9
9 2
0 0
1 3
3 4
3 4
4 2
0 0

Output for the Sample Input

OK
NG



Sample input:
1 3
3 4
3 5
3 6
4 6
4 7
4 7
5 6
6 7
5 8
5 8
6 8
6 9
7 9
8 9
9 2
0 0
1 3
3 4
3 4
4 2
0 0


Sample output:
OK
NG

Submission status: Wrong Answer

Solution code:
import sys

def solve(dic):
    odd = 0
    for k in dic:
        if dic[k] % 2:
            odd += 1
        if odd == 3:
            return "NG"
    return "OK"

di = {}
for s in sys.stdin:
    data = []
    a,b = map(int,s.split())
    if a == b == 0:
        print solve(di)
        di = {}
        continue
    try: di[a] += 1
    except: di[a] = 1
    try: di[b] += 1
    except: di[b] = 1

Submission status: Wrong Answer

Solution code:
import sys

def solve(lis):
    for e in lis[3:]:
        if e%2:
            return "NG"
    return "OK"

li = [0]*102
for s in sys.stdin:
    a,b = map(int,s.split())
    if a == b == 0:
        print solve(li)
        li = [0]*102
        continue
    li[a] += 1
    li[b] += 1

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin
targ = {}
for d in data:
    temp = d.split(' ')
    if temp[0] == temp[1] == 0:
        for k in targ.keys():
            if targ[k] % 2 != 0:
                print("NG")
                break
        else:
            print("OK")
    else:
        targ[temp[0]] = targ.get(temp[0],0) + 1
        targ[temp[1]] = targ.get(temp[1],0) + 1

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin
targ = {}
for d in data:
    temp = d.split(' ')
    if temp[0] == temp[1] == 0:
        for k in targ.keys():
            if targ[k] % 2 != 0:
                print("NG")
                targ = {}
                break
        else:
            targ = {}
            print("OK")
    else:
        targ[temp[0]] = targ.get(temp[0],0) + 1
        targ[temp[1]] = targ.get(temp[1],0) + 1

Submission status: Wrong Answer

Solution code:
import sys

ipt = []
for line in sys.stdin:
  ipt.append(line)
dic = {}

for i in xrange(len(ipt)):
  s = ipt[i]
  a,b = map(int, s.split())
  if a==b==0:
    if len(dic) == 0:
      print "OK"
    else:
      print "NG"
    continue
  if a != 1:
    if a in dic:
      del dic[a]
    else:
      dic[a] = True
  if b != 2:
    if b in dic:
      del dic[b]
    else:
      dic[b] = True

Submission status: Wrong Answer

Solution code:
import sys

ipt = []
for line in sys.stdin:
  ipt.append(line)
dic = {}

for i in xrange(len(ipt)):
  s = ipt[i]
  a,b = map(int, s.split())
  if a==b==0:
    if len(dic) == 0:
      print "OK"
    else:
      print "NG"
    dic = {}
    continue
  if a != 1:
    if a in dic:
      del dic[a]
    else:
      dic[a] = True
  if b != 2:
    if b in dic:
      del dic[b]
    else:
      dic[b] = True

Submission status: Wrong Answer

Solution code:
c=[0]*100
while 1:
    try:a,b=map(int,input().split())
    except:break
    c[a-1]+=1;c[b-1]+=1
    if a==0:
        for i in range(2,100):
            if c[i]&1:print('NG');break
        else:print('OK')
        c=[0]*100

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# adjacent list
M = []
for i in range(105):
    M.append([])

def solve(M):
    odd_num = 0
    even_num = 0

    for m in M:
        if len(m) % 2 == 0:
            even_num += 1
        else:
            odd_num += 1

    if odd_num == 0 or odd_num == 2:
        print('OK')
    else:
        print('NG')

for s in sys.stdin:
    a, b = map(int, s.split())
    if a == b == 0:
        solve(M)

        # reset
        M = []
        for i in range(105):
            M.append([])
    else:
        a -= 1
        b -= 1
        M[a].append(b)
        M[b].append(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# adjacent list
M = []
for i in range(105):
    M.append([])

def solve(M):
    odd_num = 0
    even_num = 0

    for m in M:
        if len(m) % 2 == 0:
            even_num += 1
        else:
            odd_num += 1

    # semi-Eulerlian graph
    if odd_num == 2:
        print('OK')
    else:
        print('NG')

for s in sys.stdin:
    a, b = map(int, s.split())
    if a == b == 0:
        solve(M)

        # reset
        M = []
        for i in range(105):
            M.append([])
    else:
        a -= 1
        b -= 1
        M[a].append(b)
        M[b].append(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0086

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    for line in sys.stdin:
        routes = []
        a, b = map(int, line.split())
        if a == 0 and b == 0:
            break
        while a != 0 or b!= 0:
            routes.append([a, b])
            a, b = map(int, input().split())

        degree = [0] * 101
        for a, b in routes:
            degree[a] += 1
            degree[b] += 1
        odds = [x for x in degree if x%2==1]
        # evens = [x for x in degree if x%2==0]

        if len(odds) == 0 or len(odds) == 2:
            print('OK')
        else:
            print('NG')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
while True:
    try:
        v=[]
        a,b=(int(i) for i in input().split())
        while a!=0 or b!=0:
            while b>len(v):
                v.append(0)
            v[a-1]+=1
            v[b-1]+=1
            a,b=(int(i) for i in input().split())
        a=2
        while a<len(v) and v[a]%2==0:
            a+=1
        if a<len(v):
            print("NG")
        else:
            print("OK")
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):


    for node in node_list:
        odd_num_counter = 0

        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] != 1 and node_data_list[i][1] != 2:
                if node_data_list[i][0] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
                else :
                    tmp_dic[node_data_list[i][0]] = 1

                if node_data_list[i][1] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
                else :
                    tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0

        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] != 1 and node_data_list[i][1] != 2:
                if node_data_list[i][0] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
                else :
                    tmp_dic[node_data_list[i][0]] = 1

                if node_data_list[i][1] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
                else :
                    tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())

    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0

        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] != 1 and node_data_list[i][0] != 2:
                if node_data_list[i][0] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
                else :
                    tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] != 1 and node_data_list[i][1] != 2:
                if node_data_list[i][1] in tmp_dic.keys():
                    tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
                else :
                    tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())

    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        print(node_list)
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print(odd_num_counter)
            print("OK")
        else :
            print(odd_num_counter)

            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())

    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())

    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 or odd_num_counter == 0 :
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])

    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1
                if odd_num_counter > 2:
                    print("NG")
                    break;

        if odd_num_counter == 2 :
            print("OK")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2 or odd_num_counter == 0:
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])


    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            if node_data_list[i][0] in tmp_dic.keys():
                tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1
            else :
                tmp_dic[node_data_list[i][0]] = 1

            if node_data_list[i][1] in tmp_dic.keys():
                tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1
            else :
                tmp_dic[node_data_list[i][1]] = 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):

    for node in node_list:
        odd_num_counter = 0
        for dic_value in node.values():
            if dic_value % 2 != 0:
                odd_num_counter = odd_num_counter + 1

        if odd_num_counter == 2:
            print("OK")
        else :
            print("NG")


if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}
    tmp_dic = defaultdict(int)

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])

    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            tmp_dic[node_data_list[i][0]] += 1
            tmp_dic[node_data_list[i][1]] += 1

        count_lists.append(tmp_dic.copy())
    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
data_list = []

for line in sys.stdin:
    data_list.append(list(map(int, line.split())))

def is_half_euler_graph(node_list):
    isBool = True
    for node in node_list:
        for dic_key, dic_value in node.items():
            if dic_key != 1 and dic_key != 2:
                if dic_value % 2 != 0:
                    isBool = False
                    break
            else :
                if dic_value % 2 == 0:
                    isBool = False
                    break
        if isBool :
            print("OK")
        else :
            print("NG")



if __name__ == '__main__' :
    node_data_lists = []
    tmp_list = []
    count_lists = []
    tmp_dic = {}
    tmp_dic = defaultdict(int)

    for i in range(0, len(data_list)):
        if data_list[i][0] == 0 and data_list[i][1] == 0:
            node_data_lists.append(tmp_list[:])
            tmp_list.clear()
        else :
            tmp_list.append(data_list[i])

    for node_data_list in node_data_lists :
        tmp_dic.clear()
        for i in range(0, len(node_data_list)):
            tmp_dic[node_data_list[i][0]] += 1
            tmp_dic[node_data_list[i][1]] += 1

        count_lists.append(tmp_dic.copy())

    is_half_euler_graph(count_lists)

Submission status: Wrong Answer

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
l = 0
while True:
    if l >= len(N):
        break

    points = [0 for ii in range(101)]
    while True:
        a,b = [int(i) for i in N[l].split()]
        if a== 0 and b == 0:
            flag = True
            for i in range(3,101):
                if points[i] != (points[i] // 2) * 2:
                    flag = False
                    break
            if points[1] + points[2] != ((points[1] + points[2]) // 2) * 2:
                flag = False
            if flag:
                print("OK")
            else:
                print("NG")
            l += 1
            break
        else:
            points[a] += 1
            points[b] += 1
        l += 1

Submission status: Wrong Answer

Solution code:
while True:
    try:
        d = {}
        while True:
            a, b = map(int, input().split())
            if a == 0:
                break
            if a in d:
                d[a] += 1
            else:
                d[a] = 1
            if b in d:
                d[b] += 1
            else:
                d[b] = 1
        if d[1]%2 == 1 and d[2]%2 == 1:
            del d[1], d[2]
            for node in d:
                if d[node]%2 == 1:
                    print("NG")
                    break
            else:
                print("OK")
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        d = {}
        while True:
            a, b = map(int, input().split())
            if a == 0:
                break
            if a in d:
                d[a] += 1
            else:
                d[a] = 1
            if b in d:
                d[b] += 1
            else:
                d[b] = 1
        if d[1]%2 == 1 and d[2]%2 == 1:
            del d[1], d[2]
            for node in d:
                if d[node]%2 == 1:
                    print("NG")
                    break
            else:
                print("OK")
        elif d[1]%2 == 0 and d[2]%2 == 0:
            del d[1], d[2]
            for node in d:
                if d[node]%2 == 1:
                    print("NG")
                    break
            else:
                print("OK")
        else:
            print("NG")
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        d = {}
        while True:
            a, b = map(int, input().split())
            if a == 0:
                break
            if a in d:
                d[a] += 1
            else:
                d[a] = 1
            if b in d:
                d[b] += 1
            else:
                d[b] = 1
        if d[1]%2 == d[2]%2 or d[1] == 1 or d[2] ==1:
            del d[1], d[2]
            for node in d:
                if d[node]%2 == 1:
                    print("NG")
                    break
            else:
                print("OK")
        else:
            print("NG")
    except:
        break

Submission status: Wrong Answer

Solution code:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        v[0] = 2
        for i in ab:
            v[i] += 1
        even = 0
        odd = 0
        for i in v:
            if i % 2 == 0:
                even += 1
            else:
                odd += 1
        if odd == 0 or (odd == 2 and v[1]%2 == v[2]%2 == 1):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp

Submission status: Wrong Answer

Solution code:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        v[0] = 2
        for i in ab:
            v[i] += 1
        even = 0
        odd = 0
        for i in v:
            if i % 2 == 1:
                odd += 1
        if odd == 0 or (odd == 2 and (v[1] % 2) == (v[2] % 2) == 1):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp

Submission status: Wrong Answer

Solution code:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        for i in ab:
            v[i] += 1
        print(v)
        odd = 0
        for i in v:
            if i % 2 == 1:
                odd += 1
        if odd == 0 or (odd == 2 and ((v[1] % 2) == (v[2] % 2) == 1)):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp

Submission status: Wrong Answer

Solution code:
import sys
ab = []
for line in sys.stdin:
    temp = list(map(int, line.split()))
    if temp == [0, 0]:
        v = [0 for i in range(max(ab)+1)]
        for i in ab:
            v[i] += 1
        odd = 0
        for i in v:
            if i % 2 == 1:
                odd += 1
        if odd == 0 or (odd == 2 and ((v[1] % 2) == (v[2] % 2) == 1)):
            print('OK')
        else:
            print('NG')
        ab = []
    else:
        ab += temp

Submission status: Wrong Answer

Solution code:
import sys
v=[0]*101
for e in sys.stdin:
 a,b=map(int,e.split())
 if a==0:
  print(['ng','ok'][1&v[1]and 1&v[2]and sum(x&1 for x in v[3:])==0])
  v=[0]*101
 v[a]+=1;v[b]+=1

Submission status: Wrong Answer

Solution code:
import sys
v=[0]*101
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['NG','OK'][v[1]&1*v[2]&1*sum(x&1 for x in v)==2])
  v=[0]*101

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Tax Rate Changed
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp? id=1192&lang=jp
 # 右中央
temp = [0] * 50
while True:
    a,b = map(int, input().strip().split(' '))
    boolean = True
    if a == 0 and b == 0:
        for i in range(len(temp)-3):
            if temp[i+3]%2 == 1:
                boolean = False
        if boolean == True:
            print("OK")
        else:
            print("NG")
        break
    temp[int(a)] += 1
    temp[int(b)] += 1

temp = [0] * 50
while True:
    a,b = map(int, input().strip().split(' '))
    boolean = True
    if a == 0 and b == 0:
        for i in range(len(temp)-3):
            if temp[i+3]%2 == 1:
                boolean = False
        if boolean == True:
            print("OK")
        else:
            print("NG")
        break
    temp[int(a)] += 1
    temp[int(b)] += 1

Submission status: Wrong Answer

Solution code:
import sys
R = lambda:map(int,raw_input().split())

def eulerPath(graph):
    odd = [x for x in graph.keys() if len(graph[x])&1]

    if len(odd) > 2: return -1

    stack = [graph.keys()[0]]
    path  = []

    while stack:
        v = stack[-1]
        if graph[v]:
            u = graph[v].pop(0)
            stack.append(u)
            graph[u].remove(v)
        else:
            path.append(stack.pop(0))

    return path

graph = {}
while 1:
    try:
        a,b = R()
        if not(a or b):
            #print graph
            path = eulerPath(graph)
            if path is -1: print 'NG'
            else: print 'OK'
            graph = {}
        else:
            if not a in graph.keys():
                graph[a] = [b]
            else:
                graph[a].append(b)
            if not b in graph.keys():
                graph[b] = [a]
            else:
                graph[b].append(a)
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import sys
R = lambda:map(int,raw_input().split())

def eulerPath(graph):
    odd = [x for x in graph.keys() if len(graph[x])&1]

    if len(odd) > 2: return -1

    stack = [graph.keys()[0]]
    path  = []

    while stack:
        #print stack
        v = stack[-1]
        if graph[v]:
            u = graph[v].pop(0)
            stack.append(u)
            graph[u].remove(v)
            #print graph, stack
        else:
            path.append(stack.pop())

    return path

graph = {}
while 1:
    try:
        a,b = R()
        if not(a or b):
            path = eulerPath(graph)
            if path is -1: print 'NG'
            else: print 'OK'
            graph = {}
        else:
            if not a in graph.keys():
                graph[a] = [b]
            else:
                graph[a].append(b)
            if not b in graph.keys():
                graph[b] = [a]
            else:
                graph[b].append(a)
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        cross=[0]*101
        while True:
            a,b=map(int,raw_input().split())
            if (a,b)==(0,0):
                break
            cross[a]+=1
            cross[b]+=1
        if cross[1]%2==cross[2]%2 and len(filter(lambda x:x%2==1,cross[3:]))==0:
            print "OK"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        cross=[0]*101
        while True:
            a,b=map(int,raw_input().split())
            if (a,b)==(0,0):
                break
            cross[a]+=1
            cross[b]+=1
        print len(filter(lambda x:x%2==1,cross[3:]))
        
        if cross[1]%2==cross[2]%2 and len(filter(lambda x:x%2==1,cross[3:]))==0:
            print "OK"
        else:
            print "NG"
    except:
        break