Submission #1002385

#TimeUsernameProblemLanguageResultExecution timeMemory
1002385AndreyStranded Far From Home (BOI22_island)C++14
10 / 100
1096 ms21680 KiB
#include<bits/stdc++.h>
using namespace std;

vector<int> haha[200001];

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,a,b;
    cin >> n >> m;
    vector<int> wow(n+1);
    vector<pair<int,int>> wut(0);
    for(int i = 1; i <= n; i++) {
        cin >> wow[i];
        wut.push_back({wow[i],i});
    }
    sort(wut.begin(),wut.end());
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    vector<int> ans(n+1);
    vector<bool> bruh(n+1,true);
    vector<int> no(n+1,-1);
    for(int i = 1; i <= n; i++) {
        if(bruh[i] == false) {
            continue;
        }
        priority_queue<pair<int,int>> idk;
        long long sb = 0;
        idk.push({-wow[i],i});
        vector<int> yeah(0);
        while(!idk.empty()) {
            a = -idk.top().first;
            b = idk.top().second;
            idk.pop();
            if(no[b] == i) {
                continue;
            }
            if(wow[b] > sb && b != i) {
                break;
            }
            if(ans[b]) {
                ans[i] = 1;
                break;
            }
            sb+=wow[b];
            yeah.push_back(b);
            no[b] = i;
            for(int v: haha[b]) {
                if(no[v] != i) {
                    idk.push({-wow[v],v});
                }
            }
        }
        if(yeah.size() == n) {
            ans[i] = 1;
        }
        if(ans[i] == 0) {
            for(int j = 0; j < yeah.size(); j++) {
                bruh[yeah[j]] = 0;
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:59:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |         if(yeah.size() == n) {
      |            ~~~~~~~~~~~~^~~~
island.cpp:63:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int j = 0; j < yeah.size(); j++) {
      |                            ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...