답안 #962154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962154 2024-04-13T07:57:32 Z simona1230 꿈 (IOI13_dreaming) C++17
47 / 100
51 ms 21344 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;
int n,m,k;
vector<pair<int,int> > v[100001];
int c[100001],num;
int in;
int r[100001];
int lp[1000001];
int furt[100001],ver[100001];
int sfurt[100001];
int act[100001];

void prec(int i,int p)
{
    c[i]=num;
    for(int j=0; j<v[i].size(); j++)
    {
        int nb=v[i][j].first;
        if(nb!=p)
        {
            lp[nb]=v[i][j].second;
            prec(nb,i);
        }
    }
}

int up[100001];
int minn[100001];
int dfs(int i,int p)
{
    if(v[i].size()==1&&p||v[i].size()==0)return 0;
    int curr=0,f1=0,f2=0;
    for(int j=0; j<v[i].size(); j++)
    {
        int nb=v[i][j].first;
        if(nb==p)continue;
        int f=dfs(nb,i)+v[i][j].second;
        if(furt[i]<f)
        {
            sfurt[i]=furt[i];
            furt[i]=f;
            ver[i]=nb;
        }
        else sfurt[i]=max(sfurt[i],f);
        curr=max(curr,f);
        if(f>=f1)
        {
            f2=f1;
            f1=f;
        }
        else if(f>=f2)
        {
            f2=f;
        }
    }

    in=max(in,f1+f2);
    //cout<<i-1<<": "<<furt[i]<<" "<<ver[i]<<" "<<sfurt[i]<<endl;

    //cout<<i<<" - "<<curr<<endl;
    return curr;
}

void up_(int i,int p)
{
    for(int j=0;j<v[i].size();j++)
    {
        int nb=v[i][j].first;
        if(nb==p)continue;
        int add=furt[i];
        if(ver[i]==nb)add=sfurt[i];
        up[nb]=lp[nb]+max(up[i],add);
        up_(nb,i);
        //cout<<nb-1<<" // "<<up[nb]<<endl;
    }
}

int solve()
{
    for(int i=1; i<=num; i++)
    {
        minn[i]=1e9;
        //cout<<"** "<<r[i]-1<<endl;
        dfs(r[i],0);
        up_(r[i],0);
    }

    for(int i=1; i<=n; i++)
    {
        //cout<<c[i]<<" "<<i<<" "<<dfs(i,0)<<endl;
        minn[c[i]]=min(minn[c[i]],max(furt[i],up[i]));
    }

    sort(minn+1,minn+num+1);
    return max(k+minn[num]+minn[num-1],in);
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n=N;
    m=M;
    k=L;
    //cout<<n<<" "<<m<<" "<<k<<endl;

    for(int i=0;i<m;i++)
    {
        A[i]++;
        B[i]++;
        //cout<<A[i]<<" "<<B[i]<<" "<<T[i]<<endl;
        v[A[i]].push_back({B[i],T[i]});
        v[B[i]].push_back({A[i],T[i]});
    }

    for(int i=1; i<=n; i++)
        if(!c[i])
        {
            num++;
            r[num]=i;
            prec(i,0);
        }
    return solve();
}


/*
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
*/

Compilation message

dreaming.cpp: In function 'void prec(int, int)':
dreaming.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
dreaming.cpp: In function 'int dfs(int, int)':
dreaming.cpp:33:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   33 |     if(v[i].size()==1&&p||v[i].size()==0)return 0;
      |        ~~~~~~~~~~~~~~^~~
dreaming.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
dreaming.cpp: In function 'void up_(int, int)':
dreaming.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int j=0;j<v[i].size();j++)
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 16776 KB Output is correct
2 Correct 33 ms 16468 KB Output is correct
3 Correct 27 ms 15700 KB Output is correct
4 Correct 6 ms 9816 KB Output is correct
5 Correct 5 ms 9308 KB Output is correct
6 Correct 9 ms 10332 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 18 ms 12024 KB Output is correct
9 Correct 23 ms 13956 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 30 ms 14172 KB Output is correct
12 Correct 42 ms 15264 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 16776 KB Output is correct
2 Correct 33 ms 16468 KB Output is correct
3 Correct 27 ms 15700 KB Output is correct
4 Correct 6 ms 9816 KB Output is correct
5 Correct 5 ms 9308 KB Output is correct
6 Correct 9 ms 10332 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 18 ms 12024 KB Output is correct
9 Correct 23 ms 13956 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 30 ms 14172 KB Output is correct
12 Correct 42 ms 15264 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8536 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 1 ms 8536 KB Output is correct
31 Correct 2 ms 8536 KB Output is correct
32 Correct 2 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 32 ms 16616 KB Output is correct
40 Correct 34 ms 16468 KB Output is correct
41 Correct 25 ms 15812 KB Output is correct
42 Correct 6 ms 9816 KB Output is correct
43 Correct 2 ms 8536 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 1 ms 8640 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 1 ms 8540 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 1 ms 8536 KB Output is correct
55 Correct 2 ms 8540 KB Output is correct
56 Correct 2 ms 8628 KB Output is correct
57 Correct 49 ms 13128 KB Output is correct
58 Correct 45 ms 13140 KB Output is correct
59 Correct 43 ms 13120 KB Output is correct
60 Correct 41 ms 13180 KB Output is correct
61 Correct 41 ms 13136 KB Output is correct
62 Correct 43 ms 13136 KB Output is correct
63 Correct 39 ms 12956 KB Output is correct
64 Correct 38 ms 12884 KB Output is correct
65 Correct 50 ms 13296 KB Output is correct
66 Correct 40 ms 13208 KB Output is correct
67 Correct 46 ms 13196 KB Output is correct
68 Correct 45 ms 12880 KB Output is correct
69 Correct 48 ms 13320 KB Output is correct
70 Correct 45 ms 13128 KB Output is correct
71 Correct 1 ms 6488 KB Output is correct
72 Correct 3 ms 8792 KB Output is correct
73 Correct 2 ms 8796 KB Output is correct
74 Correct 2 ms 8796 KB Output is correct
75 Correct 3 ms 8792 KB Output is correct
76 Correct 3 ms 8796 KB Output is correct
77 Correct 2 ms 8796 KB Output is correct
78 Correct 2 ms 8796 KB Output is correct
79 Correct 2 ms 8792 KB Output is correct
80 Correct 45 ms 13132 KB Output is correct
81 Correct 41 ms 13404 KB Output is correct
82 Correct 43 ms 12944 KB Output is correct
83 Correct 41 ms 12840 KB Output is correct
84 Correct 2 ms 8792 KB Output is correct
85 Correct 2 ms 8792 KB Output is correct
86 Correct 2 ms 9048 KB Output is correct
87 Correct 3 ms 8796 KB Output is correct
88 Correct 2 ms 8792 KB Output is correct
89 Correct 2 ms 8796 KB Output is correct
90 Correct 2 ms 8796 KB Output is correct
91 Correct 2 ms 8796 KB Output is correct
92 Correct 3 ms 8848 KB Output is correct
93 Correct 3 ms 9048 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 1 ms 8540 KB Output is correct
97 Correct 2 ms 8540 KB Output is correct
98 Correct 1 ms 8540 KB Output is correct
99 Correct 1 ms 8540 KB Output is correct
100 Correct 2 ms 8540 KB Output is correct
101 Correct 2 ms 8540 KB Output is correct
102 Correct 2 ms 8540 KB Output is correct
103 Correct 1 ms 8540 KB Output is correct
104 Correct 5 ms 9308 KB Output is correct
105 Correct 9 ms 10332 KB Output is correct
106 Correct 2 ms 8796 KB Output is correct
107 Correct 17 ms 11984 KB Output is correct
108 Correct 23 ms 14172 KB Output is correct
109 Correct 2 ms 8796 KB Output is correct
110 Correct 31 ms 14164 KB Output is correct
111 Correct 36 ms 15184 KB Output is correct
112 Correct 2 ms 8792 KB Output is correct
113 Correct 51 ms 21344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 10840 KB Output is correct
2 Incorrect 14 ms 10852 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8792 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8792 KB Output is correct
31 Correct 2 ms 8860 KB Output is correct
32 Incorrect 2 ms 8796 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 16776 KB Output is correct
2 Correct 33 ms 16468 KB Output is correct
3 Correct 27 ms 15700 KB Output is correct
4 Correct 6 ms 9816 KB Output is correct
5 Correct 5 ms 9308 KB Output is correct
6 Correct 9 ms 10332 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 18 ms 12024 KB Output is correct
9 Correct 23 ms 13956 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 30 ms 14172 KB Output is correct
12 Correct 42 ms 15264 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 1 ms 8536 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 1 ms 8536 KB Output is correct
31 Correct 2 ms 8536 KB Output is correct
32 Correct 2 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 32 ms 16616 KB Output is correct
40 Correct 34 ms 16468 KB Output is correct
41 Correct 25 ms 15812 KB Output is correct
42 Correct 6 ms 9816 KB Output is correct
43 Correct 2 ms 8536 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 1 ms 8640 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 1 ms 8540 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 1 ms 8536 KB Output is correct
55 Correct 2 ms 8540 KB Output is correct
56 Correct 2 ms 8628 KB Output is correct
57 Correct 49 ms 13128 KB Output is correct
58 Correct 45 ms 13140 KB Output is correct
59 Correct 43 ms 13120 KB Output is correct
60 Correct 41 ms 13180 KB Output is correct
61 Correct 41 ms 13136 KB Output is correct
62 Correct 43 ms 13136 KB Output is correct
63 Correct 39 ms 12956 KB Output is correct
64 Correct 38 ms 12884 KB Output is correct
65 Correct 50 ms 13296 KB Output is correct
66 Correct 40 ms 13208 KB Output is correct
67 Correct 46 ms 13196 KB Output is correct
68 Correct 45 ms 12880 KB Output is correct
69 Correct 48 ms 13320 KB Output is correct
70 Correct 45 ms 13128 KB Output is correct
71 Correct 1 ms 6488 KB Output is correct
72 Correct 3 ms 8792 KB Output is correct
73 Correct 2 ms 8796 KB Output is correct
74 Correct 2 ms 8796 KB Output is correct
75 Correct 3 ms 8792 KB Output is correct
76 Correct 3 ms 8796 KB Output is correct
77 Correct 2 ms 8796 KB Output is correct
78 Correct 2 ms 8796 KB Output is correct
79 Correct 2 ms 8792 KB Output is correct
80 Correct 45 ms 13132 KB Output is correct
81 Correct 41 ms 13404 KB Output is correct
82 Correct 43 ms 12944 KB Output is correct
83 Correct 41 ms 12840 KB Output is correct
84 Correct 2 ms 8792 KB Output is correct
85 Correct 2 ms 8792 KB Output is correct
86 Correct 2 ms 9048 KB Output is correct
87 Correct 3 ms 8796 KB Output is correct
88 Correct 2 ms 8792 KB Output is correct
89 Correct 2 ms 8796 KB Output is correct
90 Correct 2 ms 8796 KB Output is correct
91 Correct 2 ms 8796 KB Output is correct
92 Correct 3 ms 8848 KB Output is correct
93 Correct 3 ms 9048 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 1 ms 8540 KB Output is correct
97 Correct 2 ms 8540 KB Output is correct
98 Correct 1 ms 8540 KB Output is correct
99 Correct 1 ms 8540 KB Output is correct
100 Correct 2 ms 8540 KB Output is correct
101 Correct 2 ms 8540 KB Output is correct
102 Correct 2 ms 8540 KB Output is correct
103 Correct 1 ms 8540 KB Output is correct
104 Correct 5 ms 9308 KB Output is correct
105 Correct 9 ms 10332 KB Output is correct
106 Correct 2 ms 8796 KB Output is correct
107 Correct 17 ms 11984 KB Output is correct
108 Correct 23 ms 14172 KB Output is correct
109 Correct 2 ms 8796 KB Output is correct
110 Correct 31 ms 14164 KB Output is correct
111 Correct 36 ms 15184 KB Output is correct
112 Correct 2 ms 8792 KB Output is correct
113 Correct 51 ms 21344 KB Output is correct
114 Correct 14 ms 10840 KB Output is correct
115 Incorrect 14 ms 10852 KB Output isn't correct
116 Halted 0 ms 0 KB -