31662023-02-21 12:16:29rennHírvivők csoportosítása (40)cpp17Wrong answer 0/4021ms6084 KiB
#include <bits/stdc++.h>
using namespace std;

#define GOTTAGOFAST cin.tie(0); ios::sync_with_stdio(0);

int cnt;
void bfs(int c, int &n, int &cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok);

bool megold(int n, int cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok)
{
    fill(volt.begin(), volt.end(), false);
    
    cnt = 1;

    for (size_t i = 0; i < n; i++)
    {
        if(volt[i]) continue;
        cnt++;
        bfs(0, n, cl, k, volt, pontok);
    }

    return cnt <= k;
}

void bfs(int c, int &n, int &cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok)
{
    
    volt[c] = true;
    for(int i = 0; i < n; i++)
    {
        if(volt[i] || i == c) continue;
        if(abs(pontok.at(c).first-pontok.at(i).first)+abs(pontok.at(c).second-pontok.at(i).second) <= cl)
        {
            bfs(i, n, cl, k, volt, pontok);
            continue;
        }
    }
}

int main()
{

    GOTTAGOFAST

    int x, y, n, k;
    cin >> x >> y >> n >> k;

    vector<vector<int>> graf(n, vector<int>(n, -1));
    vector<pair<int, int>> pontok(n);
    vector<bool> volt(n);
    int a, b;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a >> b;
        pontok.at(i) = {a, b};
    }

    int left = 1, right = 1000001, mid;
    
    while(left < right)
    {
        mid = left+(right-left)/2;

        if(megold(n, mid, k, volt, pontok))
        {
            right = mid-1;
        }
        else
        {
            left = mid+1;
        }
    }

    cout << (right-1) << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/03ms1824 KiB
2Wrong answer0/018ms3484 KiB
3Wrong answer0/13ms2476 KiB
4Wrong answer0/13ms2524 KiB
5Wrong answer0/14ms3152 KiB
6Wrong answer0/16ms3256 KiB
7Wrong answer0/13ms2888 KiB
8Wrong answer0/14ms3144 KiB
9Wrong answer0/14ms3356 KiB
10Wrong answer0/16ms3760 KiB
11Wrong answer0/16ms3940 KiB
12Wrong answer0/16ms3876 KiB
13Wrong answer0/321ms5696 KiB
14Wrong answer0/320ms5552 KiB
15Wrong answer0/317ms5552 KiB
16Wrong answer0/319ms5772 KiB
17Wrong answer0/317ms5628 KiB
18Wrong answer0/319ms5708 KiB
19Wrong answer0/321ms5696 KiB
20Wrong answer0/319ms5696 KiB
21Wrong answer0/319ms5824 KiB
22Wrong answer0/317ms6084 KiB