Submission #1030064

# Submission time Handle Problem Language Result Execution time Memory
1030064 2024-07-21T18:55:45 Z mindiyak Longest Trip (IOI23_longesttrip) C++17
40 / 100
885 ms 1564 KB
#include "longesttrip.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;

vvi paths;
vi visited;
vi cur_path;
int node,dis;

void dfs(int pos,int height,vi cur){
    if(visited[pos])return;
    cur.pb(pos);
    visited[pos] = 1;
    if(dis < height){
        dis = height;
        node = pos;
        cur_path = cur;
    }
    for(int a:paths[pos]){
        dfs(a,height+1,cur);
    }
}

vi longest_trip(int N, int D)
{
    paths = vvi(N);
    FOR(i,0,N){
        FOR(j,i+1,N){
            if(are_connected({i},{j})){
                paths[i].pb(j);
                paths[j].pb(i);
            }
        }
    }

    visited = vi(N,0);
    vi possibles;

    FOR(i,0,N){
        if(visited[i])continue;
        node = -1;
        dis = -1;
        vi cur;
        dfs(i,1,cur);
        possibles.pb(node);
    }

    visited = vi(N,0);
    int temp = -1;
    vi ans;

    for(int i:possibles){
        node = -1;
        dis = -1;
        vi cur;
        dfs(i,1,cur);
        if(temp < dis){
            temp = dis;
            ans = cur_path;
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 197 ms 1008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 163 ms 600 KB Output is correct
4 Correct 406 ms 932 KB Output is correct
5 Correct 780 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 30 ms 344 KB Output is correct
3 Correct 140 ms 600 KB Output is correct
4 Correct 373 ms 724 KB Output is correct
5 Correct 801 ms 1140 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 136 ms 344 KB Output is correct
9 Correct 309 ms 712 KB Output is correct
10 Correct 784 ms 1324 KB Output is correct
11 Correct 739 ms 1112 KB Output is correct
12 Correct 764 ms 1132 KB Output is correct
13 Correct 769 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 149 ms 340 KB Output is correct
4 Correct 385 ms 476 KB Output is correct
5 Correct 850 ms 1292 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 145 ms 592 KB Output is correct
9 Correct 304 ms 556 KB Output is correct
10 Correct 817 ms 1104 KB Output is correct
11 Correct 828 ms 1188 KB Output is correct
12 Correct 801 ms 1068 KB Output is correct
13 Correct 773 ms 1068 KB Output is correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 40 ms 344 KB Output is correct
17 Correct 78 ms 344 KB Output is correct
18 Correct 137 ms 344 KB Output is correct
19 Correct 315 ms 724 KB Output is correct
20 Correct 275 ms 768 KB Output is correct
21 Correct 825 ms 1252 KB Output is correct
22 Correct 825 ms 1500 KB Output is correct
23 Correct 885 ms 1372 KB Output is correct
24 Correct 837 ms 1260 KB Output is correct
25 Correct 7 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 21 ms 344 KB Output is correct
28 Correct 15 ms 344 KB Output is correct
29 Correct 21 ms 344 KB Output is correct
30 Correct 195 ms 720 KB Output is correct
31 Correct 202 ms 600 KB Output is correct
32 Correct 191 ms 344 KB Output is correct
33 Correct 314 ms 708 KB Output is correct
34 Correct 292 ms 624 KB Output is correct
35 Correct 319 ms 728 KB Output is correct
36 Correct 804 ms 1028 KB Output is correct
37 Correct 838 ms 1332 KB Output is correct
38 Correct 774 ms 1244 KB Output is correct
39 Correct 844 ms 1272 KB Output is correct
40 Correct 814 ms 892 KB Output is correct
41 Correct 785 ms 1048 KB Output is correct
42 Correct 788 ms 1268 KB Output is correct
43 Correct 799 ms 1248 KB Output is correct
44 Correct 808 ms 1368 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 13 ms 344 KB Output is correct
47 Correct 23 ms 344 KB Output is correct
48 Correct 22 ms 344 KB Output is correct
49 Correct 21 ms 344 KB Output is correct
50 Correct 210 ms 472 KB Output is correct
51 Correct 165 ms 460 KB Output is correct
52 Correct 175 ms 452 KB Output is correct
53 Correct 308 ms 484 KB Output is correct
54 Correct 244 ms 744 KB Output is correct
55 Correct 323 ms 452 KB Output is correct
56 Correct 782 ms 1052 KB Output is correct
57 Correct 780 ms 1028 KB Output is correct
58 Correct 754 ms 1152 KB Output is correct
59 Correct 801 ms 984 KB Output is correct
60 Correct 829 ms 976 KB Output is correct
61 Correct 814 ms 980 KB Output is correct
62 Correct 801 ms 852 KB Output is correct
63 Correct 800 ms 1528 KB Output is correct
64 Correct 842 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Partially correct 147 ms 444 KB Output is partially correct
4 Partially correct 396 ms 976 KB Output is partially correct
5 Partially correct 835 ms 1216 KB Output is partially correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Partially correct 132 ms 344 KB Output is partially correct
9 Partially correct 296 ms 784 KB Output is partially correct
10 Partially correct 846 ms 1304 KB Output is partially correct
11 Partially correct 793 ms 1036 KB Output is partially correct
12 Partially correct 793 ms 1564 KB Output is partially correct
13 Partially correct 856 ms 1200 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Incorrect 1 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -