Submission #1240641

#TimeUsernameProblemLanguageResultExecution timeMemory
1240641dostsLongest Trip (IOI23_longesttrip)C++20
40 / 100
7 ms680 KiB
#include "longesttrip.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;

int c[257][257];
int sor(int a,int b) {
    if (c[a][b] != -1) return c[a][b];
    if (c[b][a] != -1) return c[b][a];
    if (a == b) return 0;
    return c[a][b] = are_connected({a},{b});
}
std::vector<int> longest_trip(int N, int D)
{   
    memset(c,-1,sizeof c);
    vi ans;
    vi have(N,0);
    for (int i = 0;i<N;i++) {
        if (have[i]) continue;
        deque<int> mytrip;
        mytrip.push_back(i);
        have[i] = 1;
        while (1) {
            int fnd = 0;
            for (int j = 0;j<N;j++) {
                if (have[j]) continue;
                if (sor(mytrip.front(),j)) mytrip.push_front(j),have[j] = 1,fnd =1;
                else if (sor(mytrip.back(),j)) mytrip.push_back(j),have[j] = 1,fnd = 1;
            }
            if (!fnd) break;
        }
        vi v = vi(all(mytrip));
        if (big(v) > big(ans)) ans = v;
    }
    return ans;
}
#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...