Submission #530908

# Submission time Handle Problem Language Result Execution time Memory
530908 2022-02-27T05:17:56 Z ToroTN Dreaming (IOI13_dreaming) C++14
47 / 100
60 ms 9108 KB
#include<bits/stdc++.h>
using namespace std;
#include "dreaming.h"
int mx1=-1e9,mx2=-1e9,mx3=-1e9,sum,val,n,m,l,u_i,v_i,w_i,d1[100005],d2[100005],u,y,ans=1e9,cost,mx,p[100005],lst,st,md,ed,sup,suck=-1e9,comp=0;
vector<pair<int,int> > v[100005];
vector<int> path,g;
queue<int> q;
void bfs(int x)
{
    q.push(x);
    d1[x]=0;
    mx=-1;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        if(d1[u]>mx)
        {
            mx=d1[u];
            x=u;
        }
        for(int i=0;i<v[u].size();i++)
        {
            y=v[u][i].first;
            cost=v[u][i].second;
            if(d1[y]==-1)
            {
                d1[y]=d1[u]+cost;
                q.push(y);
            }
        }
    }
    mx=-1;
    d2[x]=0;
    p[x]=0;
    q.push(x);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        if(d2[u]>mx)
        {
            mx=d2[u];
            lst=u;
        }
        for(int i=0;i<v[u].size();i++)
        {
            y=v[u][i].first;
            cost=v[u][i].second;
            if(d2[y]==-1)
            {
                p[y]=u;
                d2[y]=d2[u]+cost;
                q.push(y);
            }
        }
    }
    path.clear();
    g.clear();
    while(1)
    {
        if(lst==0)
        {
            break;
        }
        path.push_back(lst);
        if(p[lst]!=0)
        {
            g.push_back(d2[lst]-d2[p[lst]]);
        }
        lst=p[lst];
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    m=M;
    l=L;
    for(int i=0;i<m;i++)
    {
        u_i=A[i]+1;
        v_i=B[i]+1;
        w_i=T[i];
        v[u_i].push_back({v_i,w_i});
        v[v_i].push_back({u_i,w_i});
    }
    memset(d1,-1,sizeof d1);
    memset(d2,-1,sizeof d2);
    for(int i=1;i<=n;i++)
    {
        if(d1[i]==-1)
        {
            ++comp;
            bfs(i);
            /*for(int j=0;j<path.size();j++)
            {
                printf("%d ",path[j]);
            }
            printf("\n");
            for(int j=0;j<g.size();j++)
            {
                printf("%d ",g[j]);
            }
            printf("\n");*/
            val=1e9;
            for(int j=0;j<g.size();j++)
            {
                sum+=g[j];
            }
            suck=max(suck,sum);
            sup=0;
            val=min(val,max(sup,sum));
            for(int j=0;j<g.size();j++)
            {
                sup+=g[j];
                sum-=g[j];
                val=min(val,max(sup,sum));
            }
            if(val>=mx1)
            {
                mx3=mx2;
                mx2=mx1;
                mx1=val;
            }else if(val>=mx2)
            {
                mx3=mx2;
                mx2=val;
            }else if(val>=mx3)
            {
                mx=val;
            }
        }
    }
    //printf("%d %d\n",mx1,mx2);
    if(comp==1)
    {
        return suck;
    }else if(comp==2)
    {
        return max(suck,mx1+mx2+l);
    }else
    {
        return max(max(suck,mx1+mx2+l),2*l+mx2+mx3);
    }
}

Compilation message

dreaming.cpp: In function 'void bfs(int)':
dreaming.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int i=0;i<v[u].size();i++)
      |                     ~^~~~~~~~~~~~
dreaming.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int i=0;i<v[u].size();i++)
      |                     ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:105:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |             for(int j=0;j<g.size();j++)
      |                         ~^~~~~~~~~
dreaming.cpp:112:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |             for(int j=0;j<g.size();j++)
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 8644 KB Output is correct
2 Correct 39 ms 8700 KB Output is correct
3 Correct 25 ms 6824 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 5 ms 3916 KB Output is correct
6 Correct 10 ms 4556 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 20 ms 5528 KB Output is correct
9 Correct 24 ms 6224 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 35 ms 7296 KB Output is correct
12 Correct 38 ms 8068 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 8644 KB Output is correct
2 Correct 39 ms 8700 KB Output is correct
3 Correct 25 ms 6824 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 5 ms 3916 KB Output is correct
6 Correct 10 ms 4556 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 20 ms 5528 KB Output is correct
9 Correct 24 ms 6224 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 35 ms 7296 KB Output is correct
12 Correct 38 ms 8068 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 2 ms 3404 KB Output is correct
38 Correct 2 ms 3404 KB Output is correct
39 Correct 36 ms 8672 KB Output is correct
40 Correct 40 ms 8624 KB Output is correct
41 Correct 24 ms 6860 KB Output is correct
42 Correct 6 ms 4204 KB Output is correct
43 Correct 2 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 2 ms 3404 KB Output is correct
51 Correct 2 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3328 KB Output is correct
57 Correct 58 ms 9076 KB Output is correct
58 Correct 60 ms 8968 KB Output is correct
59 Correct 52 ms 8804 KB Output is correct
60 Correct 49 ms 8808 KB Output is correct
61 Correct 49 ms 8772 KB Output is correct
62 Correct 50 ms 8792 KB Output is correct
63 Correct 46 ms 8644 KB Output is correct
64 Correct 47 ms 8704 KB Output is correct
65 Correct 53 ms 8820 KB Output is correct
66 Correct 48 ms 8672 KB Output is correct
67 Correct 50 ms 8772 KB Output is correct
68 Correct 50 ms 8712 KB Output is correct
69 Correct 53 ms 8772 KB Output is correct
70 Correct 51 ms 8720 KB Output is correct
71 Correct 2 ms 3404 KB Output is correct
72 Correct 3 ms 3532 KB Output is correct
73 Correct 3 ms 3532 KB Output is correct
74 Correct 3 ms 3532 KB Output is correct
75 Correct 3 ms 3532 KB Output is correct
76 Correct 3 ms 3532 KB Output is correct
77 Correct 3 ms 3532 KB Output is correct
78 Correct 3 ms 3532 KB Output is correct
79 Correct 3 ms 3532 KB Output is correct
80 Correct 50 ms 8812 KB Output is correct
81 Correct 49 ms 8740 KB Output is correct
82 Correct 49 ms 8740 KB Output is correct
83 Correct 49 ms 8716 KB Output is correct
84 Correct 2 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 3 ms 3532 KB Output is correct
87 Correct 2 ms 3532 KB Output is correct
88 Correct 2 ms 3532 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 3 ms 3532 KB Output is correct
91 Correct 3 ms 3532 KB Output is correct
92 Correct 3 ms 3532 KB Output is correct
93 Correct 3 ms 3532 KB Output is correct
94 Correct 2 ms 3404 KB Output is correct
95 Correct 2 ms 3404 KB Output is correct
96 Correct 2 ms 3404 KB Output is correct
97 Correct 2 ms 3404 KB Output is correct
98 Correct 2 ms 3404 KB Output is correct
99 Correct 2 ms 3404 KB Output is correct
100 Correct 2 ms 3404 KB Output is correct
101 Correct 2 ms 3404 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 4 ms 3404 KB Output is correct
104 Correct 6 ms 3988 KB Output is correct
105 Correct 10 ms 4560 KB Output is correct
106 Correct 2 ms 3404 KB Output is correct
107 Correct 21 ms 5548 KB Output is correct
108 Correct 24 ms 6344 KB Output is correct
109 Correct 2 ms 3404 KB Output is correct
110 Correct 34 ms 7228 KB Output is correct
111 Correct 43 ms 8256 KB Output is correct
112 Correct 2 ms 3404 KB Output is correct
113 Correct 52 ms 9108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6088 KB Output is correct
2 Correct 19 ms 6060 KB Output is correct
3 Correct 17 ms 6424 KB Output is correct
4 Incorrect 20 ms 6464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3532 KB Output is correct
28 Correct 3 ms 3532 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 2 ms 3532 KB Output is correct
31 Correct 3 ms 3532 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 3 ms 3464 KB Output is correct
34 Correct 3 ms 3532 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 2 ms 3404 KB Output is correct
38 Correct 2 ms 3428 KB Output is correct
39 Correct 2 ms 3404 KB Output is correct
40 Correct 2 ms 3404 KB Output is correct
41 Correct 2 ms 3404 KB Output is correct
42 Correct 2 ms 3404 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 3 ms 3404 KB Output is correct
51 Correct 2 ms 3532 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 3 ms 3564 KB Output is correct
55 Correct 3 ms 3660 KB Output is correct
56 Correct 3 ms 3564 KB Output is correct
57 Correct 2 ms 3404 KB Output is correct
58 Correct 3 ms 3564 KB Output is correct
59 Correct 3 ms 3532 KB Output is correct
60 Correct 2 ms 3532 KB Output is correct
61 Incorrect 2 ms 3404 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 8644 KB Output is correct
2 Correct 39 ms 8700 KB Output is correct
3 Correct 25 ms 6824 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 5 ms 3916 KB Output is correct
6 Correct 10 ms 4556 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 20 ms 5528 KB Output is correct
9 Correct 24 ms 6224 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 35 ms 7296 KB Output is correct
12 Correct 38 ms 8068 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 2 ms 3404 KB Output is correct
38 Correct 2 ms 3404 KB Output is correct
39 Correct 36 ms 8672 KB Output is correct
40 Correct 40 ms 8624 KB Output is correct
41 Correct 24 ms 6860 KB Output is correct
42 Correct 6 ms 4204 KB Output is correct
43 Correct 2 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 2 ms 3404 KB Output is correct
51 Correct 2 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3328 KB Output is correct
57 Correct 58 ms 9076 KB Output is correct
58 Correct 60 ms 8968 KB Output is correct
59 Correct 52 ms 8804 KB Output is correct
60 Correct 49 ms 8808 KB Output is correct
61 Correct 49 ms 8772 KB Output is correct
62 Correct 50 ms 8792 KB Output is correct
63 Correct 46 ms 8644 KB Output is correct
64 Correct 47 ms 8704 KB Output is correct
65 Correct 53 ms 8820 KB Output is correct
66 Correct 48 ms 8672 KB Output is correct
67 Correct 50 ms 8772 KB Output is correct
68 Correct 50 ms 8712 KB Output is correct
69 Correct 53 ms 8772 KB Output is correct
70 Correct 51 ms 8720 KB Output is correct
71 Correct 2 ms 3404 KB Output is correct
72 Correct 3 ms 3532 KB Output is correct
73 Correct 3 ms 3532 KB Output is correct
74 Correct 3 ms 3532 KB Output is correct
75 Correct 3 ms 3532 KB Output is correct
76 Correct 3 ms 3532 KB Output is correct
77 Correct 3 ms 3532 KB Output is correct
78 Correct 3 ms 3532 KB Output is correct
79 Correct 3 ms 3532 KB Output is correct
80 Correct 50 ms 8812 KB Output is correct
81 Correct 49 ms 8740 KB Output is correct
82 Correct 49 ms 8740 KB Output is correct
83 Correct 49 ms 8716 KB Output is correct
84 Correct 2 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 3 ms 3532 KB Output is correct
87 Correct 2 ms 3532 KB Output is correct
88 Correct 2 ms 3532 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 3 ms 3532 KB Output is correct
91 Correct 3 ms 3532 KB Output is correct
92 Correct 3 ms 3532 KB Output is correct
93 Correct 3 ms 3532 KB Output is correct
94 Correct 2 ms 3404 KB Output is correct
95 Correct 2 ms 3404 KB Output is correct
96 Correct 2 ms 3404 KB Output is correct
97 Correct 2 ms 3404 KB Output is correct
98 Correct 2 ms 3404 KB Output is correct
99 Correct 2 ms 3404 KB Output is correct
100 Correct 2 ms 3404 KB Output is correct
101 Correct 2 ms 3404 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 4 ms 3404 KB Output is correct
104 Correct 6 ms 3988 KB Output is correct
105 Correct 10 ms 4560 KB Output is correct
106 Correct 2 ms 3404 KB Output is correct
107 Correct 21 ms 5548 KB Output is correct
108 Correct 24 ms 6344 KB Output is correct
109 Correct 2 ms 3404 KB Output is correct
110 Correct 34 ms 7228 KB Output is correct
111 Correct 43 ms 8256 KB Output is correct
112 Correct 2 ms 3404 KB Output is correct
113 Correct 52 ms 9108 KB Output is correct
114 Correct 16 ms 6088 KB Output is correct
115 Correct 19 ms 6060 KB Output is correct
116 Correct 17 ms 6424 KB Output is correct
117 Incorrect 20 ms 6464 KB Output isn't correct
118 Halted 0 ms 0 KB -