File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ def main ():
4+ input = sys .stdin .readline
5+ t = int (input ())
6+
7+ for _ in range (t ):
8+ phoneNumber = []
9+ n = int (input ())
10+ for i in range (n ):
11+ phoneNumberStr = input ().strip ()
12+ phoneNumber .append (phoneNumberStr )
13+
14+ phoneNumber .sort ()
15+
16+ isOk = True
17+ for i in range (len (phoneNumber )- 1 ):
18+ if phoneNumber [i + 1 ].startswith (phoneNumber [i ]):
19+ print ("NO" )
20+ isOk = False
21+ break
22+ if isOk :
23+ print ("YES" )
24+
25+ if __name__ == '__main__' :
26+ main ()
Original file line number Diff line number Diff line change 1+ import sys
2+ from collections import defaultdict
3+
4+ def main ():
5+ input = sys .stdin .readline
6+ N = int (input ())
7+
8+ graph = defaultdict (dict )
9+
10+ for _ in range (N ):
11+ food = input ().strip ().split ()
12+ K = int (food [0 ])
13+ foods = food [1 :]
14+
15+ current_node = graph
16+ for f in foods :
17+ if f not in current_node :
18+ current_node [f ] = defaultdict (dict )
19+ current_node = current_node [f ]
20+
21+ dfs (graph , 0 )
22+
23+ def dfs (node , depth ):
24+ for key in sorted (node .keys ()):
25+ print ('--' * depth + key )
26+ dfs (node [key ], depth + 1 )
27+
28+ if __name__ == '__main__' :
29+ main ()
You can’t perform that action at this time.
0 commit comments