Submission #578180

# Submission time Handle Problem Language Result Execution time Memory
578180 2022-06-16T07:18:00 Z idas Stranded Far From Home (BOI22_island) C++11
0 / 100
520 ms 56656 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=2e5+10;
int n, m, c[N], par[N], sm[N];
vi ad[N], ok[N];
map<int, vi> col;
set<int> dif;
bool can[N];

int fnd(int u)
{
    return par[u]=par[u]==u?u:fnd(par[u]);
}

void mrg(int a, int b)
{
    a=fnd(a); b=fnd(b);
    if(a==b) return;
    if(sz(ok[a])>sz(ok[b])) ok[a].swap(ok[b]);
    for(auto x : ok[a]) ok[b].pb(x);
    sm[b]+=sm[a];
    par[a]=b;
}

int main()
{
    setIO();
    cin >> n >> m;
    FOR(i, 0, n) cin >> c[i], dif.insert(c[i]), col[c[i]].pb(i), par[i]=i, ok[i].pb(i), can[i]=true, sm[i]=c[i];
    FOR(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        ad[a-1].pb(b-1);
        ad[b-1].pb(a-1);
    }
    for(auto val : dif){
        for(auto i : col[val]){
            for(auto x : ad[i]){
                if(c[x]>c[i]) continue;
                x=fnd(x);
                if(sm[x]<c[i]){
                    while(sz(ok[x])){
                        can[ok[x].back()]=false;
                        ok[x].pop_back();
                    }
                }
                mrg(i, x);
            }
        }
    }
    FOR(i, 0, n) cout << can[i];
}

Compilation message

island.cpp: In function 'void setIO(std::string)':
island.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Incorrect 8 ms 10108 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Incorrect 290 ms 56656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Incorrect 520 ms 56320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 276 ms 25936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Incorrect 8 ms 10108 KB Output isn't correct
5 Halted 0 ms 0 KB -