답안 #680726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680726 2023-01-11T16:23:42 Z speedyArda 꿈 (IOI13_dreaming) C++14
40 / 100
1000 ms 14944 KB
#include "dreaming.h"
#include "bits/stdc++.h"
#define pb push_back
#define pii pair<int, int>
using namespace std;
using ll = long long;
const int MAXN = 100005;
vector<vector<pair<int, int> > > adj(MAXN);
bool vis[MAXN];
pair<ll, int> down[MAXN][2];
void dfs_down(int v, int p)
{
    vis[v] = true;
    down[v][0].second = down[v][1].second = -1;

    //cout << v << "\n";
    for(pii e : adj[v])
    {
        //cout << e.first << " " << e.second << "\n";
        if(e.first == p)
            continue;
        dfs_down(e.first, v);
        ll val = down[e.first][0].first + e.second;
        if(down[v][0].first < val)
        {
            down[v][0].first = val;
            down[v][0].second = e.first;
        } else if(down[v][1].first < val)
        {
            down[v][1].first = val;
            down[v][1].second = e.first;
        }
    }

    //cout << v << " " << down[v] << "\n";
}
pair<ll, int> dfs_up(int v, int p, ll top)
{
    vis[v] = true;
    pair<ll, int> curr = {max(top, down[v][0].first), v};
    if(down[v][0].second != -1)
    {
        pii e;
        for(pii tmp : adj[v])
        {
            if(down[v][0].second == tmp.first)
                e = tmp;

        }

        pair<ll, int> temp = dfs_up(down[v][0].second, v, max(top, down[v][1].first) + e.second);
        if(curr.first > temp.first)
            curr = temp;
    }


    return curr;
}

void dfs_check(int v, int p)
{
    vis[v] = true;
    for(pii e : adj[v])
    {
        if(e.first == p)
            continue;
        dfs_check(e.first, v);
    }
}

vector<int> component;
void dfs_add(int v, int p)
{
    component.pb(v);
    for(pii e : adj[v])
    {
        if(e.first == p)
            continue;
        dfs_add(e.first, v);
    }
}

ll dfs_slow(int v, int p)
{
    vis[v] = true;
    ll maxi = 0;
    for(pii e : adj[v])
    {
        if(e.first == p)
            continue;
        ll yes = dfs_slow(e.first, v) + e.second;
        maxi = max(yes, maxi);
    }
    return maxi;
}

ll ans = 0;
ll dfs_long(int v, int p)
{
    ll max_temp = 0, max_1 = 0;

    for(pii e : adj[v])
    {
        if(e.first == p)
            continue;
        ll temp = dfs_long(e.first, v) + e.second;
        max_temp = max(max_temp, max_1 + temp);
        max_1 = max(max_1, temp);
    }
    
    ans = max(ans, max_temp);
    return max_1;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    
    for(int i = 0; i < M; i++)
    {
        adj[A[i]].pb({B[i], T[i]});
        adj[B[i]].pb({A[i], T[i]});
    }
    for(int i = 0; i < N; i++)
    {
        //cout << i << "\n";
        if(!vis[i])
            dfs_down(i, -1);
        //cout << i << "\n";
    }    

    for(int i = 0; i < N; i++)
        vis[i] = false;
    vector< pair<ll, int> > root_nodes;
    for(int i = 0; i < N; i++)
    {
        if(!vis[i])
        {
            
            //cout << i << "\n";
            dfs_add(i, -1);
            pair<ll, int> temp = {1e9+5, 0};
            for(int e : component)
            {
                //cout << e << "\n";
                ll tmp_big = dfs_slow(e, -1);
                if(tmp_big <= temp.first)
                    temp = {tmp_big, e};
            }
            //pair<ll, int> temp = dfs_up(i, -1, 0);
            //dfs_check(i, -1);
            //cout << i << " " << temp.first << " " << temp.second << "\n";
            root_nodes.pb(temp);
        }
        component.clear();
    }

    sort(root_nodes.begin(), root_nodes.end());
    reverse(root_nodes.begin(), root_nodes.end());
    int from = root_nodes[0].second;
    //cout << root_nodes.size() << "\n";
    for(int i = 1; i < root_nodes.size(); i++)
    {
        int to = root_nodes[i].second;
        adj[from].pb({to, L});
        adj[to].pb({from, L});
        //cout << from << " " << to << "\n";
    }

    dfs_long(0, -1);
    return ans;

}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:160:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |     for(int i = 1; i < root_nodes.size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 14944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2672 KB Output is correct
4 Correct 2 ms 2676 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2680 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2672 KB Output is correct
11 Correct 2 ms 2676 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2680 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2684 KB Output is correct
18 Correct 3 ms 2680 KB Output is correct
19 Correct 2 ms 2676 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2672 KB Output is correct
25 Correct 2 ms 2676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 14944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 10848 KB Output is correct
2 Correct 40 ms 10928 KB Output is correct
3 Correct 42 ms 10812 KB Output is correct
4 Correct 54 ms 10904 KB Output is correct
5 Correct 37 ms 10804 KB Output is correct
6 Correct 36 ms 11864 KB Output is correct
7 Correct 35 ms 11248 KB Output is correct
8 Correct 31 ms 10712 KB Output is correct
9 Correct 32 ms 10584 KB Output is correct
10 Correct 38 ms 11180 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 23 ms 11368 KB Output is correct
13 Correct 25 ms 11324 KB Output is correct
14 Correct 23 ms 11244 KB Output is correct
15 Correct 22 ms 11340 KB Output is correct
16 Correct 22 ms 11256 KB Output is correct
17 Correct 23 ms 11320 KB Output is correct
18 Correct 20 ms 11260 KB Output is correct
19 Correct 22 ms 11324 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2680 KB Output is correct
22 Correct 3 ms 2928 KB Output is correct
23 Correct 26 ms 11332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 3 ms 2672 KB Output is correct
4 Correct 2 ms 2676 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2680 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2672 KB Output is correct
11 Correct 2 ms 2676 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2680 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2684 KB Output is correct
18 Correct 3 ms 2680 KB Output is correct
19 Correct 2 ms 2676 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2672 KB Output is correct
25 Correct 2 ms 2676 KB Output is correct
26 Correct 2 ms 2684 KB Output is correct
27 Correct 4 ms 2772 KB Output is correct
28 Correct 5 ms 2908 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 3 ms 2900 KB Output is correct
31 Correct 4 ms 2900 KB Output is correct
32 Correct 2 ms 2692 KB Output is correct
33 Correct 5 ms 2852 KB Output is correct
34 Correct 4 ms 2940 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2668 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 158 ms 3156 KB Output is correct
55 Correct 181 ms 3068 KB Output is correct
56 Correct 3 ms 2900 KB Output is correct
57 Correct 2 ms 2900 KB Output is correct
58 Correct 64 ms 2900 KB Output is correct
59 Correct 93 ms 2900 KB Output is correct
60 Correct 3 ms 3028 KB Output is correct
61 Correct 3 ms 2900 KB Output is correct
62 Correct 63 ms 2900 KB Output is correct
63 Correct 60 ms 2900 KB Output is correct
64 Correct 2 ms 2900 KB Output is correct
65 Correct 3 ms 2948 KB Output is correct
66 Correct 116 ms 2980 KB Output is correct
67 Correct 59 ms 2940 KB Output is correct
68 Correct 3 ms 2900 KB Output is correct
69 Correct 3 ms 2944 KB Output is correct
70 Correct 3 ms 2900 KB Output is correct
71 Correct 2 ms 2900 KB Output is correct
72 Correct 97 ms 2900 KB Output is correct
73 Correct 97 ms 2900 KB Output is correct
74 Correct 6 ms 2900 KB Output is correct
75 Correct 4 ms 2900 KB Output is correct
76 Correct 67 ms 2900 KB Output is correct
77 Correct 90 ms 2948 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 3 ms 2836 KB Output is correct
80 Correct 2 ms 2900 KB Output is correct
81 Correct 3 ms 2928 KB Output is correct
82 Correct 4 ms 2944 KB Output is correct
83 Correct 3 ms 2900 KB Output is correct
84 Correct 11 ms 2956 KB Output is correct
85 Correct 2 ms 2900 KB Output is correct
86 Correct 35 ms 2908 KB Output is correct
87 Correct 97 ms 2964 KB Output is correct
88 Correct 3 ms 2968 KB Output is correct
89 Correct 2 ms 2900 KB Output is correct
90 Correct 2 ms 2940 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 29 ms 2900 KB Output is correct
93 Correct 35 ms 2900 KB Output is correct
94 Correct 37 ms 2900 KB Output is correct
95 Correct 47 ms 2900 KB Output is correct
96 Correct 46 ms 3028 KB Output is correct
97 Correct 38 ms 2900 KB Output is correct
98 Correct 45 ms 2900 KB Output is correct
99 Correct 91 ms 2900 KB Output is correct
100 Correct 65 ms 2900 KB Output is correct
101 Correct 59 ms 2848 KB Output is correct
102 Correct 2 ms 2644 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 2 ms 2644 KB Output is correct
105 Correct 2 ms 2600 KB Output is correct
106 Correct 2 ms 2676 KB Output is correct
107 Correct 2 ms 2644 KB Output is correct
108 Correct 1 ms 2644 KB Output is correct
109 Correct 2 ms 2644 KB Output is correct
110 Correct 2 ms 2644 KB Output is correct
111 Correct 2 ms 2676 KB Output is correct
112 Correct 3 ms 2680 KB Output is correct
113 Correct 8 ms 2900 KB Output is correct
114 Correct 9 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 14944 KB Time limit exceeded
2 Halted 0 ms 0 KB -