답안 #962164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962164 2024-04-13T08:15:01 Z serkanrashid 꿈 (IOI13_dreaming) C++14
47 / 100
62 ms 20404 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+5;

struct edge
{
    long long ver,dist;
    edge(){};
    edge(int vi, long long di)
    {
        ver = vi;
        dist = di;
    }
};

struct Point
{
    int x,y,d;
    Point(){};
    Point(int xi, int yi, int di)
    {
        x = xi;
        y = yi;
        d = di;
    }
};

int n;

vector<edge> g[MAXN];
long long sub[MAXN],used[MAXN];

long long mind,vut;
vector<long long> comp;

void clear_used()
{
    for(int i = 0; i < n; i++) used[i] = 0;
}

void clear_g()
{
    for(int i = 0; i < n; i++) g[i].clear();
}

void dfs_dp(int beg, long long gor)
{
    used[beg] = 1;
    long long maxch = max(sub[beg],gor);
    vut = max(vut,maxch);
    mind = min(mind,maxch);
    long long fir = 0, sec = 0;
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            if(nb.dist+sub[nb.ver] >= fir)
            {
                sec = fir;
                fir = nb.dist+sub[nb.ver];
            }
            else if(nb.dist+sub[nb.ver] >= sec)
            {
                sec = nb.dist+sub[nb.ver];
            }
        }
    }
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            long long new_gor = gor;
            if(nb.dist+sub[nb.ver] == fir) new_gor = max(new_gor,sec);
            else new_gor = max(new_gor,fir);
            new_gor += nb.dist;
            dfs_dp(nb.ver,new_gor);
        }
    }
}

void dfs(int beg)
{
    used[beg] = 1;
    for(edge nb : g[beg])
    {
        if(!used[nb.ver])
        {
            dfs(nb.ver);
            sub[beg] = max(sub[beg],sub[nb.ver]+nb.dist);
        }
    }
}

Point sp[MAXN];
int idx,lead[MAXN],br[MAXN];

bool cmp(Point p1, Point p2)
{
    return p1.d<p2.d;
}

int find_lead(int x)
{
    if(lead[x]==x) return x;
    return lead[x] = find_lead(lead[x]);
}

void union1(int x, int y)
{
    if(br[x]<br[y])
    {
        br[y] += br[x];
        lead[x] = y;
    }
    else
    {
        br[x] += br[y];
        lead[y] = x;
    }
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n = N;
    for(int i = 0; i < M; i++)
    {
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    for(int i = 0; i < N; i++) if(!used[i]) dfs(i);
    clear_used();
    for(int i = 0; i < N; i++)
    {
        if(!used[i])
        {
            mind = 1e9+5;
            dfs_dp(i,0);
            comp.push_back(mind);
        }
    }
    idx = 0;
    for(int i = 0; i < comp.size(); i++)
    {
        for(int j = i+1; j < comp.size(); j++)
        {
            sp[idx] = {i,j,comp[i]+comp[j]+L};
            idx++;
        }
    }
    clear_used();
    clear_g();
    for(int i = 0; i < comp.size(); i++)
    {
        lead[i] = i;
        br[i] = 1;
    }
    sort(sp,sp+idx,cmp);
    for(int i = 0; i < idx; i++)
    {
        int x = sp[i].x;
        int y = sp[i].y;
        x = find_lead(x);
        y = find_lead(y);
        if(x != y)
        {
            g[sp[i].x].push_back({sp[i].y,sp[i].d});
            g[sp[i].y].push_back({sp[i].x,sp[i].d});
            union1(x,y);
        }
    }


    ///
    memset(sub,0,sizeof(sub));
    for(int i = 0; i < comp.size(); i++) if(!used[i]) dfs(i);
    clear_used();
    long long ans = 0;
    for(int i = 0; i < comp.size(); i++)
    {
        if(!used[i])
        {
            mind = 1e9+5;
            dfs_dp(i,0);
            ans = max(ans,mind);
        }
    }
    return max(ans,vut);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:145:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |     for(int i = 0; i < comp.size(); i++)
      |                    ~~^~~~~~~~~~~~~
dreaming.cpp:147:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |         for(int j = i+1; j < comp.size(); j++)
      |                          ~~^~~~~~~~~~~~~
dreaming.cpp:149:43: warning: narrowing conversion of '((comp.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i)) + comp.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)j))) + ((__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)L))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
  149 |             sp[idx] = {i,j,comp[i]+comp[j]+L};
dreaming.cpp:155:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |     for(int i = 0; i < comp.size(); i++)
      |                    ~~^~~~~~~~~~~~~
dreaming.cpp:178:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  178 |     for(int i = 0; i < comp.size(); i++) if(!used[i]) dfs(i);
      |                    ~~^~~~~~~~~~~~~
dreaming.cpp:181:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |     for(int i = 0; i < comp.size(); i++)
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 15664 KB Output is correct
2 Correct 39 ms 15416 KB Output is correct
3 Correct 23 ms 14172 KB Output is correct
4 Correct 5 ms 8540 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 9 ms 9308 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 17 ms 10956 KB Output is correct
9 Correct 21 ms 12924 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 31 ms 13440 KB Output is correct
12 Correct 34 ms 14672 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 1 ms 7284 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7256 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 1 ms 7260 KB Output is correct
17 Correct 2 ms 7260 KB Output is correct
18 Correct 1 ms 7260 KB Output is correct
19 Correct 1 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 1 ms 7260 KB Output is correct
22 Correct 1 ms 7256 KB Output is correct
23 Correct 1 ms 7260 KB Output is correct
24 Correct 1 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 15664 KB Output is correct
2 Correct 39 ms 15416 KB Output is correct
3 Correct 23 ms 14172 KB Output is correct
4 Correct 5 ms 8540 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 9 ms 9308 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 17 ms 10956 KB Output is correct
9 Correct 21 ms 12924 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 31 ms 13440 KB Output is correct
12 Correct 34 ms 14672 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 2 ms 7256 KB Output is correct
15 Correct 1 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 1 ms 7260 KB Output is correct
18 Correct 1 ms 7260 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 1 ms 7284 KB Output is correct
21 Correct 1 ms 7260 KB Output is correct
22 Correct 1 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7256 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 1 ms 7260 KB Output is correct
30 Correct 2 ms 7260 KB Output is correct
31 Correct 1 ms 7260 KB Output is correct
32 Correct 1 ms 7260 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 1 ms 7260 KB Output is correct
35 Correct 1 ms 7256 KB Output is correct
36 Correct 1 ms 7260 KB Output is correct
37 Correct 1 ms 7260 KB Output is correct
38 Correct 2 ms 7260 KB Output is correct
39 Correct 36 ms 15660 KB Output is correct
40 Correct 31 ms 15192 KB Output is correct
41 Correct 24 ms 14220 KB Output is correct
42 Correct 5 ms 8540 KB Output is correct
43 Correct 2 ms 7260 KB Output is correct
44 Correct 2 ms 7260 KB Output is correct
45 Correct 2 ms 7260 KB Output is correct
46 Correct 1 ms 7260 KB Output is correct
47 Correct 1 ms 7260 KB Output is correct
48 Correct 2 ms 7260 KB Output is correct
49 Correct 2 ms 7260 KB Output is correct
50 Correct 2 ms 7260 KB Output is correct
51 Correct 1 ms 7260 KB Output is correct
52 Correct 2 ms 7260 KB Output is correct
53 Correct 1 ms 7260 KB Output is correct
54 Correct 1 ms 7260 KB Output is correct
55 Correct 1 ms 7256 KB Output is correct
56 Correct 2 ms 7260 KB Output is correct
57 Correct 41 ms 13368 KB Output is correct
58 Correct 42 ms 13204 KB Output is correct
59 Correct 43 ms 13076 KB Output is correct
60 Correct 40 ms 13076 KB Output is correct
61 Correct 49 ms 12880 KB Output is correct
62 Correct 41 ms 12892 KB Output is correct
63 Correct 38 ms 12604 KB Output is correct
64 Correct 37 ms 12636 KB Output is correct
65 Correct 47 ms 12576 KB Output is correct
66 Correct 38 ms 12624 KB Output is correct
67 Correct 42 ms 13080 KB Output is correct
68 Correct 41 ms 13112 KB Output is correct
69 Correct 51 ms 13080 KB Output is correct
70 Correct 43 ms 12844 KB Output is correct
71 Correct 2 ms 7260 KB Output is correct
72 Correct 2 ms 7260 KB Output is correct
73 Correct 3 ms 7260 KB Output is correct
74 Correct 2 ms 7260 KB Output is correct
75 Correct 3 ms 7260 KB Output is correct
76 Correct 2 ms 7260 KB Output is correct
77 Correct 3 ms 7260 KB Output is correct
78 Correct 3 ms 7260 KB Output is correct
79 Correct 2 ms 7260 KB Output is correct
80 Correct 43 ms 13072 KB Output is correct
81 Correct 47 ms 13336 KB Output is correct
82 Correct 50 ms 12776 KB Output is correct
83 Correct 42 ms 12884 KB Output is correct
84 Correct 2 ms 7256 KB Output is correct
85 Correct 3 ms 7276 KB Output is correct
86 Correct 2 ms 7256 KB Output is correct
87 Correct 3 ms 7256 KB Output is correct
88 Correct 2 ms 7260 KB Output is correct
89 Correct 2 ms 7256 KB Output is correct
90 Correct 2 ms 7260 KB Output is correct
91 Correct 3 ms 7472 KB Output is correct
92 Correct 2 ms 7260 KB Output is correct
93 Correct 2 ms 7260 KB Output is correct
94 Correct 1 ms 7260 KB Output is correct
95 Correct 2 ms 7260 KB Output is correct
96 Correct 1 ms 7260 KB Output is correct
97 Correct 2 ms 7260 KB Output is correct
98 Correct 1 ms 7260 KB Output is correct
99 Correct 1 ms 7260 KB Output is correct
100 Correct 2 ms 7260 KB Output is correct
101 Correct 1 ms 7088 KB Output is correct
102 Correct 2 ms 7260 KB Output is correct
103 Correct 2 ms 7260 KB Output is correct
104 Correct 5 ms 8028 KB Output is correct
105 Correct 9 ms 9308 KB Output is correct
106 Correct 2 ms 7260 KB Output is correct
107 Correct 17 ms 11100 KB Output is correct
108 Correct 23 ms 13036 KB Output is correct
109 Correct 2 ms 7260 KB Output is correct
110 Correct 30 ms 13660 KB Output is correct
111 Correct 35 ms 14636 KB Output is correct
112 Correct 2 ms 7260 KB Output is correct
113 Correct 62 ms 20404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 19928 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 1 ms 7284 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7256 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 1 ms 7260 KB Output is correct
17 Correct 2 ms 7260 KB Output is correct
18 Correct 1 ms 7260 KB Output is correct
19 Correct 1 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 1 ms 7260 KB Output is correct
22 Correct 1 ms 7256 KB Output is correct
23 Correct 1 ms 7260 KB Output is correct
24 Correct 1 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 6 ms 7260 KB Output is correct
28 Runtime error 14 ms 14684 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 15664 KB Output is correct
2 Correct 39 ms 15416 KB Output is correct
3 Correct 23 ms 14172 KB Output is correct
4 Correct 5 ms 8540 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 9 ms 9308 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 17 ms 10956 KB Output is correct
9 Correct 21 ms 12924 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 31 ms 13440 KB Output is correct
12 Correct 34 ms 14672 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 2 ms 7256 KB Output is correct
15 Correct 1 ms 7260 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 1 ms 7260 KB Output is correct
18 Correct 1 ms 7260 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 1 ms 7284 KB Output is correct
21 Correct 1 ms 7260 KB Output is correct
22 Correct 1 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7256 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 1 ms 7260 KB Output is correct
30 Correct 2 ms 7260 KB Output is correct
31 Correct 1 ms 7260 KB Output is correct
32 Correct 1 ms 7260 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 1 ms 7260 KB Output is correct
35 Correct 1 ms 7256 KB Output is correct
36 Correct 1 ms 7260 KB Output is correct
37 Correct 1 ms 7260 KB Output is correct
38 Correct 2 ms 7260 KB Output is correct
39 Correct 36 ms 15660 KB Output is correct
40 Correct 31 ms 15192 KB Output is correct
41 Correct 24 ms 14220 KB Output is correct
42 Correct 5 ms 8540 KB Output is correct
43 Correct 2 ms 7260 KB Output is correct
44 Correct 2 ms 7260 KB Output is correct
45 Correct 2 ms 7260 KB Output is correct
46 Correct 1 ms 7260 KB Output is correct
47 Correct 1 ms 7260 KB Output is correct
48 Correct 2 ms 7260 KB Output is correct
49 Correct 2 ms 7260 KB Output is correct
50 Correct 2 ms 7260 KB Output is correct
51 Correct 1 ms 7260 KB Output is correct
52 Correct 2 ms 7260 KB Output is correct
53 Correct 1 ms 7260 KB Output is correct
54 Correct 1 ms 7260 KB Output is correct
55 Correct 1 ms 7256 KB Output is correct
56 Correct 2 ms 7260 KB Output is correct
57 Correct 41 ms 13368 KB Output is correct
58 Correct 42 ms 13204 KB Output is correct
59 Correct 43 ms 13076 KB Output is correct
60 Correct 40 ms 13076 KB Output is correct
61 Correct 49 ms 12880 KB Output is correct
62 Correct 41 ms 12892 KB Output is correct
63 Correct 38 ms 12604 KB Output is correct
64 Correct 37 ms 12636 KB Output is correct
65 Correct 47 ms 12576 KB Output is correct
66 Correct 38 ms 12624 KB Output is correct
67 Correct 42 ms 13080 KB Output is correct
68 Correct 41 ms 13112 KB Output is correct
69 Correct 51 ms 13080 KB Output is correct
70 Correct 43 ms 12844 KB Output is correct
71 Correct 2 ms 7260 KB Output is correct
72 Correct 2 ms 7260 KB Output is correct
73 Correct 3 ms 7260 KB Output is correct
74 Correct 2 ms 7260 KB Output is correct
75 Correct 3 ms 7260 KB Output is correct
76 Correct 2 ms 7260 KB Output is correct
77 Correct 3 ms 7260 KB Output is correct
78 Correct 3 ms 7260 KB Output is correct
79 Correct 2 ms 7260 KB Output is correct
80 Correct 43 ms 13072 KB Output is correct
81 Correct 47 ms 13336 KB Output is correct
82 Correct 50 ms 12776 KB Output is correct
83 Correct 42 ms 12884 KB Output is correct
84 Correct 2 ms 7256 KB Output is correct
85 Correct 3 ms 7276 KB Output is correct
86 Correct 2 ms 7256 KB Output is correct
87 Correct 3 ms 7256 KB Output is correct
88 Correct 2 ms 7260 KB Output is correct
89 Correct 2 ms 7256 KB Output is correct
90 Correct 2 ms 7260 KB Output is correct
91 Correct 3 ms 7472 KB Output is correct
92 Correct 2 ms 7260 KB Output is correct
93 Correct 2 ms 7260 KB Output is correct
94 Correct 1 ms 7260 KB Output is correct
95 Correct 2 ms 7260 KB Output is correct
96 Correct 1 ms 7260 KB Output is correct
97 Correct 2 ms 7260 KB Output is correct
98 Correct 1 ms 7260 KB Output is correct
99 Correct 1 ms 7260 KB Output is correct
100 Correct 2 ms 7260 KB Output is correct
101 Correct 1 ms 7088 KB Output is correct
102 Correct 2 ms 7260 KB Output is correct
103 Correct 2 ms 7260 KB Output is correct
104 Correct 5 ms 8028 KB Output is correct
105 Correct 9 ms 9308 KB Output is correct
106 Correct 2 ms 7260 KB Output is correct
107 Correct 17 ms 11100 KB Output is correct
108 Correct 23 ms 13036 KB Output is correct
109 Correct 2 ms 7260 KB Output is correct
110 Correct 30 ms 13660 KB Output is correct
111 Correct 35 ms 14636 KB Output is correct
112 Correct 2 ms 7260 KB Output is correct
113 Correct 62 ms 20404 KB Output is correct
114 Runtime error 20 ms 19928 KB Execution killed with signal 11
115 Halted 0 ms 0 KB -