답안 #861635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861635 2023-10-16T15:25:23 Z faustaadp 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
880 ms 5348 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
const ll NN = 1e5 + 5;
vector<int> ret, ret2;
ll b[NN], n, ada = 0, mxx, now, coba = 0, ti;
vector<ll> v[NN];
void dfs(ll pos)
{
    if(ada)return ;
    b[pos] = 1;
    ret.pb(pos);
    // cout << pos << " mas " << ret.size() << "_\n";
    // cout << ret.size() << " dan " << mxx << "\n";
    coba++;
    if(ret2.size() < ret.size())ret2 = ret;
    if(coba >= 10000)ada = 2;
    if(ret.size() * 2 >= mxx)ada = 1;
    if(ada)return;
    // random_shuffle(v[pos].begin(), v[pos].end());
    for(ll i = 0; i < v[pos].size(); i++)
    {
        if(b[v[pos][i]] == 0)dfs(v[pos][i]);
        if(ada)return ;
    }
    b[pos] = 0;
    // cout << pos << " kel\n";
    ret.pop_back();
}
void dfs2(ll pos)
{
    now++;
    mxx = max(mxx, now);
    b[pos] = ti;
    for(ll i = 0; i < v[pos].size(); i++)
        if(b[v[pos][i]] == 0)
            dfs2(v[pos][i]);
}
std::vector<int> longest_trip(int N, int D)
{
    ret2.clear();
    mxx = 0;
    coba = 0;
    ada = 0;
    n = N;
    ret.clear();
    for(ll i = 0; i < N; i++)
    {
        v[i].clear();
        b[i] = 0;
    }
    for(ll i = 0; i < N; i++)
        for(ll j = i + 1; j < N; j++)
        {
            vector<int> A;A.pb(i);
            vector<int> B;B.pb(j);
            bool isi = are_connected(A, B);
            if(isi)
            {
                // cout << i << "--" << j << "\n";
                v[i].pb(j);
                v[j].pb(i);
            }
        }
    for(ll i = 0; i < N; i++)
        if(!b[i])
        {
            ti++;
            now = 0;
            dfs2(i);
        }
    for(ll i = 0; i < N; i++)
    {
        b[i] = 0;
    }
    ti = 1;
    vector<ll> cal;
    for(ll i = 0; i < N; i++)
        if(!b[i])
        {
            ti++;
            now = 0;
            dfs2(i);
            if(now != mxx)
                continue;
            for(ll j = 0; j < N; j++)
            {
                if(b[j] == ti)
                    cal.pb(j);
            }
            break;
        }
    memset(b, 0, sizeof(b));
    for(auto aa : cal)
    {
        coba = 0;
        dfs(aa);
        if(ada == 2)
            ada = 0;
    }
    return ret2;
    // ll mul = 1;
    // if(N % 2 == 0)
    // {
    //     vector<int> A;A.pb(0);
    //     vector<int> B;B.pb(1);
    //     bool isi = are_connected(A, B);
    //     if(!isi)
    //         swap(cal[1], cal[2]);
    //     ret.pb(cal[0]);
    //     ret.pb(cal[1]);
    // }
    // else
    //     ret.pb(cal[0]);
    // for(ll i = mul; i + 1 < N; i += 2)
    // {
    //     ll now = ret.back();
    //     vector<int> A;A.pb(now);
    //     vector<int> B;A.pb(cal[i]);
    //     bool isi = are_connected(A, B);
    //     if()
    // }
    // return ret;
}

Compilation message

longesttrip.cpp: In function 'void dfs(ll)':
longesttrip.cpp:20:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   20 |     if(ret.size() * 2 >= mxx)ada = 1;
      |        ~~~~~~~~~~~~~~~^~~~~~
longesttrip.cpp:23:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'void dfs2(ll)':
longesttrip.cpp:37:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(ll i = 0; i < v[pos].size(); i++)
      |                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3672 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3668 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3416 KB Output is correct
2 Correct 40 ms 3416 KB Output is correct
3 Correct 132 ms 3924 KB Output is correct
4 Correct 414 ms 4248 KB Output is correct
5 Correct 851 ms 4272 KB Output is correct
6 Correct 16 ms 3672 KB Output is correct
7 Correct 29 ms 3672 KB Output is correct
8 Correct 155 ms 3848 KB Output is correct
9 Correct 327 ms 4344 KB Output is correct
10 Correct 845 ms 4392 KB Output is correct
11 Correct 880 ms 4136 KB Output is correct
12 Correct 830 ms 4740 KB Output is correct
13 Correct 829 ms 4292 KB Output is correct
14 Correct 14 ms 3672 KB Output is correct
15 Correct 15 ms 3416 KB Output is correct
16 Correct 47 ms 3672 KB Output is correct
17 Correct 102 ms 3576 KB Output is correct
18 Correct 154 ms 3680 KB Output is correct
19 Correct 283 ms 4248 KB Output is correct
20 Correct 244 ms 3908 KB Output is correct
21 Correct 767 ms 4224 KB Output is correct
22 Correct 739 ms 4396 KB Output is correct
23 Correct 705 ms 5016 KB Output is correct
24 Correct 723 ms 5184 KB Output is correct
25 Correct 13 ms 3416 KB Output is correct
26 Correct 13 ms 3416 KB Output is correct
27 Correct 25 ms 3416 KB Output is correct
28 Correct 21 ms 3668 KB Output is correct
29 Correct 21 ms 3416 KB Output is correct
30 Correct 163 ms 4092 KB Output is correct
31 Correct 154 ms 4328 KB Output is correct
32 Correct 166 ms 4076 KB Output is correct
33 Correct 252 ms 4456 KB Output is correct
34 Correct 260 ms 4140 KB Output is correct
35 Correct 220 ms 4192 KB Output is correct
36 Correct 696 ms 4712 KB Output is correct
37 Correct 686 ms 4600 KB Output is correct
38 Correct 675 ms 5348 KB Output is correct
39 Correct 690 ms 5084 KB Output is correct
40 Correct 774 ms 5108 KB Output is correct
41 Correct 713 ms 4064 KB Output is correct
42 Correct 743 ms 4500 KB Output is correct
43 Correct 733 ms 5004 KB Output is correct
44 Correct 692 ms 5248 KB Output is correct
45 Correct 14 ms 3416 KB Output is correct
46 Correct 15 ms 3672 KB Output is correct
47 Correct 26 ms 3672 KB Output is correct
48 Correct 23 ms 3672 KB Output is correct
49 Correct 23 ms 3416 KB Output is correct
50 Correct 160 ms 4328 KB Output is correct
51 Incorrect 10 ms 4092 KB Incorrect
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Incorrect
2 Halted 0 ms 0 KB -