質問編集履歴
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -126,6 +126,76 @@
|
|
126
126
|
|
127
127
|
int from, to, weight;
|
128
128
|
|
129
|
+
Edge(int from, int to, int weight): from(from), to(to), weight(weight){}
|
130
|
+
|
131
|
+
bool operator <(Edge x) {
|
132
|
+
|
133
|
+
return this->weight < x.weight;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
vector<Edge> es;
|
142
|
+
|
143
|
+
int main(){
|
144
|
+
|
145
|
+
ios::sync_with_stdio(false);
|
146
|
+
|
147
|
+
cin.tie(0);
|
148
|
+
|
149
|
+
int V, E; cin >> V >> E;
|
150
|
+
|
151
|
+
es.resize(E);
|
152
|
+
|
153
|
+
for(int i = 0; i < E; ++i){
|
154
|
+
|
155
|
+
int s, t, weight; cin >> s >>t >> weight;
|
156
|
+
|
157
|
+
es[i] = Edge(s, t, weight);
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
sort(es.begin(), es.end());
|
162
|
+
|
163
|
+
Dsu uf(V);
|
164
|
+
|
165
|
+
int ans = 0;
|
166
|
+
|
167
|
+
for(int i = 0; i < E; ++i){
|
168
|
+
|
169
|
+
if(!uf.issame(es[i].from, es[i].to)){
|
170
|
+
|
171
|
+
ans += es[i].weight;
|
172
|
+
|
173
|
+
uf.merge(es[i].from, es[i].to);
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
cout << ans << endl;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
### 試したこと
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
struct Edgeのところに空のコンストラクタを以下のように設定したところ問題なく通りました。
|
192
|
+
|
193
|
+
```C++
|
194
|
+
|
195
|
+
struct Edge{
|
196
|
+
|
197
|
+
int from, to, weight;
|
198
|
+
|
129
199
|
Edge(){}
|
130
200
|
|
131
201
|
Edge(int from, int to, int weight): from(from), to(to), weight(weight){}
|
@@ -138,78 +208,6 @@
|
|
138
208
|
|
139
209
|
};
|
140
210
|
|
141
|
-
|
142
|
-
|
143
|
-
vector<Edge> es;
|
144
|
-
|
145
|
-
int main(){
|
146
|
-
|
147
|
-
ios::sync_with_stdio(false);
|
148
|
-
|
149
|
-
cin.tie(0);
|
150
|
-
|
151
|
-
int V, E; cin >> V >> E;
|
152
|
-
|
153
|
-
es.resize(E);
|
154
|
-
|
155
|
-
for(int i = 0; i < E; ++i){
|
156
|
-
|
157
|
-
int s, t, weight; cin >> s >>t >> weight;
|
158
|
-
|
159
|
-
es[i] = Edge(s, t, weight);
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
sort(es.begin(), es.end());
|
164
|
-
|
165
|
-
Dsu uf(V);
|
166
|
-
|
167
|
-
int ans = 0;
|
168
|
-
|
169
|
-
for(int i = 0; i < E; ++i){
|
170
|
-
|
171
|
-
if(!uf.issame(es[i].from, es[i].to)){
|
172
|
-
|
173
|
-
ans += es[i].weight;
|
174
|
-
|
175
|
-
uf.merge(es[i].from, es[i].to);
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
cout << ans << endl;
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
### 試したこと
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
struct Edgeのところに空のコンストラクタを以下のように設定したところ問題なく通りました。
|
194
|
-
|
195
|
-
```C++
|
196
|
-
|
197
|
-
struct Edge{
|
198
|
-
|
199
|
-
int from, to, weight;
|
200
|
-
|
201
|
-
Edge(){}
|
202
|
-
|
203
|
-
Edge(int from, int to, int weight): from(from), to(to), weight(weight){}
|
204
|
-
|
205
|
-
bool operator <(Edge x) {
|
206
|
-
|
207
|
-
return this->weight < x.weight;
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
};
|
212
|
-
|
213
211
|
```
|
214
212
|
|
215
213
|
|