답안 #962166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962166 2024-04-13T08:17:07 Z serkanrashid 꿈 (IOI13_dreaming) C++14
47 / 100
60 ms 65536 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[90*MAXN];
int idx,lead[90*MAXN],br[90*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 33 ms 19440 KB Output is correct
2 Correct 32 ms 19028 KB Output is correct
3 Correct 31 ms 18004 KB Output is correct
4 Correct 7 ms 12380 KB Output is correct
5 Correct 8 ms 11868 KB Output is correct
6 Correct 10 ms 13216 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 18 ms 14936 KB Output is correct
9 Correct 22 ms 16960 KB Output is correct
10 Correct 2 ms 11244 KB Output is correct
11 Correct 31 ms 17500 KB Output is correct
12 Correct 41 ms 18516 KB Output is correct
13 Correct 2 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 2 ms 11096 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11100 KB Output is correct
11 Correct 2 ms 11172 KB Output is correct
12 Correct 2 ms 11100 KB Output is correct
13 Correct 3 ms 11100 KB Output is correct
14 Correct 2 ms 11096 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11156 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 2 ms 11100 KB Output is correct
25 Correct 3 ms 11100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 19440 KB Output is correct
2 Correct 32 ms 19028 KB Output is correct
3 Correct 31 ms 18004 KB Output is correct
4 Correct 7 ms 12380 KB Output is correct
5 Correct 8 ms 11868 KB Output is correct
6 Correct 10 ms 13216 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 18 ms 14936 KB Output is correct
9 Correct 22 ms 16960 KB Output is correct
10 Correct 2 ms 11244 KB Output is correct
11 Correct 31 ms 17500 KB Output is correct
12 Correct 41 ms 18516 KB Output is correct
13 Correct 2 ms 11096 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11096 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11100 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11096 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 2 ms 11172 KB Output is correct
25 Correct 2 ms 11100 KB Output is correct
26 Correct 3 ms 11100 KB Output is correct
27 Correct 2 ms 11096 KB Output is correct
28 Correct 2 ms 11100 KB Output is correct
29 Correct 2 ms 11100 KB Output is correct
30 Correct 2 ms 11100 KB Output is correct
31 Correct 2 ms 11096 KB Output is correct
32 Correct 2 ms 11100 KB Output is correct
33 Correct 2 ms 11156 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 2 ms 11100 KB Output is correct
37 Correct 2 ms 11100 KB Output is correct
38 Correct 3 ms 11100 KB Output is correct
39 Correct 49 ms 19540 KB Output is correct
40 Correct 33 ms 19036 KB Output is correct
41 Correct 23 ms 18008 KB Output is correct
42 Correct 6 ms 12384 KB Output is correct
43 Correct 2 ms 11352 KB Output is correct
44 Correct 2 ms 11100 KB Output is correct
45 Correct 3 ms 11096 KB Output is correct
46 Correct 3 ms 11096 KB Output is correct
47 Correct 2 ms 11100 KB Output is correct
48 Correct 2 ms 10928 KB Output is correct
49 Correct 2 ms 11100 KB Output is correct
50 Correct 2 ms 11100 KB Output is correct
51 Correct 2 ms 11096 KB Output is correct
52 Correct 2 ms 11100 KB Output is correct
53 Correct 2 ms 11100 KB Output is correct
54 Correct 2 ms 11096 KB Output is correct
55 Correct 2 ms 11100 KB Output is correct
56 Correct 2 ms 11100 KB Output is correct
57 Correct 46 ms 17028 KB Output is correct
58 Correct 43 ms 17460 KB Output is correct
59 Correct 46 ms 16720 KB Output is correct
60 Correct 53 ms 16852 KB Output is correct
61 Correct 49 ms 16720 KB Output is correct
62 Correct 42 ms 16748 KB Output is correct
63 Correct 40 ms 16468 KB Output is correct
64 Correct 39 ms 16432 KB Output is correct
65 Correct 40 ms 16476 KB Output is correct
66 Correct 39 ms 16260 KB Output is correct
67 Correct 47 ms 16724 KB Output is correct
68 Correct 46 ms 16832 KB Output is correct
69 Correct 59 ms 16928 KB Output is correct
70 Correct 44 ms 16948 KB Output is correct
71 Correct 2 ms 11096 KB Output is correct
72 Correct 3 ms 11356 KB Output is correct
73 Correct 4 ms 11512 KB Output is correct
74 Correct 3 ms 11096 KB Output is correct
75 Correct 3 ms 11100 KB Output is correct
76 Correct 3 ms 11356 KB Output is correct
77 Correct 3 ms 11356 KB Output is correct
78 Correct 3 ms 11356 KB Output is correct
79 Correct 4 ms 11356 KB Output is correct
80 Correct 44 ms 16696 KB Output is correct
81 Correct 47 ms 16720 KB Output is correct
82 Correct 50 ms 16728 KB Output is correct
83 Correct 60 ms 16768 KB Output is correct
84 Correct 3 ms 11100 KB Output is correct
85 Correct 2 ms 11100 KB Output is correct
86 Correct 3 ms 11100 KB Output is correct
87 Correct 3 ms 11096 KB Output is correct
88 Correct 3 ms 11100 KB Output is correct
89 Correct 3 ms 11096 KB Output is correct
90 Correct 3 ms 11100 KB Output is correct
91 Correct 3 ms 11100 KB Output is correct
92 Correct 3 ms 11096 KB Output is correct
93 Correct 3 ms 11100 KB Output is correct
94 Correct 2 ms 11100 KB Output is correct
95 Correct 2 ms 11352 KB Output is correct
96 Correct 2 ms 11100 KB Output is correct
97 Correct 2 ms 11100 KB Output is correct
98 Correct 2 ms 11168 KB Output is correct
99 Correct 2 ms 11100 KB Output is correct
100 Correct 2 ms 11100 KB Output is correct
101 Correct 2 ms 11100 KB Output is correct
102 Correct 2 ms 11100 KB Output is correct
103 Correct 2 ms 11100 KB Output is correct
104 Correct 5 ms 11868 KB Output is correct
105 Correct 9 ms 13148 KB Output is correct
106 Correct 3 ms 11096 KB Output is correct
107 Correct 21 ms 14928 KB Output is correct
108 Correct 24 ms 16988 KB Output is correct
109 Correct 2 ms 11096 KB Output is correct
110 Correct 32 ms 17500 KB Output is correct
111 Correct 44 ms 18516 KB Output is correct
112 Correct 3 ms 11100 KB Output is correct
113 Correct 55 ms 24152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 2 ms 11096 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11100 KB Output is correct
11 Correct 2 ms 11172 KB Output is correct
12 Correct 2 ms 11100 KB Output is correct
13 Correct 3 ms 11100 KB Output is correct
14 Correct 2 ms 11096 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11156 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 2 ms 11100 KB Output is correct
25 Correct 3 ms 11100 KB Output is correct
26 Correct 5 ms 11100 KB Output is correct
27 Correct 5 ms 13148 KB Output is correct
28 Correct 10 ms 13148 KB Output is correct
29 Incorrect 3 ms 11096 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 19440 KB Output is correct
2 Correct 32 ms 19028 KB Output is correct
3 Correct 31 ms 18004 KB Output is correct
4 Correct 7 ms 12380 KB Output is correct
5 Correct 8 ms 11868 KB Output is correct
6 Correct 10 ms 13216 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 18 ms 14936 KB Output is correct
9 Correct 22 ms 16960 KB Output is correct
10 Correct 2 ms 11244 KB Output is correct
11 Correct 31 ms 17500 KB Output is correct
12 Correct 41 ms 18516 KB Output is correct
13 Correct 2 ms 11096 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11096 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11100 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11096 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 2 ms 11172 KB Output is correct
25 Correct 2 ms 11100 KB Output is correct
26 Correct 3 ms 11100 KB Output is correct
27 Correct 2 ms 11096 KB Output is correct
28 Correct 2 ms 11100 KB Output is correct
29 Correct 2 ms 11100 KB Output is correct
30 Correct 2 ms 11100 KB Output is correct
31 Correct 2 ms 11096 KB Output is correct
32 Correct 2 ms 11100 KB Output is correct
33 Correct 2 ms 11156 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 2 ms 11100 KB Output is correct
37 Correct 2 ms 11100 KB Output is correct
38 Correct 3 ms 11100 KB Output is correct
39 Correct 49 ms 19540 KB Output is correct
40 Correct 33 ms 19036 KB Output is correct
41 Correct 23 ms 18008 KB Output is correct
42 Correct 6 ms 12384 KB Output is correct
43 Correct 2 ms 11352 KB Output is correct
44 Correct 2 ms 11100 KB Output is correct
45 Correct 3 ms 11096 KB Output is correct
46 Correct 3 ms 11096 KB Output is correct
47 Correct 2 ms 11100 KB Output is correct
48 Correct 2 ms 10928 KB Output is correct
49 Correct 2 ms 11100 KB Output is correct
50 Correct 2 ms 11100 KB Output is correct
51 Correct 2 ms 11096 KB Output is correct
52 Correct 2 ms 11100 KB Output is correct
53 Correct 2 ms 11100 KB Output is correct
54 Correct 2 ms 11096 KB Output is correct
55 Correct 2 ms 11100 KB Output is correct
56 Correct 2 ms 11100 KB Output is correct
57 Correct 46 ms 17028 KB Output is correct
58 Correct 43 ms 17460 KB Output is correct
59 Correct 46 ms 16720 KB Output is correct
60 Correct 53 ms 16852 KB Output is correct
61 Correct 49 ms 16720 KB Output is correct
62 Correct 42 ms 16748 KB Output is correct
63 Correct 40 ms 16468 KB Output is correct
64 Correct 39 ms 16432 KB Output is correct
65 Correct 40 ms 16476 KB Output is correct
66 Correct 39 ms 16260 KB Output is correct
67 Correct 47 ms 16724 KB Output is correct
68 Correct 46 ms 16832 KB Output is correct
69 Correct 59 ms 16928 KB Output is correct
70 Correct 44 ms 16948 KB Output is correct
71 Correct 2 ms 11096 KB Output is correct
72 Correct 3 ms 11356 KB Output is correct
73 Correct 4 ms 11512 KB Output is correct
74 Correct 3 ms 11096 KB Output is correct
75 Correct 3 ms 11100 KB Output is correct
76 Correct 3 ms 11356 KB Output is correct
77 Correct 3 ms 11356 KB Output is correct
78 Correct 3 ms 11356 KB Output is correct
79 Correct 4 ms 11356 KB Output is correct
80 Correct 44 ms 16696 KB Output is correct
81 Correct 47 ms 16720 KB Output is correct
82 Correct 50 ms 16728 KB Output is correct
83 Correct 60 ms 16768 KB Output is correct
84 Correct 3 ms 11100 KB Output is correct
85 Correct 2 ms 11100 KB Output is correct
86 Correct 3 ms 11100 KB Output is correct
87 Correct 3 ms 11096 KB Output is correct
88 Correct 3 ms 11100 KB Output is correct
89 Correct 3 ms 11096 KB Output is correct
90 Correct 3 ms 11100 KB Output is correct
91 Correct 3 ms 11100 KB Output is correct
92 Correct 3 ms 11096 KB Output is correct
93 Correct 3 ms 11100 KB Output is correct
94 Correct 2 ms 11100 KB Output is correct
95 Correct 2 ms 11352 KB Output is correct
96 Correct 2 ms 11100 KB Output is correct
97 Correct 2 ms 11100 KB Output is correct
98 Correct 2 ms 11168 KB Output is correct
99 Correct 2 ms 11100 KB Output is correct
100 Correct 2 ms 11100 KB Output is correct
101 Correct 2 ms 11100 KB Output is correct
102 Correct 2 ms 11100 KB Output is correct
103 Correct 2 ms 11100 KB Output is correct
104 Correct 5 ms 11868 KB Output is correct
105 Correct 9 ms 13148 KB Output is correct
106 Correct 3 ms 11096 KB Output is correct
107 Correct 21 ms 14928 KB Output is correct
108 Correct 24 ms 16988 KB Output is correct
109 Correct 2 ms 11096 KB Output is correct
110 Correct 32 ms 17500 KB Output is correct
111 Correct 44 ms 18516 KB Output is correct
112 Correct 3 ms 11100 KB Output is correct
113 Correct 55 ms 24152 KB Output is correct
114 Runtime error 36 ms 65536 KB Execution killed with signal 9
115 Halted 0 ms 0 KB -