276 | 2021-06-22 15:24:54 | mraron | Turista járatok | cpp14 | Accepted 100/100 | 188ms | 76688 KiB |
//
#include <bits/stdc++.h>
#define maxN 40001
using namespace std;
struct El2{
int q;
bool lat;
El2(){};
El2(int x, bool y){q=x; lat=y;}
};
struct El3{
int p; int q;
bool lat;
El3(){};
El3(int x, int y, bool z){p=x; q=y; lat=z;}
};
int n;//n=pontok száma, k=látványok
vector<El2> G[maxN];
void BeOlvas();
int D[maxN];
int L[maxN];
int Apa[maxN];
bool Elvago[maxN];
bool Mego[maxN];
vector<int> EB[maxN];
vector<int> BE[maxN];
stack<El3> V;
vector<vector<El3>> Blokk;
int ido=0;
void MelyBejar(int p){
//Global: G, ido, D, L, V,H
D[p]=++ido;
L[p]=ido;
for (El2 pq:G[p]){
int q=pq.q;
if (D[q]==0){//p->q faél
V.push(El3(p,q,pq.lat));
Apa[q]=p;
MelyBejar(q);
L[p]=min(L[p],L[q]);
if ( L[q]>=D[p]){//találtunk egy komponenst
bool lat=false;
Elvago[p]=true;
El3 e;
vector<El3> Bp;
do{
e=V.top(); V.pop();
Bp.push_back(e);
lat|=e.lat;
if(Elvago[e.p]) BE[Blokk.size()].push_back(e.p);
}while(!(e.p==p && e.q==q || e.p==q && e.q==p));
if(Bp.size()==1 && Elvago[e.q]) BE[Blokk.size()].push_back(e.q);
EB[p].push_back(Blokk.size());
Blokk.push_back(Bp);
Blokk[Blokk.size()-1][0].lat=lat;
}
}else if (q!=Apa[p] && D[q]<D[p]){//p->q visszaél
L[p]=min(L[p],D[q]);
V.push(El3(p,q,pq.lat));
}
}
}
void Komponensek(){
//global: G, íd, Apa, Elvago
for (int p=1; p<=n; p++) {
D[p]=0; Apa[p]=0; Elvago[p]=false; Mego[p]=false;
}
MelyBejar(1);
}
void Bejar(int p, bool volt){
bool van=volt;
Elvago[p]=false;
for (int b:EB[p]){
van=volt;
if(Blokk[b][0].p==0) continue;
van|= Blokk[b][0].lat;//van-e a blokkban látvány
if(van) for(El3 e:Blokk[b]){
Mego[e.p]=true; Mego[e.q]=true;
}
Blokk[b][0].p=0;
for(int q:BE[b])
if(Elvago[q])
Bejar(q, van);
}
Mego[p]=volt;
}
//
int main (){
ios_base::sync_with_stdio(false); cin.tie(NULL);
BeOlvas();
Komponensek();
Bejar(1,false);
int m=0; for(int x=1;x<=n;x++) if(Mego[x]) m++;
cout<<m<<endl;
for(int x=1;x<=n;x++)
if(Mego[x]) cout<<x<<" "; cout<<endl;
}
void BeOlvas(){
//Global:n,G
int m,p,q,k;
cin>>n>>m>>k;
for (int i=0; i<m; i++){
cin>>p>>q;
if(i<k){
G[p].push_back({q,1});
G[q].push_back({p,1});
}else{
G[p].push_back({q,0});
G[q].push_back({p,0});
}
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 7480 KiB | ||||
2 | Accepted | 10ms | 9588 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 4ms | 7684 KiB | ||||
4 | Accepted | 4ms | 7688 KiB | ||||
5 | Accepted | 3ms | 7700 KiB | ||||
6 | Accepted | 4ms | 7688 KiB | ||||
7 | Accepted | 4ms | 7680 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 4ms | 7716 KiB | ||||
9 | Accepted | 4ms | 7700 KiB | ||||
10 | Accepted | 4ms | 7716 KiB | ||||
11 | Accepted | 4ms | 8008 KiB | ||||
12 | Accepted | 7ms | 9232 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 12ms | 10864 KiB | ||||
14 | Accepted | 3ms | 7876 KiB | ||||
15 | Accepted | 4ms | 7992 KiB | ||||
16 | Accepted | 4ms | 8296 KiB | ||||
17 | Accepted | 188ms | 65564 KiB | ||||
18 | Accepted | 57ms | 24692 KiB | ||||
19 | Accepted | 81ms | 30600 KiB | ||||
20 | Accepted | 57ms | 26612 KiB | ||||
subtask5 | 10/10 | ||||||
21 | Accepted | 14ms | 17132 KiB | ||||
22 | Accepted | 4ms | 15292 KiB | ||||
23 | Accepted | 4ms | 15312 KiB | ||||
24 | Accepted | 4ms | 15424 KiB | ||||
25 | Accepted | 103ms | 54640 KiB | ||||
26 | Accepted | 10ms | 20424 KiB | ||||
27 | Accepted | 14ms | 20572 KiB | ||||
subtask6 | 60/60 | ||||||
28 | Accepted | 4ms | 18584 KiB | ||||
29 | Accepted | 4ms | 18600 KiB | ||||
30 | Accepted | 4ms | 18848 KiB | ||||
31 | Accepted | 6ms | 18956 KiB | ||||
32 | Accepted | 6ms | 19224 KiB | ||||
33 | Accepted | 8ms | 19672 KiB | ||||
34 | Accepted | 10ms | 20716 KiB | ||||
35 | Accepted | 10ms | 20868 KiB | ||||
36 | Accepted | 10ms | 21020 KiB | ||||
37 | Accepted | 172ms | 76688 KiB | ||||
38 | Accepted | 48ms | 35872 KiB | ||||
39 | Accepted | 56ms | 36804 KiB | ||||
40 | Accepted | 48ms | 37704 KiB | ||||
41 | Accepted | 46ms | 38584 KiB | ||||
42 | Accepted | 45ms | 39468 KiB | ||||
43 | Accepted | 48ms | 40396 KiB | ||||
44 | Accepted | 50ms | 41260 KiB | ||||
45 | Accepted | 74ms | 47084 KiB | ||||
46 | Accepted | 50ms | 43128 KiB | ||||
47 | Accepted | 48ms | 43920 KiB | ||||
48 | Accepted | 46ms | 45276 KiB | ||||
49 | Accepted | 46ms | 46220 KiB | ||||
50 | Accepted | 48ms | 47120 KiB |