Submission #852603

# Submission time Handle Problem Language Result Execution time Memory
852603 2023-09-22T07:48:06 Z 12345678 Stranded Far From Home (BOI22_island) C++17
0 / 100
95 ms 15520 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=2e5+5;
int n, m, sz[2*nx], u, v, dsu[2*nx], cnt;
vector<tuple<int, int, int>> d;
vector<pair<int, int>> p;
bool can[2*nx];

int find(int x)
{
    if (dsu[x]==x) return x;
    return dsu[x]=find(dsu[x]);
}

void dfs(int u)
{
    if (u<=n) return;
    if (!can[u]) can[p[u].first]=can[p[u].second]=0;
    dfs(p[u].first); dfs(p[u].second);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=2*n; i++) can[i]=1, dsu[i]=i;
    for (int i=1; i<=n; i++) cin>>sz[i];
    for (int i=0; i<m; i++) cin>>u>>v, d.push_back({max(sz[u], sz[v]), u, v});
    sort(d.begin(), d.end());
    p.resize(n+1); cnt=n;
    for (int i=0; i<m; i++)
    {
        auto [w, u, v]=d[i];
        int pu=find(u), pv=find(v);
        if (pu==pv) continue;
        if (sz[pu]<w) can[pu]=0;
        if (sz[pv]<w) can[pv]=0;
        dsu[pu]=dsu[pv]=++cnt;
        sz[cnt]=sz[pu]+sz[pv];
        p.push_back({pu, pv});
    }
    dfs(cnt);
    for (int i=1; i<=n; i++) cout<<can[i]?'1':'0';
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:47:50: warning: second operand of conditional expression has no effect [-Wunused-value]
   47 |     for (int i=1; i<=n; i++) cout<<can[i]?'1':'0';
      |                                                  ^
island.cpp:47:50: warning: third operand of conditional expression has no effect [-Wunused-value]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 82 ms 15520 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 83 ms 14216 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 95 ms 14252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Halted 0 ms 0 KB -