Submission #823746

# Submission time Handle Problem Language Result Execution time Memory
823746 2023-08-13T04:28:07 Z ttamx Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 17316 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int,int> p2;
typedef tuple<int,int,int> t3;

const int N=2e5+5;

int n,m;
int s[2*N],fa[2*N],ans[2*N];
ll sz[2*N];
vector<t3> edge;
vector<p2> node;

int fp(int u){
    if(u==fa[u])return u;
    return fa[u]=fp(fa[u]);
}

void dfs(int u){
    cerr << u << " : " << ans[u] << "\n";
    if(u<=n)return;
    auto [l,r]=node[u];
    if(ans[u]==0)ans[l]=ans[r]=0;
    dfs(l);
    dfs(r);
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++)cin >> s[i];
    for(int i=1;i<=2*n;i++){
        fa[i]=i;
        sz[i]=s[i];
        ans[i]=1;
    }
    for(int i=0;i<m;i++){
        int u,v;
        cin >> u >> v;
        edge.emplace_back(max(s[u],s[v]),u,v);
    }
    sort(edge.begin(),edge.end());
    node=vector<p2>(n+1,p2(0,0));
    for(auto [w,u,v]:edge){
        int pu=fp(u),pv=fp(v);
        if(pu==pv)continue;
        if(sz[pu]<w)ans[pu]=0;
        if(sz[pv]<w)ans[pv]=0;
        int p=node.size();
        node.emplace_back(pu,pv);
        fa[pu]=fa[pv]=p;
        sz[p]=sz[pu]+sz[pv];
    }
    dfs(node.size()-1);
    for(int i=1;i<=n;i++)cout << ans[i];
}

Compilation message

island.cpp: In function 'void dfs(int)':
island.cpp:26:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |     auto [l,r]=node[u];
      |          ^
island.cpp: In function 'int main()':
island.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |     for(auto [w,u,v]:edge){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 14 ms 528 KB Output is correct
5 Correct 16 ms 536 KB Output is correct
6 Correct 12 ms 488 KB Output is correct
7 Correct 14 ms 504 KB Output is correct
8 Correct 14 ms 504 KB Output is correct
9 Correct 16 ms 556 KB Output is correct
10 Correct 16 ms 516 KB Output is correct
11 Correct 16 ms 468 KB Output is correct
12 Correct 20 ms 504 KB Output is correct
13 Correct 16 ms 468 KB Output is correct
14 Correct 16 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Execution timed out 1087 ms 17316 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1071 ms 15644 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1066 ms 15976 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 14 ms 528 KB Output is correct
5 Correct 16 ms 536 KB Output is correct
6 Correct 12 ms 488 KB Output is correct
7 Correct 14 ms 504 KB Output is correct
8 Correct 14 ms 504 KB Output is correct
9 Correct 16 ms 556 KB Output is correct
10 Correct 16 ms 516 KB Output is correct
11 Correct 16 ms 468 KB Output is correct
12 Correct 20 ms 504 KB Output is correct
13 Correct 16 ms 468 KB Output is correct
14 Correct 16 ms 468 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Execution timed out 1087 ms 17316 KB Time limit exceeded
18 Halted 0 ms 0 KB -