Submission #960828

# Submission time Handle Problem Language Result Execution time Memory
960828 2024-04-11T05:49:18 Z 12345678 Longest Trip (IOI23_longesttrip) C++17
0 / 100
1000 ms 2082704 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=305;

int qrs[nx][nx], vs[nx], m, cnt, u, v;
vector<int> d[nx];

int query(int i, int j)
{
    if (i>j) swap(i, j);
    return qrs[i][j];
}

void dfs(int u)
{
    vs[u]=1;
    cnt++;
    for (auto v:d[u]) if (!vs[v]) dfs(v);
}

std::vector<int> longest_trip(int N, int D)
{
    for (int i=0; i<N; i++) d[i].clear(), vs[i]=0;
    for (int i=0; i<N; i++) for (int j=i+1; j<N; j++) qrs[i][j]=are_connected(vector<int> {i}, vector<int> {j});
    for (int i=0; i<N; i++) for (int j=0; j<N; j++) if (query(i, j)) d[i].push_back(j);
    cnt=0;
    dfs(0);
    vector<int> res;
    if (cnt!=N)
    {
        if (cnt>N/2) m=1;
        for (int i=0; i<N; i++)
        {
            if (vs[i]&&m) res.push_back(i);
            if (!vs[i]&&!m) res.push_back(i);
        }
        return res;
    }
    pair<int, int> mn={INT_MAX, 0};
    for (int i=0; i<N; i++) mn=min(mn, {d[i].size(), i});
    //cout<<"here "<<mn.first<<' '<<mn.second<<'\n';
    if (mn.first>(N/2))
    {
        for (int i=0; i<N; i++) vs[i]=0;
        queue<int> q;
        q.push(mn.second);
        vs[mn.second]=1;
        while (!q.empty())
        {
            u=q.front();
            q.pop();
            res.push_back(u);
            for (auto v:d[u]) vs[v]=1, q.push(v);
        }
    }
    else
    {
        for (int i=0; i<N; i++) if (!query(i, mn.second)&&i!=mn.second) res.push_back(i);
        return res;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
   64 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3104 ms 1649812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3120 ms 1916008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3120 ms 2082704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3122 ms 2070120 KB Time limit exceeded
2 Halted 0 ms 0 KB -