QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#115996#2045. Pathological PathsNYCU_gAwr_gurA#0 0ms0kbPython31.9kb2023-06-27 21:27:552023-06-27 21:27:57

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-27 21:27:57]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-06-27 21:27:55]
  • Submitted

answer

class Node:
    def __init__(self, par, root = False):
        self.end = False
        self.cls = {
            '.': self,
            '..': par,
        }
        # if not end:
        #     self.cls['index.html'] = Node(self, True)

    # def __repr__(self):
    #     return id(self)

    # def __str__(self):
    #     s = ''
    #     for word in self.cls:
    #         s += word + '\n'
    #         for line in str(self.cls[word]).splitlines():
    #             s += '  ' + line + '\n'
    #     return s

    def go(self, word):
        if word not in self.cls:
            o = Node(self)
            self.cls[word] = o
        return self.cls[word]

    def get(self, words):
        if len(words) == 0:
            if self.end:
                return self
            return self.cls.get('index.html')
        if self.end:
            return None
        word, *words = words
        if not word:
            return self.cls.get('index.html')
        nxt = self.cls.get(word)
        if nxt is None:
            return None
        return nxt.get(words)

def split(path):
    words = path.split('/')[1:]
    return words

with open('D.txt') as f:
    while True:
        n, m = map(int, f.readline().strip().split())
        if n == 0 and m == 0:
            break

        d = Node(None, True)
        for _ in range(n):
            path = f.readline().strip()
            words = split(path)
            c = d
            for word in words:
                c = c.go(word)
            c.end = True
        # print(str(d))

        for _ in range(m):
            p1 = split(f.readline().strip())
            p2 = split(f.readline().strip())
            n1 = d.get(p1)
            n2 = d.get(p2)
            # print(_)
            # print(p1, n1)
            # print(p2, n2)
            if n1 is None or n2 is None or not n1.end or not n2.end:
                print('not found')
            elif n1 == n2:
                print('yes')
            else:
                print('no')


詳細信息

Test #1:

score: 0
Runtime Error

input:

5 6
/home/ACM/index.html
/ICPC/index.html
/ICPC/general.html
/ICPC/japanese/index.html
/ICPC/secret/confidential/2005/index.html
/home/ACM/
/home/ICPC/../ACM/
/ICPC/secret/
/ICPC/secret/index.html
/ICPC
/ICPC/../ICPC/index.html
/ICPC
/ICPC/general.html
/ICPC/japanese/.././
/ICPC/japanese/./../
/home...

output:


result: