Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int MAXN = 100;
- int U[MAXN+1],S[MAXN],P[MAXN],G[MAXN][MAXN],N;
- void DFS_R(int r)
- { int y;
- while(G[r][0]>0)
- { y=G[r][G[r][0]--];
- if(!U[y]) {U[y]=1; P[y]=r; DFS_R(y); }
- }
- }
- void first_call()
- { for(int i=1;i<=N;i++) U[i]=0;
- for(int i=1;i<=N;i++) if(U[i]==0)
- DFS_R(i);
- }
- int main(){
- int x,y;
- cin >> N;
- while( cin >> x >> y ){
- G[x][++G[x][0]] = y;
- G[y][++G[y][0]] = x;
- }
- DFS_R(1);
- for(int i=1; i<=10; i++ ) cout << i << " " << P[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment