Pagini recente » Cod sursa (job #742884) | Cod sursa (job #1997178) | Cod sursa (job #1192967) | Cod sursa (job #561851) | Cod sursa (job #973233)
Cod sursa(job #973233)
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
ifstream cin("pamant.in");
ofstream cout("pamant.out");
const int MAXN = 100005;
const int oo = (1<<31)-1;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
Graph G;
vector<int> Con;
set<int>ArtPoints;
int N, M;
vector<int> Dfn(MAXN, -1), Low(MAXN);
bitset<MAXN>Used;
inline void Get_min(int &a, int b){
if(a>b)
a=b;
}
inline void DFs(int Node, int Father, int actLevel){
Dfn[Node] = Low[Node] = actLevel;
int sons = 0;
bool critical = false;
for(It it = G[Node].begin(), fin = G[Node].end() ; it != fin ; ++ it)
if(*it != Father){
if(Dfn[*it] == -1){
DFs(*it, Node, actLevel + 1);
Get_min(Low[Node], Low[*it]);
critical |= (Low[*it] >= Dfn[Node]);
++ sons;
}
else Get_min(Low[Node], Dfn[*it]);
}
if (Node != Father) {
if (critical)
ArtPoints.insert(Node);
} else if (sons >= 2)
ArtPoints.insert(Node);
}
int main(){
cin >> N >> M;
for(int i = 1 ; i <= M ; ++ i){
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for(int i = 1 ; i <= N ; ++ i)
if(Dfn[i] == -1 ){
DFs(i, i, 1);
Con.push_back(i);
}
cout << Con.size() << "\n";
for(It it = Con.begin() , fin = Con.end() ; it != fin ; ++ it)
cout << *it << " ";
cout << "\n" << ArtPoints.size() <<"\n";
for(set<int> :: iterator it = ArtPoints.begin() , fin = ArtPoints.end() ; it != fin ; ++ it)
cout << *it << " ";
cin.close();
cout.close();
return 0;
}