Submission #1152309

#TimeUsernameProblemLanguageResultExecution timeMemory
1152309Sandarach151Odašiljači (COCI20_odasiljaci)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; vector<pair<double, pair<int, int> > > vect; vector<int> sze; vector<int> link; int find(int a){ while(a!=link[a]){ a = link[a]; } return a; } bool same(int a, int b){ return find(a)==find(b); } void unite(int a, int b){ a = find(a); b = find(b); if(sze[a]<sze[b]){ swap(a, b); } link[b]=a; sze[a]+=sze[b]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; pair<int, int> points[n]; sze.assign(n, 1); for(int i=0; i<n; i++){ link.push_back(i); } for(int i=0; i<n; i++){ int a, b; cin >> a >> b; points[i] = make_pair(a, b); } for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ vect.push_back(make_pair(sqrt(pow(points[i].first-points[j].first, 2) + pow(points[i].first-points[j].first, 2)), make_pair(i, j))); } } sort(vect.begin(), vect.end()); int cnt = 0; double ans = 0; for(int i=0; i<vect.size(); i++){ int a = vect[i].second.first; int b = vect[i].second.second; if(!same(a, b)){ unite(a, b); cnt += 1; ans = vect[i].first / 2; } if(cnt==n*(n-1)/2) break; } cout << ans << '\n'; return 0; }

Compilation message (stderr)

odasiljaci.cpp:6:13: error: 'std::vector<int> link' redeclared as different kind of entity
    6 | vector<int> link;
      |             ^~~~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/11/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:43,
                 from odasiljaci.cpp:1:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
odasiljaci.cpp: In function 'int find(int)':
odasiljaci.cpp:9:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
    9 |         while(a!=link[a]){
      |                        ^
odasiljaci.cpp:9:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
    9 |         while(a!=link[a]){
      |               ~^~~~~~~~~
odasiljaci.cpp:10:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   10 |                 a = link[a];
      |                           ^
odasiljaci.cpp:10:27: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   10 |                 a = link[a];
      |                     ~~~~~~^
      |                           |
      |                           int (*)(const char*, const char*) noexcept
odasiljaci.cpp: In function 'void unite(int, int)':
odasiljaci.cpp:25:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   25 |         link[b]=a;
      |               ^
odasiljaci.cpp:25:16: error: assignment of read-only location '*(link + ((sizetype)b))'
   25 |         link[b]=a;
      |         ~~~~~~~^~
odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:37:22: error: request for member 'push_back' in 'link', which is of non-class type 'int(const char*, const char*) noexcept'
   37 |                 link.push_back(i);
      |                      ^~~~~~~~~