답안 #640235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640235 2022-09-14T04:04:39 Z kebine Stranded Far From Home (BOI22_island) C++17
0 / 100
216 ms 21620 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl                        ios_base::sync_with_stdio(0);   cin.tie(0);                     cout.tie(0)

int n, m, u, v;
vi adj[MAXN];
int par[MAXN];
ll val[MAXN];
bool vis[MAXN];

priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;

int fpar(int a)
{
  return par[a] = (par[a] == a ? a : fpar(par[a]));
}

int main()
{
  gl;
  cin >> n >> m;

  ll mx = 0;
  for (int i = 1; i <= n; i++)
  {
    cin >> val[i];
    par[i] = i;
    pq.push({val[i], i});
    mx = max(mx, val[i]);
  }

  for (int i = 1; i <= m; i++)
  {
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }

  while (!pq.empty())
  {
    auto [va, idx] = pq.top();
    // cout << ":: " << va << ' ' << idx << endl;
    pq.pop();
    vis[idx] = 1;
    if (va != val[fpar(par[idx])])
      continue;
    for (int i : adj[idx])
    {
      if (!vis[i] and val[idx] >= val[i])
      {
        vis[i] = 1;
        val[i] += va;
        par[idx] = fpar(par[i]);
        pq.push({val[i], i});
      }
    }
  }

  for (int i = 1; i <= n; i++)
  {
    if (val[fpar(par[i])] >= mx)
      cout << 1;
    else
      cout << 0;
  }

  cout << endl;

  // for (int i = 1; i <= n; i++)
  // {
  //   cout << par[i] << ' ';
  // }
  // cout << endl;

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 4 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 153 ms 21620 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 167 ms 21452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 216 ms 21512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 4 ms 5076 KB Output isn't correct
5 Halted 0 ms 0 KB -