Submission #598565

# Submission time Handle Problem Language Result Execution time Memory
598565 2022-07-18T14:04:27 Z MadokaMagicaFan Fountain Parks (IOI21_parks) C++17
0 / 100
0 ms 212 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second
/* #define ONPC */

using vi = vector<int>;

const ll X= 2e5+10;

int p[X];

set<ll> bench;
set<ll> fount;
map<ll, int> fnt;

int ucount;

int getp(int x) { return p[x] = (p[x] == x) ? x : getp(p[x]); }
ll cord(ll x, ll y) { return y * X + x; }
void build (vi u, vi v, vi a, vi b);

void
uni(int a, int b)
{
    a = getp(a);
    b = getp(b);
    if (a == b) return;
    ++ucount;
    p[a] = b;
    return;
}

int
construct_roads(vi x, vi y)
{
    int n = sz(x);
    vector<ll> q;
    for (int i = 0; i < n; ++i) {
        p[i] = i;
        fount.insert(cord(x[i],y[i]));
        fnt[(cord(x[i],y[i]))] = i;
        q.pb(cord(x[i],y[i]));
    }

    sort(q.begin(), q.end());

    int a,b, ind, tind;

    vi u, v, ansa, ansb;
    for (int i = 0; i < n; ++i) {
        a = q[i] % X;
        b = q[i] / X;

        ind = fnt[q[i]];

        if (fount.find(cord(a+2,b)) != fount.end()) {
            tind = fnt[cord(a+2,b)];
            if (getp(ind) != getp(tind)) {
                if (bench.find(cord(a+1,b-1)) == bench.end()) {
                    bench.insert(cord(a+1,b-1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b-1);
                } else {
                    bench.insert(cord(a+1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b+1);
                }
                uni(ind,tind);
            }
        }

        if (fount.find(cord(a,b+2)) != fount.end()) {
            tind = fnt[cord(a,b+2)];
            if (getp(ind) != getp(tind)) {
                if (bench.find(cord(a-1,b+1)) == bench.end()) {
                    bench.insert(cord(a-1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a-1);
                    ansb.pb(b+1);
                    uni(ind,tind);
                } else if (bench.find(cord(a+1,b+1)) == bench.end()){
                    bench.insert(cord(a+1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b+1);
                    uni(ind,tind);
                }
            }
        }

    }


    if (ucount != n-1) return 0;
    return 1;
}

#ifdef ONPC
void
build(vi u, vi v, vi a, vi b)
{

}

void
solve()
{
    int n;
    cin >> n;

    vi x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    cout << construct_raods(x, y) << endl;
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        solve();
}
#endif
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -