Submission #861624

#TimeUsernameProblemLanguageResultExecution timeMemory
861624faustaadpLongest Trip (IOI23_longesttrip)C++17
0 / 100
2264 ms4548 KiB
#include "longesttrip.h" #include<bits/stdc++.h> typedef long long ll; using namespace std; #define pb push_back const ll NN = 1e5 + 5; vector<int> ret, ret2; ll b[NN], n, ada = 0, mxx, now; vector<ll> v[NN]; void dfs(ll pos) { if(ada)return ; b[pos] = 1; ret.pb(pos); // cout << pos << " mas " << ret.size() << "_\n"; // cout << ret.size() << " dan " << mxx << "\n"; if(ret.size() * 2 >= mxx)ada = 1; if(ada)return; random_shuffle(v[pos].begin(), v[pos].end()); for(ll i = 0; i < v[pos].size(); i++) { if(b[v[pos][i]] == 0)dfs(v[pos][i]); if(ada)return ; } b[pos] = 0; // cout << pos << " kel\n"; ret.pop_back(); } void dfs2(ll pos) { now++; mxx = max(mxx, now); b[pos] = 1; for(ll i = 0; i < v[pos].size(); i++) if(b[v[pos][i]] == 0) dfs2(v[pos][i]); } std::vector<int> longest_trip(int N, int D) { mxx = 0; ada = 0; n = N; ret.clear(); for(ll i = 0; i < N; i++) { v[i].clear(); b[i] = 0; } for(ll i = 0; i < N; i++) for(ll j = i + 1; j < N; j++) { vector<int> A;A.pb(i); vector<int> B;B.pb(j); bool isi = are_connected(A, B); if(isi) { // cout << i << "--" << j << "\n"; v[i].pb(j); v[j].pb(i); } } for(ll i = 0; i < N; i++) if(!b[i]) { now = 0; dfs2(i); } for(ll i = 0; i < N; i++) { b[i] = 0; } for(ll i = 0; i < N; i++) if(!b[i]) { now = 0; dfs2(i); if(now == mxx) { for(ll j = 0; j < N; j++) { b[j] = 0; } dfs(i); return ret; } } // return ret; // ll mul = 1; // if(N % 2 == 0) // { // vector<int> A;A.pb(0); // vector<int> B;B.pb(1); // bool isi = are_connected(A, B); // if(!isi) // swap(cal[1], cal[2]); // ret.pb(cal[0]); // ret.pb(cal[1]); // } // else // ret.pb(cal[0]); // for(ll i = mul; i + 1 < N; i += 2) // { // ll now = ret.back(); // vector<int> A;A.pb(now); // vector<int> B;A.pb(cal[i]); // bool isi = are_connected(A, B); // if() // } // return ret; }

Compilation message (stderr)

longesttrip.cpp: In function 'void dfs(ll)':
longesttrip.cpp:17:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   17 |     if(ret.size() * 2 >= mxx)ada = 1;
      |        ~~~~~~~~~~~~~~~^~~~~~
longesttrip.cpp:20:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'void dfs2(ll)':
longesttrip.cpp:34:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:110:1: warning: control reaches end of non-void function [-Wreturn-type]
  110 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...