Submission #840870

# Submission time Handle Problem Language Result Execution time Memory
840870 2023-08-31T19:46:21 Z Minindu206 Longest Trip (IOI23_longesttrip) C++17
0 / 100
1000 ms 844 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
int mxlen = INT_MIN;
vector<int> ans;
void dfs(vector<int> adj[], int node, vector<int> &vis, vector<int> temp)
{
    //cout << temp.size() << '\n';
    if((int)temp.size() > mxlen)
    {
      //  cout << 'x';
        mxlen = temp.size();
        ans.clear();
        ans = temp;
    }
    else if(temp.size() == mxlen)
    {
        ans.clear();
        ans = temp;
    }
    for(auto a:adj[node])
    {
        if(vis[a])
            continue;
        temp.push_back(a);
        vis[a] = 1;
        dfs(adj, a, vis, temp);
        temp.pop_back();
        vis[a] = 0;
    }
}


vector<int> longest_trip(int n, int d)
{

    vector<int> adj[n];
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (are_connected({i}, {j}))
            {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }
    vector<int> vis, temp;
    for (int i = 0; i < n; i++)
    {
        temp.clear();
        vis.resize(n, 0);
        temp.push_back(i);
        vis[i] = 1;
        dfs(adj, i, vis, temp);
        if(mxlen == n)
        {
            break;
        }
    }
   // cout << "MAX:-" << mxlen << '\n';
    mxlen = -1;
    return ans;
}

Compilation message

longesttrip.cpp: In function 'void dfs(std::vector<int>*, int, std::vector<int>&, std::vector<int>)':
longesttrip.cpp:16:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     else if(temp.size() == mxlen)
      |             ~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Execution timed out 3040 ms 844 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 208 KB Output is correct
2 Execution timed out 3034 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Execution timed out 3023 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Execution timed out 3018 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 208 KB Output is correct
2 Execution timed out 3049 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -