Submission #992763

# Submission time Handle Problem Language Result Execution time Memory
992763 2024-06-05T06:59:52 Z Muhammet Longest Trip (IOI23_longesttrip) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

#define N 1005

using namespace std;

vector <int> v[N], v1;

int c[N], k, y;

bool vis[N][N], vi[N];

void dfs(int x){
    vi[x] = 1;
    if(k < c[x]) y = x;
    k = max(c[x], k);
    for(auto i : v[x]){
        if(vi[i] == 0){
            c[i] = c[x] + 1;
            dfs(i);
        }
    }
}

void df(int x, int z){
    v1.push_back(x);
    if(x == z) return;
    for(auto i : v[x]){
        if(c[i] == c[x] - 1){
            dfs(i);
            break;
        }
    }
}

vector<int> longest_trip(int n, int d) {
    vector <int> a(1), b(1);
    for(int i = 0; i < n; i++) v[i].clear();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            vis[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            a[0] = i;
            b[0] = j;
            if(are_connected(a, b) and vis[i][j] == 0) {
                vis[i][j] = 1;
                vis[j][i] = 1;
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }
    v1.clear();
    int mx = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) vi[j] = c[j] = 0;
        k = y = 0;
        c[i] = 1;
        dfs(i);
        if(k > mx){
            mx = k;
            v1.clear();
            df(y,i);
        }
    }
    reverse(v1.begin(), v1.end());
    return v1;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:60:49: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   60 |         for(int j = 0; j < n; j++) vi[j] = c[j] = 0;
      |                                            ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -