답안 #840069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840069 2023-08-31T04:46:24 Z Fysty 가장 긴 여행 (IOI23_longesttrip) C++17
60 / 100
565 ms 848 KB
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;

ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll tmp=1;
    for(ll cur=a;b;b>>=1,cur=cur*cur%m) if(b&1) tmp=tmp*cur%m;
    return tmp;
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)

#include "longesttrip.h"

int has[300][300];
vector<int> ed[300];
bool vis[300];
int par[300];
int deg[300],cnt[300];
int n;

void dfs(int u)
{
    vis[u]=1;
    rep(v,n) if(!vis[v])
    {
        if(has[u][v]==-1)
        {
            has[u][v]=has[v][u]=are_connected({u},{v});
        }
        if(has[u][v]==0) continue;
        par[v]=u;
        cnt[u]++;
        dfs(v);
    }
}

void dfs2(int u,vector<int> &ret)
{
    vis[u]=1;
    ret.pb(u);
    rep(v,n) if(!vis[v])
    {
        if(has[u][v]==-1)
        {
            has[u][v]=has[v][u]=are_connected({u},{v});
        }
        if(has[u][v]==0) continue;
        dfs2(v,ret);
    }
}



/*bool db[300][300];

bool are_connected(vector<int> a,vector<int> b)
{
    bool ret=0;
    for(int x:a) for(int y:b)
    {
        ret|=db[x][y];
    }
    return ret;
}*/

vector<int> longest_trip(int N,int D)
{
    n=N;
    rep(i,n)
    {
        rep(j,n)
        {
            has[i][j]=-1;
        }
        ed[i].clear();
        vis[i]=0;
        par[i]=-1;
        deg[i]=cnt[i]=0;
    }
    vector<int> ret;
    if(D==3)
    {
        rep(i,n) ret.pb(i);
        return ret;
    }
    /*rep(i,n) rep(j,i)
    {
        bool res=are_connected({i},{j});
        if(res)
        {
            ed[i].pb(j);
            ed[j].pb(i);
            has[i][j]=has[j][i]=1;
            deg[i]++,deg[j]++;
        }
    }*/
    par[0]=-1;
    dfs(0);
    vector<int> a,b;
    rep(i,n)
    {
        if(vis[i]) a.pb(i);
        else b.pb(i);
    }
    if(!b.empty())
    {
        if(a.size()>b.size()) return a;
        else return b;
    }
    /*int r=-1;
    rep(i,n)
    {
        vis[i]=0;
        if(deg[i]==1) r=i;
    }
    if(r!=-1)
    {
        dfs2(r,ret);
        return ret;
    }*/
    rep(i,n) vis[i]=0;
    vector<int> tmp;
    int x;
    rep(i,n)
    {
        if(cnt[i]==0) tmp.pb(i);
        if(cnt[i]==2) x=i;
    }
    if(tmp.size()==1)
    {
        int cur=tmp[0];
        while(cur!=-1)
        {
            ret.pb(cur);
            cur=par[cur];
        }
        return ret;
    }
    vector<int> ret2;
    int cur=tmp[0];
    while(cur!=par[x])
    {
        ret.pb(cur);
        cur=par[cur];
    }
    cur=tmp[1];
    while(cur!=x)
    {
        ret2.pb(cur);
        cur=par[cur];
    }
    reverse(ret2.begin(),ret2.end());
    for(int v:ret2) ret.pb(v);
    if(x==0) return ret;

    vector<int> ret3;
    cur=par[x];
    while(cur!=-1)
    {
        ret3.pb(cur);
        cur=par[cur];
    }
    if(has[par[x]][tmp[0]]==-1)
    {
        has[par[x]][tmp[0]]=are_connected({par[x]},{tmp[0]});
    }
    if(has[par[x]][tmp[0]])
    {
        reverse(ret.begin(),ret.end());
    }
    for(int v:ret3) ret.pb(v);
    return ret;
}

/*
void solve()
{
    int N,D;
    cin>>N>>D;
    rep(i,N)
    {
        rep(j,N) cin>>db[i][j];
    }
    auto ans=longest_trip(N,D);
    for(int x:ans) cout<<x<<" ";
}

signed main()
{
    MottoHayaku

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}*/

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:186:14: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
  186 |     cur=par[x];
      |         ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 8 ms 464 KB Output is correct
5 Correct 8 ms 720 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 8 ms 336 KB Output is correct
9 Correct 8 ms 336 KB Output is correct
10 Correct 10 ms 592 KB Output is correct
11 Correct 7 ms 592 KB Output is correct
12 Correct 10 ms 592 KB Output is correct
13 Correct 7 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 8 ms 336 KB Output is correct
4 Correct 9 ms 464 KB Output is correct
5 Correct 10 ms 592 KB Output is correct
6 Correct 11 ms 208 KB Output is correct
7 Correct 10 ms 208 KB Output is correct
8 Correct 10 ms 336 KB Output is correct
9 Correct 9 ms 336 KB Output is correct
10 Correct 9 ms 592 KB Output is correct
11 Correct 7 ms 592 KB Output is correct
12 Correct 6 ms 592 KB Output is correct
13 Correct 7 ms 592 KB Output is correct
14 Correct 11 ms 208 KB Output is correct
15 Correct 14 ms 208 KB Output is correct
16 Correct 14 ms 336 KB Output is correct
17 Correct 13 ms 336 KB Output is correct
18 Correct 12 ms 336 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 10 ms 336 KB Output is correct
21 Correct 12 ms 644 KB Output is correct
22 Correct 11 ms 620 KB Output is correct
23 Correct 11 ms 592 KB Output is correct
24 Correct 11 ms 592 KB Output is correct
25 Correct 10 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 10 ms 208 KB Output is correct
28 Correct 16 ms 220 KB Output is correct
29 Correct 11 ms 208 KB Output is correct
30 Correct 17 ms 336 KB Output is correct
31 Correct 77 ms 336 KB Output is correct
32 Correct 137 ms 336 KB Output is correct
33 Correct 13 ms 464 KB Output is correct
34 Correct 36 ms 336 KB Output is correct
35 Correct 41 ms 336 KB Output is correct
36 Correct 12 ms 592 KB Output is correct
37 Correct 64 ms 592 KB Output is correct
38 Correct 248 ms 716 KB Output is correct
39 Correct 368 ms 636 KB Output is correct
40 Correct 468 ms 612 KB Output is correct
41 Correct 343 ms 628 KB Output is correct
42 Correct 476 ms 752 KB Output is correct
43 Correct 398 ms 592 KB Output is correct
44 Correct 539 ms 612 KB Output is correct
45 Correct 12 ms 208 KB Output is correct
46 Correct 13 ms 208 KB Output is correct
47 Correct 15 ms 208 KB Output is correct
48 Correct 14 ms 208 KB Output is correct
49 Correct 10 ms 208 KB Output is correct
50 Correct 14 ms 336 KB Output is correct
51 Correct 75 ms 336 KB Output is correct
52 Correct 80 ms 396 KB Output is correct
53 Correct 10 ms 336 KB Output is correct
54 Correct 31 ms 336 KB Output is correct
55 Correct 29 ms 336 KB Output is correct
56 Correct 15 ms 592 KB Output is correct
57 Correct 50 ms 592 KB Output is correct
58 Correct 152 ms 748 KB Output is correct
59 Correct 221 ms 592 KB Output is correct
60 Correct 190 ms 640 KB Output is correct
61 Correct 453 ms 632 KB Output is correct
62 Correct 270 ms 712 KB Output is correct
63 Correct 343 ms 612 KB Output is correct
64 Correct 311 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 208 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Correct 9 ms 336 KB Output is correct
4 Correct 10 ms 464 KB Output is correct
5 Correct 11 ms 592 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 11 ms 336 KB Output is correct
10 Correct 11 ms 592 KB Output is correct
11 Correct 7 ms 592 KB Output is correct
12 Correct 10 ms 592 KB Output is correct
13 Correct 7 ms 592 KB Output is correct
14 Correct 11 ms 260 KB Output is correct
15 Correct 15 ms 208 KB Output is correct
16 Correct 15 ms 336 KB Output is correct
17 Correct 14 ms 336 KB Output is correct
18 Correct 11 ms 336 KB Output is correct
19 Correct 10 ms 452 KB Output is correct
20 Correct 9 ms 336 KB Output is correct
21 Correct 11 ms 208 KB Output is correct
22 Correct 7 ms 208 KB Output is correct
23 Correct 16 ms 208 KB Output is correct
24 Correct 12 ms 208 KB Output is correct
25 Correct 16 ms 208 KB Output is correct
26 Correct 13 ms 336 KB Output is correct
27 Partially correct 97 ms 336 KB Output is partially correct
28 Partially correct 107 ms 336 KB Output is partially correct
29 Correct 16 ms 336 KB Output is correct
30 Correct 35 ms 336 KB Output is correct
31 Partially correct 56 ms 336 KB Output is partially correct
32 Correct 9 ms 208 KB Output is correct
33 Correct 11 ms 208 KB Output is correct
34 Correct 8 ms 388 KB Output is correct
35 Correct 11 ms 208 KB Output is correct
36 Correct 10 ms 208 KB Output is correct
37 Correct 15 ms 336 KB Output is correct
38 Partially correct 44 ms 336 KB Output is partially correct
39 Partially correct 84 ms 336 KB Output is partially correct
40 Correct 17 ms 336 KB Output is correct
41 Correct 25 ms 452 KB Output is correct
42 Partially correct 37 ms 336 KB Output is partially correct
43 Correct 12 ms 592 KB Output is correct
44 Correct 10 ms 592 KB Output is correct
45 Correct 11 ms 592 KB Output is correct
46 Correct 7 ms 592 KB Output is correct
47 Partially correct 21 ms 592 KB Output is partially correct
48 Partially correct 81 ms 636 KB Output is partially correct
49 Partially correct 234 ms 628 KB Output is partially correct
50 Partially correct 408 ms 616 KB Output is partially correct
51 Partially correct 386 ms 640 KB Output is partially correct
52 Partially correct 377 ms 652 KB Output is partially correct
53 Partially correct 400 ms 848 KB Output is partially correct
54 Partially correct 565 ms 716 KB Output is partially correct
55 Partially correct 383 ms 632 KB Output is partially correct
56 Partially correct 57 ms 592 KB Output is partially correct
57 Partially correct 297 ms 636 KB Output is partially correct
58 Partially correct 331 ms 628 KB Output is partially correct
59 Partially correct 496 ms 628 KB Output is partially correct
60 Partially correct 458 ms 628 KB Output is partially correct
61 Partially correct 437 ms 720 KB Output is partially correct
62 Partially correct 10 ms 592 KB Output is partially correct
63 Partially correct 68 ms 592 KB Output is partially correct
64 Partially correct 188 ms 592 KB Output is partially correct
65 Partially correct 236 ms 636 KB Output is partially correct
66 Partially correct 293 ms 628 KB Output is partially correct
67 Partially correct 316 ms 720 KB Output is partially correct
68 Partially correct 236 ms 680 KB Output is partially correct
69 Partially correct 340 ms 620 KB Output is partially correct
70 Partially correct 375 ms 608 KB Output is partially correct
71 Partially correct 70 ms 644 KB Output is partially correct
72 Partially correct 162 ms 720 KB Output is partially correct
73 Partially correct 194 ms 640 KB Output is partially correct
74 Partially correct 279 ms 640 KB Output is partially correct
75 Partially correct 392 ms 640 KB Output is partially correct
76 Partially correct 322 ms 720 KB Output is partially correct
77 Partially correct 47 ms 592 KB Output is partially correct
78 Partially correct 234 ms 632 KB Output is partially correct
79 Partially correct 258 ms 756 KB Output is partially correct
80 Partially correct 239 ms 724 KB Output is partially correct
81 Partially correct 255 ms 728 KB Output is partially correct
82 Partially correct 315 ms 748 KB Output is partially correct