답안 #714729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714729 2023-03-25T08:32:41 Z fuad27 Stranded Far From Home (BOI22_island) C++17
0 / 100
874 ms 49808 KB
#include<bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> e;
  vector<int> sum;
  DSU(int N) {
    e = vector<int>(N, -1);
    sum=vector<int>(N,0);
  }
  int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
  bool same_set(int a, int b) { return get(a) == get(b); }
  int size(int x) { return -e[get(x)]; }
  bool unite(int x, int y) {
    x = get(x), y = get(y);
    if (x == y) return false;
    if (e[x] > e[y]) swap(x, y);
    sum[x]+=sum[y];
    sum[y]=0;
    e[x] += e[y]; e[y] = x; return true;
  }
};
const int N=200'010;
int s[N];
vector<int> gg[N];
vector<int> g[N];
int main () {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  set<int> ss;
  map<int,int> cc;
  for(int i = 0;i<n;i++) {
    cin >> s[i];
    ss.insert(s[i]);
    cc[s[i]]=1;
  }
  {
    int cnt=0;
    for(auto &i:cc) {
      i.second=cnt++;
    }
  }
  for(int i = 0;i<m;i++) {
    int a, b;
    cin >> a >> b;
    a--,b--;
    gg[a].push_back(b);
    gg[b].push_back(a);
  }
  vector<int> ns[n];
  for(int i = 0;i<n;i++) {
    ns[cc[s[i]]].push_back(i);
  }
  DSU d(n);
  vector<int> par(n);
  iota(par.begin(),par.end(),0);
  vector<int> res(n,1);
  for(int i = 0;i<n;i++)d.sum[i]=s[i];
  for(int i = 0;i<n;i++) {
    for(int at:ns[i]) {
      for(int to:gg[at]) {
        if(cc[s[to]]<=i) {
          d.unite(at,to);
        }
      }
      for(int to:gg[at]) {
        if(cc[s[to]]<=i and res[par[to]]) {
          par[to]=d.get(at);
        }
      }
      if(res[par[at]])
      par[at]=d.get(at);
    }
    if(ns[i].size()) {
      auto it=ss.upper_bound(s[ns[i][0]]);
      if(it==ss.end())continue;
      for(int at:ns[i]) {
        int mn=1e9;
        for(int to:gg[at]) {
          if(cc[s[to]]>i) {
            mn=min(mn,s[to]);
          }
        }
        if(d.sum[d.get(at)]<(*it)){
          res[par[at]]=0;
        }
      }
    }
  }
  for(int i = 0;i<n;i++) {
    cout << res[par[i]] << ""; 
  }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9624 KB Output is correct
3 Correct 6 ms 9608 KB Output is correct
4 Incorrect 8 ms 9940 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 398 ms 49808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Incorrect 874 ms 49524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 232 ms 25848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9624 KB Output is correct
3 Correct 6 ms 9608 KB Output is correct
4 Incorrect 8 ms 9940 KB Output isn't correct
5 Halted 0 ms 0 KB -