fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. const ll MAXN = 30+7;
  9. const ll INF = 1e18;
  10. vector <vector<pair<ll,ll>>> a(MAXN);
  11. vector <bool> ktra(MAXN,false);
  12. vector <ll> vet(MAXN),best(MAXN);
  13. ll tcp,u=0,ans=INF;
  14. ll n,m,k;
  15.  
  16. void Try(ll xp){
  17. for(auto canh:a[xp]){
  18. ll v=canh.fi, w=canh.se;
  19. if(!ktra[v]){
  20. ktra[v]=true;
  21. u++; vet[u]=v; tcp+=w;
  22. Try(v);
  23. ktra[v]=false;
  24. u--;
  25. tcp-=w;
  26. }
  27. else{
  28. if(v==k && u+1==n){
  29. if(ans>tcp+w){
  30. ans=tcp+w;
  31. for(ll i=0 ; i<=u ; i++) best[i]=vet[i];
  32. best[u+1]=k;
  33. }
  34. }
  35. }
  36. }
  37. }
  38.  
  39.  
  40.  
  41. int main(){
  42. //freopen("inp.inp","r",stdin);
  43. cin >> n >> m >> k;
  44. for(ll i=1 ; i<=m ; i++){
  45. ll u,v,w; cin >> u >> v >> w;
  46. a[u].pb({v,w});
  47. a[v].pb({u,w});
  48. }
  49. ktra[k]=true;
  50. vet[u]=k;
  51. Try(k);
  52. if(ans==INF cout << "error!\n";
  53. else{
  54. cout << ans <<"\n";
  55. for(ll i=0; i<=n ; i++){
  56. cout << best[i] << " ";
  57. }
  58. }
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:52:8: warning: init-statement in selection statements only available with -std=c++17 or -std=gnu++17
     if(ans==INF cout << "error!\n";
        ^~~
prog.cpp:52:16: error: expected ‘;’ before ‘cout’
     if(ans==INF cout << "error!\n";
                ^~~~~
                ;
prog.cpp:53:5: error: expected primary-expression before ‘else’
     else{
     ^~~~
prog.cpp:52:36: error: expected ‘)’ before ‘else’
     if(ans==INF cout << "error!\n";
       ~                            ^
                                    )
     else{
     ~~~~                            
prog.cpp:59:1: error: expected primary-expression before ‘}’ token
 }
 ^
stdout
Standard output is empty