Submission #1305620

#TimeUsernameProblemLanguageResultExecution timeMemory
1305620thesentroStranded Far From Home (BOI22_island)C++20
0 / 100
443 ms51432 KiB
/*
 _____ _          ____             _             
|_   _| |__   ___/ ___|  ___ _ __ | |_ _ __ ___  
  | | | '_ \ / _ \___ \ / _ \ '_ \| __| '__/ _ \ 
  | | | | | |  __/___) |  __/ | | | |_| | | (_) |
  |_| |_| |_|\___|____/ \___|_| |_|\__|_|  \___/ 
*/
 
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
ll mod = 1e9+7;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1)
            res = (res*a)%mod;
        a = (a*a)%mod;
        b>>=1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (y==0)
        return x;
    return gcd(y, x%y);
}
ll maxi =202020;
vector<vector<ll>>g(maxi);
vector<ll>vis(maxi, 0), v(maxi);
ll cnt=0;
vector<ll>lst;
ll dfs(ll x)
{
    vis[x] = 1;
    cnt += v[x];
    lst.push_back(x);
    for (auto i:g[x])
    {
        if (vis[i]==0)
            dfs(i);
    }
}
void solve()
{   
    ll n,m;
    cin>>n>>m;
    for (int i=1 ; i<=n ;i++) cin>>v[i];
    set<ll>s;
    for (int i=1 ; i<=n ;i++)
        s.insert(v[i]);
    vector<ll>vs;
    for (auto i:s) vs.push_back(i);
    ll idx = 1;
    map<ll,vector<pair<ll,ll>>>mp;
    for (int i=1 ; i<=m ;i++)
    {
        ll x,y;
        cin>>x>>y;
        mp[max(v[x], v[y])].push_back({x,y});
        mp[v[x]].push_back({x,x});
        mp[v[y]].push_back({y,y});
    }
    vector<ll>res(n+1,1);
    for (auto it:mp)
    {
        if (idx==vs.size()) break;
        for (auto i:it.second)
        {
            g[i.first].push_back(i.second);
            g[i.second].push_back(i.first);
        }
        vis.assign(n+1, 0);
        for (int i=1 ; i<=n ;i++)
        {
            if (vis[i]==0)
            {
                cnt = 0;
                lst.clear();
                dfs(i);
                if (cnt<vs[idx])
                {
                    for (auto j:lst)
                        res[j] = 0;
                }
            }
        }
        idx++;
    }
    for (int i=1 ; i<=n ;i++) cout<<res[i];
}
int main()
{
    ll tt = 1;
    // cin>>tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

Compilation message (stderr)

island.cpp: In function 'long long int dfs(long long int)':
island.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
#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...