fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define MOD 1000000007
  5. #define PI 4 * atan(1)
  6. #define sz(A) (int)A.size()
  7. typedef long long ll;
  8. typedef vector<int> vi;
  9. typedef pair<int, int> pii;
  10. typedef vector<long long> vll;
  11. typedef long int int32;
  12. typedef unsigned long int uint32;
  13. typedef long long int int64;
  14. typedef unsigned long long int uint64;
  15. int n,e;
  16. set<int> adj[10004];
  17. inline void solve(int test){
  18. ifstream in("CT.INP");
  19. ofstream out("CT.OUT");
  20. int t,a;
  21. in >> t >> n >> e;
  22. if(t == 2) in >> a;
  23. int u,v;
  24. for(int i=0; i<e; i++){
  25. in >> u >> v;
  26. adj[u].insert(v);
  27. adj[v].insert(u);
  28. }
  29. int c0 = 0, c1 =0;
  30. if(t == 1){
  31. for(int i=1; i<=n; i++){
  32. if(adj[i].size() & 1) c1++;
  33. else c0++;
  34. }
  35. if(c0 == n){
  36. out << 1;
  37. return;
  38. }
  39. if(c1 == 2){
  40. out << 2;
  41. return;
  42. }
  43. out << 0;
  44. return;
  45. }else{
  46. stack<int> st;
  47. st.push(a);
  48. vector<int> res;
  49. while(!st.empty()){
  50. int f = st.top();
  51. if(adj[f].empty()){
  52. res.push_back(f);
  53. st.pop();
  54. }else{
  55. int x = *adj[f].begin();
  56. st.push(x);
  57. adj[f].erase(x);
  58. adj[x].erase(f);
  59. }
  60. }
  61. for(int i=res.size()-1; i>=0; i--){
  62. out << res[i] << " ";
  63. }
  64. }
  65. in.close();
  66. out.close();
  67. }
  68. int main(){
  69. int typetest = 0;
  70. if (typetest){
  71. int t;
  72. cin >> t;
  73. cin.ignore();
  74. for(int i=1; i<=t; i++){
  75. solve(i);
  76. }
  77. }
  78. else solve(0);
  79. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty