182482025-10-16 10:40:19ubormaciHálózati biztonság (50)cpp17Elfogadva 50/50111ms14132 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int64_t ll;



void solve() {

    ll n, m, k;
    cin >> n >> m >> k;
    
    vector<vector<ll>> v(n+1);
    vector<ll> cn(n+1, 0);
    for(ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        cn[a]++;
        cn[b]++;
    }

    // ez effektive ilyen szinezos feladat
    // hogy tudunk a leheto legtobbet beszinezni, hogy minden szinezettnek legalabb k darab szinezett szomeszedja legyen

    // forditva dolgozunk:
    // beszinezzuk az osszeset
    // es aztan nezzuk, hogy amugy helyes-e
    // es amelyiknek nem mukodik, annak a szinet kitoroljuk

    vector<bool> col(n+1, true);

    queue<ll> q;
    for(ll i = 1; i <= n; i++) {
        if(cn[i] < k) {
            q.push(i);
        }
    }

    while(!q.empty()) {

        ll curr = q.front();
        q.pop();

        if(col[curr] == true) {
            // megszamoljuk, es aztan updateljuk
        
            // ha most valik hamissa
            // akkor update-eljuk a neighboroket
            // es akik ezaltal hamissa fognak valni
            // azokat berakjuk a queue-ba

            ll cex = 0;

            for(const auto & x : v[curr]) {
                cex += col[x];
            }

            cn[curr] = cex;

            if(cn[curr] < k) {
                col[curr] = false;
                for(const auto & x : v[curr]) {
                    cn[x]--;
                    if(cn[x] < k) {
                        q.push(x);
                    }
                }
            }
        }
    }

    /*
    cerr << "\n";
    for(ll i = 1; i <= n; i++) {
        cerr << "col " << i << ": " << col[i] << " ; ";
    }
    */

    // we traverse the colored components and take the largest of them

    vector<bool> vis(n+1, false);
    ll mx = 0;
    vector<ll> ans;

    for(ll i = 1; i <= n; i++) {

        if(col[i] && vis[i] == false) {

            ll h = 0;
            queue<ll> q;
            q.push(i);
            vector<ll> pans; // potans
            vis[i] = true;
            while(!q.empty()) {
                
                ll curr = q.front();
                q.pop();

                h++;
                pans.push_back(curr);

                for(const auto & x : v[curr]) {
                    if(col[x] && vis[x] == false) {
                        vis[x] = true;
                        q.push(x);
                    }
                }
            }

            if(h > mx) {
                mx = h;
                ans.clear();
                for(const auto & x : pans) {
                    ans.push_back(x);
                }
            }
        }
    }

    cout << mx << "\n";
    sort(ans.begin(), ans.end());
    for(const auto & x : ans) {
        cout << x << " ";
    }

}   

int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    solve();

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/054ms7728 KiB
3Elfogadva2/21ms512 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms420 KiB
7Elfogadva2/21ms616 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva2/24ms820 KiB
11Elfogadva2/22ms500 KiB
12Elfogadva2/23ms564 KiB
13Elfogadva3/32ms564 KiB
14Elfogadva3/34ms948 KiB
15Elfogadva3/34ms1588 KiB
16Elfogadva3/350ms6476 KiB
17Elfogadva3/34ms1076 KiB
18Elfogadva3/37ms2840 KiB
19Elfogadva3/359ms9620 KiB
20Elfogadva3/3111ms14132 KiB
21Elfogadva3/364ms10164 KiB
22Elfogadva3/31ms316 KiB