Submission #714623

# Submission time Handle Problem Language Result Execution time Memory
714623 2023-03-25T06:42:58 Z murad_2005 Stranded Far From Home (BOI22_island) C++14
0 / 100
152 ms 12096 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pllll pair<ll, ll>
#define size(v) v.size()
#define all(v) v.begin(), v.end()
#define INF 2e9
#define f first
#define s second

using namespace std;

int Sum;
vector<int>s;
vector<vector<int>>g;
vector<bool>visited;

bool comp(int i, int j){
    return s[i] < s[j];
}

void dfs_sub1(int node){
    visited[node] = true;
    for(int to : g[node]){
        if(!visited[to] && Sum >= s[to]){
            Sum += s[to];
            dfs_sub1(to);
        }
    }
}

void Sub1(int n, int m, int SUM){
    string Res = "";
    for(int i = 1; i <= n; ++i){
        Sum = s[i];
        dfs_sub1(i);
        if(Sum == SUM){
            Res += '1';
        }else{
            Res += '0';
        }
        visited.assign(n + 1, false);
    }
    cout << Res << "\n";
}


void solve(){
    int n, m, SUM = 0;
    cin >> n >> m;
    g.resize(n + 1);
    s.resize(n + 1);
    visited.assign(n + 1, false);
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
        SUM += s[i];
    }
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 1; i <= n; ++i){
        sort(all(g[i]), comp);
    }
    if(n <= 2000 && m <= 2000){
        Sub1(n, m, SUM);
    }

}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    // cin >> t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
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 Incorrect 134 ms 12096 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 152 ms 12016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 139 ms 12032 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -