답안 #908933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908933 2024-01-17T02:29:26 Z Sandarach151 Odašiljači (COCI20_odasiljaci) C++17
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<int> link, sze;

struct Edge{
    int node1;
    int node2;
    long double weight;

    Edge(int a, int b, long double c){
        node1=a;
        node2=b;
        weight=c;
    }
};

bool operator<(const Edge& a, const Edge& b){
    return a.weight<b.weight;
}

int find(int x){
    while(x!=link[x]) x = link[x];
    return x;
}

bool same(int a, int b){
    return find(a)==find(b);
}

void unite(int a, int b){
    if(sze[a]<sze[b]) swap(a, b);
    link[b]=a;
    sze[a]+=sze[b];
}

int main(){
    int n;
    cin >> n;
    pair<long double, long double> arr[n];
    for(int i=0; i<n; i++){
        cin >> arr[i].first >> arr[i].second;
    }
    link.assign(n, 0);
    sze.assign(n, 1);
    for(int i=0; i<n; i++) link[i]=i;
    vector<Edge> vect;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            Edge temp(i, j, sqrt(pow(arr[i].first-arr[j].first, 2)+pow(arr[i].second-arr[j].second, 2))/2);
            vect.push_back(temp);
        }
    }
    sort(vect.begin(), vect.end());
    // for(Edge edge : vect){
    //     cout << edge.node1 << ", " << edge.node2 << ": " << edge.weight << '\n';
    // }
    int cnt = 0;
    long double minn = 0;
    for(int pos = 0; pos<vect.size() && cnt<n-1; pos++){
        if(!same(vect[pos].node1, vect[pos].node2)){
            unite(vect[pos].node1, vect[pos].node2);
            minn = vect[pos].weight;
            cnt++;
        }
    }
    cout << minn << '\n';
    return 0;
}

Compilation message

odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:52:34: error: 'pow' was not declared in this scope
   52 |             Edge temp(i, j, sqrt(pow(arr[i].first-arr[j].first, 2)+pow(arr[i].second-arr[j].second, 2))/2);
      |                                  ^~~
odasiljaci.cpp:52:29: error: 'sqrt' was not declared in this scope
   52 |             Edge temp(i, j, sqrt(pow(arr[i].first-arr[j].first, 2)+pow(arr[i].second-arr[j].second, 2))/2);
      |                             ^~~~
odasiljaci.cpp:62:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int pos = 0; pos<vect.size() && cnt<n-1; pos++){
      |                      ~~~^~~~~~~~~~~~