Submission #823743

# Submission time Handle Problem Language Result Execution time Memory
823743 2023-08-13T04:25:12 Z ttamx Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 17840 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[N],fa[2*N],ans[2*N];
ll sum,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<=n;i++){
        fa[i]=i;
        sz[i]=s[i];
        sum+=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;
        fa[p]=p;
        sz[p]=sz[pu]+sz[pv];
        ans[p]=1;
    }
    for(int i=2;i<=n;i++)if(fp(i)!=fp(1))cout << string(n,'0'),exit(0);
    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:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |     for(auto [w,u,v]:edge){
      |              ^
# 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 Correct 0 ms 340 KB Output is correct
4 Correct 21 ms 528 KB Output is correct
5 Correct 17 ms 572 KB Output is correct
6 Correct 20 ms 648 KB Output is correct
7 Correct 14 ms 528 KB Output is correct
8 Correct 11 ms 536 KB Output is correct
9 Correct 16 ms 596 KB Output is correct
10 Correct 16 ms 556 KB Output is correct
11 Correct 16 ms 564 KB Output is correct
12 Correct 16 ms 560 KB Output is correct
13 Correct 16 ms 568 KB Output is correct
14 Correct 16 ms 544 KB Output is correct
# 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 Execution timed out 1088 ms 17840 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 1074 ms 15444 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 1063 ms 15872 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 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 21 ms 528 KB Output is correct
5 Correct 17 ms 572 KB Output is correct
6 Correct 20 ms 648 KB Output is correct
7 Correct 14 ms 528 KB Output is correct
8 Correct 11 ms 536 KB Output is correct
9 Correct 16 ms 596 KB Output is correct
10 Correct 16 ms 556 KB Output is correct
11 Correct 16 ms 564 KB Output is correct
12 Correct 16 ms 560 KB Output is correct
13 Correct 16 ms 568 KB Output is correct
14 Correct 16 ms 544 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Execution timed out 1088 ms 17840 KB Time limit exceeded
18 Halted 0 ms 0 KB -