2762021-06-22 15:24:54mraronTurista járatokcpp14Accepted 100/100188ms76688 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});
      }
   }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms7480 KiB
2Accepted10ms9588 KiB
subtask210/10
3Accepted4ms7684 KiB
4Accepted4ms7688 KiB
5Accepted3ms7700 KiB
6Accepted4ms7688 KiB
7Accepted4ms7680 KiB
subtask310/10
8Accepted4ms7716 KiB
9Accepted4ms7700 KiB
10Accepted4ms7716 KiB
11Accepted4ms8008 KiB
12Accepted7ms9232 KiB
subtask410/10
13Accepted12ms10864 KiB
14Accepted3ms7876 KiB
15Accepted4ms7992 KiB
16Accepted4ms8296 KiB
17Accepted188ms65564 KiB
18Accepted57ms24692 KiB
19Accepted81ms30600 KiB
20Accepted57ms26612 KiB
subtask510/10
21Accepted14ms17132 KiB
22Accepted4ms15292 KiB
23Accepted4ms15312 KiB
24Accepted4ms15424 KiB
25Accepted103ms54640 KiB
26Accepted10ms20424 KiB
27Accepted14ms20572 KiB
subtask660/60
28Accepted4ms18584 KiB
29Accepted4ms18600 KiB
30Accepted4ms18848 KiB
31Accepted6ms18956 KiB
32Accepted6ms19224 KiB
33Accepted8ms19672 KiB
34Accepted10ms20716 KiB
35Accepted10ms20868 KiB
36Accepted10ms21020 KiB
37Accepted172ms76688 KiB
38Accepted48ms35872 KiB
39Accepted56ms36804 KiB
40Accepted48ms37704 KiB
41Accepted46ms38584 KiB
42Accepted45ms39468 KiB
43Accepted48ms40396 KiB
44Accepted50ms41260 KiB
45Accepted74ms47084 KiB
46Accepted50ms43128 KiB
47Accepted48ms43920 KiB
48Accepted46ms45276 KiB
49Accepted46ms46220 KiB
50Accepted48ms47120 KiB