Submission #1098891

# Submission time Handle Problem Language Result Execution time Memory
1098891 2024-10-10T09:42:00 Z razivo Stranded Far From Home (BOI22_island) C++14
0 / 100
165 ms 12408 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
    int find(int p, vector<int> &dsu) {
        if(p==dsu[p]) return p;
        int u = find(dsu[p],dsu);
        dsu[p]=u;
        return u;
    }
void un(int a,int b,vector<int> &dsu,vector<int> &ev) {
        a=find(a,dsu);
        b=find(b,dsu);
        dsu[b]=a;
        ev[a]+=ev[b];
        ev[a] = min(1000000000,ev[a]);
    }
int main()
{
    int n,m;
    cin>>n>>m;
        vector<int> v(n),ev(n),dsu(n);
        vector<pair<int,int>> s;
    for (int i = 0; i < n; ++i) {
        int 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<int,int>,pair<int,int>>> ed;
    for (int i = 0; i < m; ++i) {
        int 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);
    }
        int ma = find(s[n-1].second,dsu);
    for (int 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:39:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |     for (auto [u,t]:ed) {
      |               ^
island.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |         auto [a,b] = t;
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 344 KB Output isn't correct
5 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 Incorrect 147 ms 12408 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 159 ms 12268 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 165 ms 12180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -