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: Accepted

Solution code:
#coding:utf-8
while 1:
    try:
        #初期化
        key=[0]*101
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        if(key[1]%2 == 1 and key[2]%2==1 and len(filter(lambda x:x%2==1,key[3:]))==0):
            print "OK"
        else:
            print "NG"
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        lst = []
        ju = True
        while True:
            a, b = map(int, input().split())
            if a == 0:
                break
            lst.append(a)
            lst.append(b)

        anslst = []
        for i in range(1, max(lst)+1):
            anslst.append(lst.count(i))

        if anslst[0]%2 == 0 or anslst[1]%2 == 0:
            ju = False

        else:
            for i in anslst[2:]:
                if i%2 !=0:
                    ju = False
                    break    

        if ju:
            print('OK')
        else:
            print('NG')

    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    L = 100
    G = [[] for i in range(L)]
    for line in readlines():
        a, b = map(int, line.split())
        if a != 0 != b:
            G[a-1].append(b-1)
            G[b-1].append(a-1)
            continue
        ok = 1
        if len(G[0]) % 2 == 0 and len(G[1]) % 2 == 0:
            ok = 0
        else:
            for i in range(2, L):
                if len(G[i]) == 0:
                    continue
                if len(G[i]) % 2 == 1:
                    ok = 0
        write("OK\n" if ok else "NG\n")

        G = [[] for i in range(L)]
solve()

Submission status: Accepted

Solution code:
while 1:
    try:
        v = [0]*101
        a, b = map(int, input().split())
        v[a] += 1
        v[b] += 1

        while 1:
            a, b = map(int, input().split())
            if a == 0:
                break
            v[a] += 1
            v[b] += 1

        flag = 0
        for num in v[3:]:
            if num % 2 == 1:
                flag = 1

        if v[1] % 2 and v[2] % 2 and (not flag):
            print('OK')
        else:
            print('NG')

    except:
        break

Submission status: Accepted

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' if c[0] & 1 and c[1] & 1 else 'NG')
        c = [0] * 100

Submission status: Accepted

Solution code:
def ap(i):
    if len(root)<i:
        for _ in range(i-len(root)):root.append(0)
    root[i-1]=[0,1][root[i-1]==0]
while 1:
    try:
        root=[0,0]
        while 1:
            n,m=map(int,input().split())
            if n==m==0:break
            ap(n)
            ap(m)
        if root.pop(0)+root.pop(0)==2 and sum(root)==0:print("OK")
        else:print("NG")
    except:break

Submission status: Accepted

Solution code:
cntlist = [0] * 102

while 1:
    try:
        a, b = map(int, input().split())
    except:
        break

    cntlist[a] += 1
    cntlist[b] += 1
    if a == 0 and b == 0:
        for cnt in cntlist[3:]:
            if cnt % 2 == 1:
                print("NG")
                break
        else:
            print("OK" if cntlist[1] & 1 and cntlist[2] & 1 else "NG")
        cntlist = [0] * 102

Submission status: Accepted

Solution code:
import sys
try:
    while True:
        edges = [0]*101
        while True:
            a, b = map(int, input().split())
            if not a:
                break
            edges[a] += 1
            edges[b] += 1

        if edges[1]%2 == 1 and edges[2]%2 == 1 and all(n%2==0 for n in edges[3:]):
            print("OK")
        else:
            print("NG")
except EOFError:
    pass

Submission status: Runtime Error

Solution code:
import sys
data = sys.stdin.readlines()
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] = targ.get(temp,0) + 1

Submission status: Runtime Error

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):
    while True:
        routes = []
        while True:
            a, b = map(int, input().split())
            if a == 0 and b == 0:
                break
            routes.append([a, b])
        if len(routes) < 1:
            quit()

        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: Runtime Error

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
            v[b]+=1
        a=0
        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: Runtime Error

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(['OK','NG'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)-2])
  v=[0]*101

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Tax Rate Changed
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp? id=1192&lang=jp
 # 右中央
while True:
    a,b,c = map(int, input().strip().split(' '))
    temp = 0
    if a == 0 and b == 0 and c == 0:
        break
    for i in range(1, c):
        for j in range(i, c):
            if i*(100+a)//100 + j*(100+a)//100 == c:
                if temp < i*(100+b)//100 + j*(100+b)//100:
                    temp = i*(100+b)//100 + j*(100+b)//100
    print(temp)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Tax Rate Changed
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp? id=1192&lang=jp
 # 右中央
from sys import stdin
 
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")
    temp[int(a)] += 1
    temp[int(b)] += 1

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
for line in stdin:
    start, end = (int(s) for s in line.split())
    if start or end:
        cnt[start] += 1
        cnt[end] += 1
    else:
        assert cnt[1] == 1
        assert cnt[2] == 1
        eulerian_graph = sum(i % 2 for i in cnt.values()) == 2
        print('OK' if eulerian_graph else 'NG')
        cnt.clear()

Submission status: Runtime Error

Solution code:
while True:
    try:
        path = [0]*100
        while True:
            a,b = map(int, raw_input().split())
            if a == 0: break
            path[a-1] += 1; path[b-1] += 1
        if (path[0]%2 == path[1]%2 == 1 ):
            print "OK"
        else:
            print "NG"
    except:
        break

Submission status: Runtime Error

Solution code:
while True:
    try:
        path = [0]*100
        while True:
            a,b = map(int, raw_input().split())
            if a == 0: break
            path[a-1] += 1; path[b-1] += 1
        if (path[0]%2 == 1 and path[1]%2 == 1 ):
            print "OK"
        else:
            print "NG"
    except:
        break

Submission status: Runtime Error

Solution code:
#coding:utf-8
        #初期化
        key=[0]*101
        flag = 0;
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        for v in key:
            if v%2 == 1:
                flag+=1
        if(flag == 2):
            print "OK"
        else:
            print "NG"

Submission status: Runtime Error

Solution code:
#coding:utf-8
while 1:
    try:
        #初期化
        key=[0]*101
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        if(key[1]%2 == 1 and key[2]%2==1 and len(filter(lambda x:x%2=1,key[3:]))==0):
            print "OK"
        else:
            print "NG"
    except:
        break