Submission #1076223

# Submission time Handle Problem Language Result Execution time Memory
1076223 2024-08-26T11:56:31 Z MarwenElarbi Longest Trip (IOI23_longesttrip) C++17
0 / 100
1000 ms 1144 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
const int nax = 2e5+5;
const int MOD = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[256];
bool vis[256];
set<int> components[256];
vector<int> cur;
void dfs(int x){
    cur.pb(x);
    vis[x]=true;
    for(auto u:adj[x]){
        if(vis[u]) continue;
        dfs(u);
        return;
    }
}
std::vector<int> longest_trip(int N, int D)
{
    for (int i = 0; i < N; ++i)
    {
        adj[i].clear();
    }
    for (int i = 0; i < N; ++i)
    {
        for (int j = i+1; j < N; ++j)
        {
            if(are_connected({i},{j})){
                adj[i].pb(j);
                adj[j].pb(i);
            }
        }
    }
    int t=10000;
    vector<int> ans;
    while(t--){
        memset(vis,0,sizeof vis);
        for (int i = 0; i < N; ++i)
        {
            shuffle(adj[i].begin(),adj[i].end(),rng); 
        }
        for (int i = 0; i < N; ++i)
        {
            if(vis[i]) continue;
            cur.clear();
            dfs(i);
            if(ans.size()<cur.size()) ans=cur;
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Execution timed out 3062 ms 1144 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 302 ms 344 KB Output is correct
2 Correct 736 ms 344 KB Output is correct
3 Execution timed out 3011 ms 344 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 303 ms 344 KB Output is correct
2 Correct 745 ms 344 KB Output is correct
3 Execution timed out 3070 ms 728 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 301 ms 344 KB Output is correct
2 Correct 730 ms 344 KB Output is correct
3 Execution timed out 3088 ms 344 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 297 ms 344 KB Output is correct
2 Correct 759 ms 344 KB Output is correct
3 Execution timed out 3059 ms 344 KB Time limit exceeded
4 Halted 0 ms 0 KB -