제출 #904147

#제출 시각아이디문제언어결과실행 시간메모리
904147vjudge1Odašiljači (COCI20_odasiljaci)C++17
70 / 70
992 ms87400 KiB
#include<bits/stdc++.h> using namespace std; struct Dsu { vector<int> parent, rank, size; Dsu(int N) { parent.resize(N); rank.resize(N); size.resize(N, 1); for (int i = 0; i < N; i++){ parent[i] = i; } } bool isSameSet(int i, int j){ return findSet(i) == findSet(j); } int findSet(int i) { if(parent[i] == i){ return i; }else{ return parent[i] = findSet(parent[i]); } } void unionSet(int i, int j){ int x = findSet(i); int y = findSet(j); if (x != y){ if (rank[x] > rank[y]){ parent[y] = x; size[x] += size[y]; }else if(rank[x] < rank[y]){ parent[x] = y; size[y] += size[x]; }else{ parent[x] = y; size[y] += size[x]; rank[y]++; } } } int getSize(int i){ return size[findSet(i)]; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(12); int n; cin >> n; vector <pair<int,int>> antena; for (int i = 0; i < n; i++){ int a, b; cin >> a >> b; antena.push_back({a,b}); } vector<vector<long double>> edges, edges_mst; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ long double d = antena[i].first - antena[j].first; long double e = antena[i].second - antena[j].second; long double w = (sqrt((d*d)+(e*e))/2.0); edges.push_back({w, i, j}); } } /* for(int i = 0; i < m; i++){ int a, b, w; cin >> a >> b; a--; b--; edges.push_back({w, a, b}); } */ // Ordeno las aristas por peso // (es importante que el peso sea el primer elemento de cada arista) sort(edges.begin(), edges.end()); long double maximo; Dsu dsu(n); // Kruskal long double costo_total = 0; for(int i = 0; i < edges.size(); i++){ long double w = edges[i][0]; int a = edges[i][1]; int b = edges[i][2]; if(!dsu.isSameSet(a, b)){ // Si a y b no estan en la misma componente conexa dsu.unionSet(a, b); // entonces las uno costo_total += w; edges_mst.push_back({w, a, b}); maximo = w; } } // Finalmente se obtiene el costo minimo para conectar todos los nodos cout << maximo << "\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:67:33: warning: narrowing conversion of 'i' from 'int' to 'long double' [-Wnarrowing]
   67 |             edges.push_back({w, i, j});
      |                                 ^
odasiljaci.cpp:67:33: warning: narrowing conversion of 'i' from 'int' to 'long double' [-Wnarrowing]
odasiljaci.cpp:67:36: warning: narrowing conversion of 'j' from 'int' to 'long double' [-Wnarrowing]
   67 |             edges.push_back({w, i, j});
      |                                    ^
odasiljaci.cpp:67:36: warning: narrowing conversion of 'j' from 'int' to 'long double' [-Wnarrowing]
odasiljaci.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int i = 0; i < edges.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
odasiljaci.cpp:93:37: warning: narrowing conversion of 'a' from 'int' to 'long double' [-Wnarrowing]
   93 |             edges_mst.push_back({w, a, b});
      |                                     ^
odasiljaci.cpp:93:37: warning: narrowing conversion of 'a' from 'int' to 'long double' [-Wnarrowing]
odasiljaci.cpp:93:40: warning: narrowing conversion of 'b' from 'int' to 'long double' [-Wnarrowing]
   93 |             edges_mst.push_back({w, a, b});
      |                                        ^
odasiljaci.cpp:93:40: warning: narrowing conversion of 'b' from 'int' to 'long double' [-Wnarrowing]
#Verdict Execution timeMemoryGrader output
Fetching results...