12342022-03-27 14:33:04Valaki2Turista járatokcpp14Wrong answer 0/100156ms44612 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int maxn = 40000;

int n, m, k;
vector<pair<int, int> > g[maxn + 1];
bool vis[maxn + 1];
vector<int> ans;

void dfs(int cur, int ok) {
    if(ok) {
        ans.pb(cur);
    }
    vis[cur] = true;
    for(pair<int, int> nei : g[cur]) {
        if(!vis[nei.fi] && cur != nei.fi) {
            dfs(nei.fi, max(ok, nei.se));
        }
    }
}

void solve() {
    cin >> n >> m >> k;
    for(int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        if(i <= k) {
            g[a].pb(mp(b, 1));
            g[b].pb(mp(a, 1));
        } else {
            g[a].pb(mp(b, 0));
            g[b].pb(mp(a, 0));
        }
    }
    dfs(1, 0);
    sort(ans.begin(), ans.end());
    cout << (int) ans.size() << "\n";
    for(int x : ans) {
        cout << x << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms3872 KiB
2Accepted8ms5028 KiB
subtask20/10
3Accepted2ms4060 KiB
4Accepted2ms4108 KiB
5Wrong answer2ms4064 KiB
6Wrong answer2ms4144 KiB
7Wrong answer2ms4084 KiB
subtask30/10
8Wrong answer2ms4088 KiB
9Accepted2ms4088 KiB
10Accepted2ms4160 KiB
11Accepted3ms4128 KiB
12Accepted4ms4564 KiB
subtask40/10
13Accepted8ms5056 KiB
14Accepted2ms4252 KiB
15Accepted3ms4432 KiB
16Accepted3ms4448 KiB
17Wrong answer156ms33624 KiB
18Wrong answer37ms14144 KiB
19Wrong answer50ms17404 KiB
20Wrong answer37ms16524 KiB
subtask50/10
21Accepted7ms12572 KiB
22Wrong answer2ms11636 KiB
23Wrong answer2ms11644 KiB
24Wrong answer3ms11664 KiB
25Wrong answer83ms29888 KiB
26Wrong answer7ms15588 KiB
27Wrong answer7ms15736 KiB
subtask60/60
28Wrong answer2ms14816 KiB
29Accepted4ms14960 KiB
30Accepted3ms15016 KiB
31Accepted4ms15224 KiB
32Wrong answer4ms15312 KiB
33Accepted4ms15552 KiB
34Accepted7ms16120 KiB
35Accepted8ms16316 KiB
36Accepted7ms16420 KiB
37Wrong answer143ms44612 KiB
38Wrong answer34ms25424 KiB
39Wrong answer35ms26344 KiB
40Wrong answer35ms27260 KiB
41Wrong answer35ms28140 KiB
42Wrong answer35ms28888 KiB
43Wrong answer34ms29944 KiB
44Wrong answer35ms30688 KiB
45Wrong answer52ms33960 KiB
46Wrong answer41ms33064 KiB
47Wrong answer39ms33956 KiB
48Wrong answer37ms34696 KiB
49Wrong answer34ms35768 KiB
50Wrong answer35ms36676 KiB