File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 98
98
99
99
## Задачи за упражнение
100
100
101
+ - [ The Islander] ( https://www.hackerrank.com/contests/sda-hw-13-2022/challenges/islander/problem )
101
102
- [ Permutations] ( https://leetcode.com/problems/permutations )
102
103
- [ All Paths From Source to Target] ( https://leetcode.com/problems/all-paths-from-source-to-target )
103
104
- [ Reconstruct Itinerary] ( https://leetcode.com/problems/reconstruct-itinerary )
Original file line number Diff line number Diff line change 1
1
## Условия:
2
2
3
+ - [ The Islander] ( https://www.hackerrank.com/contests/sda-hw-13-2022/challenges/islander/problem )
3
4
- [ Permutations] ( https://leetcode.com/problems/permutations )
4
5
- [ All Paths From Source to Target] ( https://leetcode.com/problems/all-paths-from-source-to-target )
5
6
- [ Reconstruct Itinerary] ( https://leetcode.com/problems/reconstruct-itinerary )
Original file line number Diff line number Diff line change
1
+ def dfs (current , visited , graph ):
2
+ for neighbor in graph [current ]:
3
+ if neighbor not in visited :
4
+ visited .add (neighbor )
5
+ dfs (neighbor , visited , graph )
6
+
7
+
8
+ def is_connected (V , graph ):
9
+ start_vertex = 1
10
+ visited = set ([start_vertex ])
11
+
12
+ dfs (start_vertex , visited , graph )
13
+
14
+ return len (visited ) >= V
15
+
16
+
17
+ def check_euler (V , graph ):
18
+ degrees = [0 ] * (V + 1 )
19
+
20
+ for v in graph :
21
+ degrees [v ] = len (graph [v ])
22
+
23
+ count_odd = sum (1 if degree % 2 == 1 else 0 for degree in degrees )
24
+
25
+ if not is_connected (V , graph ):
26
+ return 'none'
27
+
28
+ if count_odd == 0 :
29
+ return 'ecycle'
30
+
31
+ if count_odd == 2 :
32
+ return 'epath'
33
+
34
+ return 'none'
35
+
36
+
37
+ def solve ():
38
+ N , M = map (int , input ().split ())
39
+ graph = {v : [] for v in range (N + 1 )}
40
+
41
+ for _ in range (M ):
42
+ x , y = map (int , input ().split ())
43
+ graph [x ].append (y )
44
+ graph [y ].append (x )
45
+
46
+ result = check_euler (N , graph )
47
+
48
+ return result
49
+
50
+ Q = int (input ())
51
+ for _ in range (Q ):
52
+ print (solve ())
You can’t perform that action at this time.
0 commit comments