답안 #840880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840880 2023-08-31T19:56:52 Z Minindu206 가장 긴 여행 (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 / 2)
        {
            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)
      |             ~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Execution timed out 3015 ms 844 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 208 KB Output is correct
2 Execution timed out 3054 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 208 KB Output is correct
2 Execution timed out 3090 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 208 KB Output is correct
2 Execution timed out 3050 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 208 KB Output is correct
2 Execution timed out 3045 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -