-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergesortstring.cpp
More file actions
224 lines (179 loc) · 4.67 KB
/
Copy pathmergesortstring.cpp
File metadata and controls
224 lines (179 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// #include<iostream>
// using namespace std;
// void swap(int *a, int *b) {
// int temp = *a;
// *a = *b;
// *b = temp;
// }
// int partition(int start, int end, int arr[]) {
// int pivot = arr[start];
// int count = 0;
// for (int i = start + 1; i <= end; i++) {
// if (arr[i] < pivot) {
// count++;
// }
// }
// int pivotindex = start + count;
// swap(&arr[start], &arr[pivotindex]);
// int i = start;
// int j = end;
// while (i < pivotindex && j > pivotindex) {
// while (arr[i] < pivot) {
// i++;
// }
// while (arr[j] > pivot) {
// j--;
// }
// if (arr[i] <= pivot && arr[j] > pivot) {
// swap(&arr[i++], &arr[j--]);
// }
// }
// return pivotindex;
// }
// void quicksort(int start, int end, int arr[]) {
// if (start >= end) {
// return;
// }
// int pivotindex = partition(start, end, arr);
// // Print array after each partition (each pass)
// cout << "Pass: ";
// for (int i = 0; i <= end; i++) {
// cout << arr[i] << " ";
// }
// cout << endl;
// quicksort(start, pivotindex - 1, arr);
// quicksort(pivotindex + 1, end, arr);
// }
// int main() {
// int n;
// cout << "Enter size of array: ";
// cin >> n;
// cout << "Enter elements of array: ";
// int arr[n];
// for (int i = 0; i < n; i++) {
// cin >> arr[i];
// }
// quicksort(0, n - 1, arr);
// cout << "Sorted array: ";
// for (int i = 0; i < n; i++) {
// cout << arr[i] << " ";
// }
// cout << endl;
// return 0;
// }
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Edge {
int src, dest, weight;
};
bool compareEdges(Edge a, Edge b) {
return a.weight < b.weight;
}
void kruskalMST(vector<Edge>& edges, int n) {
sort(edges.begin(), edges.end(), compareEdges);
vector<vector<int> > adjMatrix(n, vector<int>(n, 0));
int totalCost = 0;
vector<pair<int, int> > mstEdges;
for (size_t i = 0; i < edges.size(); i++) {
int src = edges[i].src;
int dest = edges[i].dest;
int weight = edges[i].weight;
if (adjMatrix[src][dest] == 0 && adjMatrix[dest][src] == 0) {
adjMatrix[src][dest] = weight;
adjMatrix[dest][src] = weight;
mstEdges.push_back({src, dest});
totalCost += weight;
}
}
cout << "Edge \tWeight\n";
for (size_t i = 0; i < mstEdges.size(); i++) {
cout << mstEdges[i].first << " - " << mstEdges[i].second << "\t"
<< adjMatrix[mstEdges[i].first][mstEdges[i].second] << "\n";
}
cout << "\nTotal cost of MST: " << totalCost << endl;
}
int main() {
int n = 5;
vector<Edge> edges;
edges.push_back(Edge{0, 1, 2});
edges.push_back(Edge{0, 3, 6});
edges.push_back(Edge{1, 2, 3});
edges.push_back(Edge{1, 3, 8});
edges.push_back(Edge{1, 4, 5});
edges.push_back(Edge{2, 4, 7});
edges.push_back(Edge{3, 4, 9});
kruskalMST(edges, n);
return 0;
}
{
"model": "image-to-image",
"input_data": {
"image_url": "https://runwayml.com/assets/sample_image.jpg",
"style": "vivid"
}
}
{
"status": "success",
"generated_media_url": "https://runwayml.com/output/generated_media4567",
"message": "Media generated successfully."
}
{
"status": "success",
"models": [
{
"model_id": "image-to-image",
"description": "Transforms input images into new styles or variations."
},
{
"model_id": "text-to-image",
"description": "Generates images from textual descriptions."
}
]
}
{
"user_id": "user123",
"media_url": "https://runwayml.com/output/generated_media4567",
"media_name": "Vivid Landscape"
}
{
"status": "success",
"message": "Media saved successfully to your account."
}
{
"genre": "chillwave",
"mood": "relaxed",
"duration": "3:30"
}
{
"status": "success",
"generated_music_url": "https://soundraw.io/output/musicTrack1234",
"message": "Music track generated successfully."
}
{
"status": "success",
"genres": [
{
"genre_id": "chillwave",
"description": "Relaxing and mellow electronic music with soft beats."
},
{
"genre_id": "lo-fi",
"description": "Low-fidelity music with a calming vibe."
},
{
"genre_id": "pop",
"description": "Upbeat and catchy music suited for mainstream audiences."
}
]
}
{
"user_id": "user456",
"music_url": "https://soundraw.io/output/musicTrack1234",
"music_name": "Chillwave Dream"
}
{
"status": "success",
"message": "Music saved successfully to your account."
}