77522024-01-11 07:17:57TuruTamasHálózatjavításcpp17Wrong answer 3/50400ms7300 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

ll N, M, a, b, max_korszam;
vvi G;
vector<pii> kor;
vector<char> vis;

bool dfs1(ll x) {
    vis[x] = 1;
    for (ll next : G[x]) {
        if (!vis[next] && dfs1(next)) {
            kor[x] = {next, 0};
            return true;
        }
        if (vis[next] == 1) {
            kor[x] = {next, 0};
            return true;
        }
    }
    vis[x] = 2;
    return false;
}

void korbejar(ll tol, ll ig) {
    ll most = tol;
    while (most != ig) {
        kor[most].second++;
        most = kor[most].first;
    }
}

void dfs2(ll x, ll kezdx) {
    vis[x] = 1;
    for (ll next : G[x]) {
        if (kor[next].first != -1) {
            korbejar(next, kezdx);
            continue;
        }
        if (!vis[next]) {
            dfs2(next, kezdx);
        }
    }
}

int main() {
    INTHENAMEOFGOD
    input >> N >> M;
    G.resize(N);
    for (ll m = 0; m < M; m++) {
        input >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }

    vis.assign(N, 0);
    kor.assign(N, {-1, 0});
    dfs1(0);
    
    vis.assign(N, 0);
    for (ll n = 0; n < N; n++) {
        if (kor[n].first != -1) {
            for (ll next : G[n]) {
                if (!vis[next] && kor[next].first == -1) {
                    dfs2(next, n);
                }
            }
        }
    }

    ll maxfok = max_element(kor.begin(), kor.end(), [](pii a, pii b) { return a.second < b.second; })->second;

    ll db = 0;
    string s;
    ostringstream os(s);

    for (ll n = 0; n < N; n++) {
        if (kor[n].first != -1 && kor[n].second == maxfok) {
            db++;
            os << n+1 << " " << kor[n].first+1 << "\n";
        }
    }

    cout << db << "\n" << os.str();
}
SubtaskSumTestVerdictTimeMemory
base3/50
1Accepted0/03ms1976 KiB
2Wrong answer0/09ms4972 KiB
3Wrong answer0/13ms2264 KiB
4Accepted1/13ms2160 KiB
5Time limit exceeded0/1400ms2232 KiB
6Wrong answer0/13ms2916 KiB
7Wrong answer0/13ms3132 KiB
8Wrong answer0/24ms3348 KiB
9Wrong answer0/24ms3524 KiB
10Accepted2/24ms3328 KiB
11Wrong answer0/24ms4140 KiB
12Wrong answer0/23ms3744 KiB
13Wrong answer0/26ms5004 KiB
14Wrong answer0/26ms4872 KiB
15Wrong answer0/27ms5556 KiB
16Wrong answer0/26ms5100 KiB
17Wrong answer0/28ms5748 KiB
18Wrong answer0/29ms6584 KiB
19Wrong answer0/28ms6136 KiB
20Wrong answer0/29ms6900 KiB
21Wrong answer0/29ms6948 KiB
22Wrong answer0/29ms7136 KiB
23Wrong answer0/39ms7016 KiB
24Wrong answer0/49ms7100 KiB
25Wrong answer0/49ms7300 KiB
26Wrong answer0/49ms7292 KiB