Submission #1098893

# Submission time Handle Problem Language Result Execution time Memory
1098893 2024-10-10T09:45:55 Z razivo Stranded Far From Home (BOI22_island) C++14
0 / 100
179 ms 20120 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
    long long find(long long p, vector<long long> &dsu) {
        if(p==dsu[p]) return p;
        long long u = find(dsu[p],dsu);
        dsu[p]=u;
        return u;
    }
void un(long long a,long long b,vector<long long> &dsu,vector<long long> &ev) {
        a=find(a,dsu);
        b=find(b,dsu);
        dsu[b]=a;
        ev[a]+=ev[b];
    }
int main()
{
    long long n,m;
    cin>>n>>m;
        vector<long long> v(n),ev(n),dsu(n);
        vector<pair<long long,long long>> s;
    for (long long i = 0; i < n; ++i) {
        long long x; cin>>x;
        ev[i]=x;
        v[i]=x;
        s.push_back({x,i});
        dsu[i]=i;
    }
        sort(s.begin(), s.end());
    vector<pair<pair<long long,long long>,pair<long long,long long>>> ed;
    for (long long i = 0; i < m; ++i) {
        long long x,y; cin>>x>>y; x--; y--;
        if(v[x]>v[y]) swap(x,y);
        ed.push_back({{v[x],v[y]},{x,y}});
    }
        sort(ed.begin(),ed.end());
    for (auto [u,t]:ed) {
        auto [a,b] = t;
            if(ev[find(a,dsu)]>=v[b]) un(a,b,dsu,ev);
    }
        long long ma = find(s[n-1].second,dsu);
    for (long long i = 0; i < n; ++i) {
        if(ma==find(i,dsu))cout<<"1";
        else cout<<"0";
    }
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:38:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for (auto [u,t]:ed) {
      |               ^
island.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |         auto [a,b] = t;
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 155 ms 20024 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 170 ms 20120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 179 ms 19980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -