fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define read() freopen("input.txt","r",stdin)
  5. #define INF ((1<<31)-1)
  6. #define EPS (1e-9)
  7. #define PI (2*acos(0.0))
  8. #define ll long long
  9. #define ull ll
  10. #define SIZE ((ll)1e6)+10
  11. #define testcase ll T;cin>>T;for(int t=1;t<=T;t++)
  12. #define printcase() cout<<"Case "<<t<<":\n"
  13. #define pb push_back
  14. #define PAR_SIZE 30010
  15. #define BFS_GRID 1010
  16. #define NL() cout << endl
  17. #define FOR(itt,n) for(int itt=0;itt<n;++itt)
  18. #define FOR1(itt,n) for(int itt=1;itt<=n;++itt)
  19.  
  20. int a[1000][1000];
  21. vector <int> adj[SIZE];
  22. bool vis[SIZE];
  23. int cost[SIZE];
  24. void dfs(int v)
  25. {
  26. vis[v]=true;
  27. for(int i=0;i<adj[v].size();i++){
  28. //cost[adj[v][i]]=min(cost[v]+1,cost[adj[v][i]]);
  29. if(!vis[adj[v][i]]){
  30. dfs(adj[v][i]);
  31. //vis[adj[v][i]]=false;
  32. }
  33. }
  34. cout << v << endl;
  35.  
  36. }
  37.  
  38.  
  39. void makeList(){
  40. int n, m;
  41. cin >> n;
  42. cin >> m;
  43. FOR(i,m){
  44. int x, y;
  45. cin >> x >> y;
  46. adj[x].pb(y);
  47. adj[y].pb(x);
  48. a[x][y]=true;
  49. a[y][x]=true;
  50. }
  51.  
  52. }
  53.  
  54. int main()
  55. {
  56. #ifdef pinanzo
  57. read();
  58. #endif // pinanzo
  59. //ios_base::sync_with_stdio(0);
  60. //cin.tie(NULL);
  61. //cout.tie(NULL);
  62. //int n;
  63. makeList();
  64. FOR(i,SIZE)cost[i]=INF;
  65. cost[0]=0;
  66. dfs(1);
  67. int q;
  68. while(cin >> q){
  69. cout << q << " Costs " << cost[q] << endl;
  70. }
  71.  
  72. return 0;
  73. }
  74.  
  75.  
  76.  
Runtime error #stdin #stdout 0s 23240KB
stdin
Standard input is empty
stdout
Standard output is empty