답안 #860987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860987 2023-10-15T04:24:26 Z Cookie Stranded Far From Home (BOI22_island) C++14
0 / 100
72 ms 17348 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
ifstream fin("store.inp");
ofstream fout("store.out");
const ll mxn = 3e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
//const int x[4] = {0, -1, 0, 1};
int n, m;
struct E{
    ll u, v, w;
    bool operator <(const E &b){
        return(w < b.w);
    }
};
vt<E>edge;
bool bad[mxn + 1];
int pa[mxn + 1]; 
ll sm[mxn + 1], c[mxn + 1];
int fp(int u){
    if(pa[u] == u)return(u);
    int v = fp(pa[u]);
    bad[u] |= bad[v]; pa[u] = v;
    return(v);
}
void unon(int u, int v){
    u = fp(u); v = fp(v);
    if(u == v)return;
    if(c[u] < c[v])swap(u, v);  
    if(c[u] > sm[v])bad[v] = 1;
    pa[v] = u; sm[u] += sm[v];
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> c[i]; pa[i] = i; sm[i] = c[i];
    }
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        edge.pb({u, v, max(c[u], c[v])});
    }
    sort(edge.begin(), edge.end());
    for(auto [u, v, w]: edge){
        unon(u, v);
    }
    for(int i = 1; i <= n; i++){
        fp(i);
        cout << !bad[i];
    }
    return(0);
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [u, v, w]: edge){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2516 KB Output is correct
4 Incorrect 1 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 70 ms 15716 KB Output is correct
4 Incorrect 54 ms 14768 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 72 ms 17348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 67 ms 16832 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2516 KB Output is correct
4 Incorrect 1 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -