5219 | 2023-04-22 21:36:48 | Valaki2 | Turista járatok | cpp14 | Hibás válasz 30/100 | 158ms | 71412 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
struct edge {
int from, to, id;
};
const int maxn = 40'000;
const int maxm = 400'000;
const int root = 1;
const int maxc = maxm; // actually maxn should be enough!!!!!
int n, m, k;
vector<edge> graph[1 + maxn];
pii edges[1 + maxm];
/*bool special(const edge &e) {
return e.id <= k;
}*/
int t;
int dep[1 + maxn];
int low[1 + maxn];
bool cut[1 + maxn];
bool vis_low[1 + maxn];
void dfs_low(int cur, int par) {
t++;
dep[cur] = t;
low[cur] = t;
vis_low[cur] = true;
int cnt = 0;
int lowcheck = 0;
for(const edge &e : graph[cur]) {
int nei = e.to;
if(!vis_low[nei]) {
cnt++;
dfs_low(nei, cur);
low[cur] = min(low[cur], low[nei]);
lowcheck = max(lowcheck, low[nei]);
} else if(nei != par) {
low[cur] = min(low[cur], dep[nei]);
}
}
if((par == -1 && cnt > 1) || ((par != -1) && (lowcheck >= dep[cur]) && (cnt > 0))) {
cut[cur] = true;
}
}
stack<int> s;
int comp_cnt;
int start[1 + maxc];
int comp[1 + maxm];
int nodes_comp[1 + maxn];
bool vis_bcc[1 + maxn];
void dfs_bcc(int cur, int prv_id) {
vis_bcc[cur] = true;
for(const edge &e : graph[cur]) {
if(!vis_bcc[e.to]) {
s.push(e.id);
dfs_bcc(e.to, e.id);
if((low[e.to] >= dep[cur]) && (cut[cur] || cur == root)) {
comp_cnt++;
start[comp_cnt] = cur;
while(!s.empty() && s.top() != e.id) {
comp[s.top()] = comp_cnt;
s.pop();
}
if(!s.empty()) {
comp[s.top()] = comp_cnt;
s.pop();
}
}
} else if(e.id != prv_id && dep[e.to] < low[cur]) {
s.push(e.id);
}
}
}
vector<int> tree[1 + maxc];
bool has[1 + maxc];
void dfs_has(int cur, bool have) {
if(have) {
has[cur] = true;
}
have = has[cur];
for(int nei : tree[cur]) {
dfs_has(nei, have);
}
}
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
graph[a].pb({a, b, i});
graph[b].pb({b, a, i});
edges[i] = mp(a, b);
}
dfs_low(root, -1);
dfs_bcc(root, -1);
for(int i = 1; i <= m; i++) {
if(comp[i] != 0) {
if(start[comp[i]] != edges[i].fi) {
nodes_comp[edges[i].fi] = comp[i];
}
if(start[comp[i]] != edges[i].se) {
nodes_comp[edges[i].se] = comp[i];
}
}
}
for(int i = 1; i <= comp_cnt; i++) {
tree[nodes_comp[start[i]]].pb(i);
}
for(int i = 1; i <= k; i++) {
has[comp[i]] = true;
}
dfs_has(0, false);
vector<int> ans;
for(int i = 1; i <= n; i++) {
if(has[nodes_comp[i]]) {
ans.pb(i);
}
}
cout << ans.size() << "\n";
for(int x : ans) {
cout << x << " ";
}
cout << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 13ms | 22548 KiB | ||||
2 | Hibás válasz | 19ms | 24936 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Elfogadva | 10ms | 23064 KiB | ||||
4 | Elfogadva | 9ms | 23016 KiB | ||||
5 | Elfogadva | 9ms | 23280 KiB | ||||
6 | Elfogadva | 9ms | 23492 KiB | ||||
7 | Elfogadva | 9ms | 23708 KiB | ||||
subtask3 | 0/10 | ||||||
8 | Hibás válasz | 9ms | 23664 KiB | ||||
9 | Elfogadva | 9ms | 23780 KiB | ||||
10 | Elfogadva | 9ms | 23868 KiB | ||||
11 | Elfogadva | 9ms | 24092 KiB | ||||
12 | Elfogadva | 14ms | 24964 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Elfogadva | 17ms | 26144 KiB | ||||
14 | Elfogadva | 12ms | 24540 KiB | ||||
15 | Elfogadva | 13ms | 24728 KiB | ||||
16 | Elfogadva | 13ms | 25056 KiB | ||||
17 | Elfogadva | 157ms | 70784 KiB | ||||
18 | Elfogadva | 57ms | 34784 KiB | ||||
19 | Elfogadva | 68ms | 38468 KiB | ||||
20 | Elfogadva | 57ms | 34912 KiB | ||||
subtask5 | 10/10 | ||||||
21 | Elfogadva | 17ms | 27064 KiB | ||||
22 | Elfogadva | 12ms | 25516 KiB | ||||
23 | Elfogadva | 12ms | 25632 KiB | ||||
24 | Elfogadva | 10ms | 25568 KiB | ||||
25 | Elfogadva | 87ms | 55556 KiB | ||||
26 | Elfogadva | 16ms | 27284 KiB | ||||
27 | Elfogadva | 17ms | 27252 KiB | ||||
subtask6 | 0/60 | ||||||
28 | Elfogadva | 10ms | 25548 KiB | ||||
29 | Hibás válasz | 10ms | 25696 KiB | ||||
30 | Hibás válasz | 13ms | 25900 KiB | ||||
31 | Hibás válasz | 14ms | 26264 KiB | ||||
32 | Hibás válasz | 14ms | 26344 KiB | ||||
33 | Hibás válasz | 16ms | 26472 KiB | ||||
34 | Hibás válasz | 17ms | 27660 KiB | ||||
35 | Hibás válasz | 17ms | 27600 KiB | ||||
36 | Hibás válasz | 17ms | 27600 KiB | ||||
37 | Elfogadva | 158ms | 71412 KiB | ||||
38 | Elfogadva | 57ms | 35540 KiB | ||||
39 | Elfogadva | 57ms | 35400 KiB | ||||
40 | Elfogadva | 54ms | 35652 KiB | ||||
41 | Elfogadva | 57ms | 35640 KiB | ||||
42 | Elfogadva | 57ms | 35608 KiB | ||||
43 | Elfogadva | 56ms | 35608 KiB | ||||
44 | Elfogadva | 54ms | 35596 KiB | ||||
45 | Elfogadva | 68ms | 39372 KiB | ||||
46 | Elfogadva | 54ms | 35644 KiB | ||||
47 | Elfogadva | 57ms | 35816 KiB | ||||
48 | Elfogadva | 57ms | 35620 KiB | ||||
49 | Elfogadva | 57ms | 35620 KiB | ||||
50 | Elfogadva | 56ms | 35624 KiB |