Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("dfs.in");
- ofstream cout("dfs.out");
- int n,m,p,c=0,viz[10001],a[102][102],k=0;
- void DF(int nod)
- {
- cout << nod << " ";
- viz[nod]=1;
- for(int i=1;i<=n;i++)
- {
- if(a[nod][i]==1 && viz[i]==0)
- {
- DF(i);
- }
- }
- }
- void Citire()
- {
- int x,y;
- int contor=1;
- for(int i=1;i<=m;i++)
- {
- cin >> x >> y;
- a[x][y]=a[y][x]=1;
- }
- }
- int main()
- {
- cin >> n >> m >> p;
- Citire();
- DF(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement