Submission #714618

# Submission time Handle Problem Language Result Execution time Memory
714618 2023-03-25T06:41:50 Z Toxtaq Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 36780 KB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>g;
vector<int>num;
vector<bool>vis, chosen;
bool cmp(int a, int b){
    return num[a] < num[b];
}
long long cnt = 0;
vector<int>tmp;
void dfs(int u){
    vis[u] = 1;
    vector<int>tempo;
    for(int v : g[u]){
        if(!chosen[v] && cnt >= num[v]){
            cnt += num[v];
            chosen[v] = 1;
            tempo.push_back(v);
        }
        else if(cnt < num[v]){
            tmp.push_back(v);
        }
    }
    for(int v : tempo){
        if(!vis[v]){
            dfs(v);
        }
    }
    for(int i = 0;i < tmp.size();++i){
        int v = tmp[i];
        if(!chosen[v] && cnt >= num[v]){
            cnt += num[v];
            chosen[v] = 1;
            dfs(v);
        }
    }
}
int main()
{
    int n, m;
    cin >> n >> m;
    g.resize(n + 1);
    num.resize(n + 1);
    vis.resize(n + 1);
    chosen.resize(n + 1);
    for(int i = 1;i <= n;++i)cin >> num[i];
    for(int i = 0;i < m;++i){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1;i <= n;++i){
        sort(g[i].begin(), g[i].end(), cmp);
    }
//    for(int i = 1;i <= n;++i){
//        cout << i << ": ";
//        for(int j : g[i]){
//            cout << j << " ";
//        }
//        cout << '\n';
//    }
    string s = "";
    for(int i = 1;i <= n;++i){
        cnt = num[i];
        chosen[i] = 1;
        dfs(i);
        bool ok = 1;
        for(int j = 1;j <= n && ok;++j){
            if(!vis[j]){
                ok = 0;
            }
        }
        for(int j = 1;j <= n;++j){
            vis[j] = 0;
            chosen[j] = 0;
        }
        if(ok)s += '1';
        else s += '0';
    }
    cout << s;
}

Compilation message

island.cpp: In function 'void dfs(int)':
island.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0;i < tmp.size();++i){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 1082 ms 588 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1069 ms 22084 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1086 ms 36780 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1083 ms 13764 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 1082 ms 588 KB Time limit exceeded
5 Halted 0 ms 0 KB -