Submission #805707

# Submission time Handle Problem Language Result Execution time Memory
805707 2023-08-03T21:03:55 Z Mouad_ouj Dreaming (IOI13_dreaming) C++17
59 / 100
1000 ms 17472 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int> >> adj;
vector<bool> vis;
vector<vector<int> > t;
vector<int> d,ty;
int n,m,l;
void dfs(int node,int f)
{
    vis[node]=true;
    int k=adj[node].size();
    for(int x=0;x<k;x++)
    {
        int to=adj[node][x].first;
        if(!vis[to])
        {
        t[f].push_back(to);    
        dfs(to,f);
        }
    }
}
void dfs3(int node,int dis[])
{
    vis[node]=true;
    int k=adj[node].size();
    for(int x=0;x<k;x++)
    {
        int to=adj[node][x].first;
        if(!vis[to])
        {
        dis[to]=dis[node]+adj[node][x].second;    
        dfs3(to,dis);
        }
    }
}
int get(int y)
{
    int cn=t[y].size();
    int dis[n+1]={0},disa[n+1]={0},disb[n+1]={0},a=0,b=0,cur=0;
    vis.assign(n+1,false);
    if(adj[y].size()!=0)
    dfs3(y,dis);
    else 
    return 0;
    for(int x=0;x<cn;x++)
    {
        if(cur<=dis[t[y][x]] && t[y][x]!=y)
        {
            a=t[y][x];
            cur=dis[t[y][x]];
        }
    }    
    vis.assign(n+1,false);
    dfs3(a,disa);
    cur=0;
    for(int x=0;x<cn;x++)
    {
        if(cur<disa[t[y][x]] && t[y][x]!=a)
        {
            b=t[y][x];
            cur=disa[t[y][x]];
        }
    }
    vis.assign(n+1,false);
    dfs3(b,disb);
    int ans=disb[a];
    for(int x=0;x<cn;x++)
        ans=min(ans,max(disa[t[y][x]],disb[t[y][x]]));
    d.push_back(disa[b]);
    return ans;
}
int travelTime(int ne,int me,int le,int u[],int v[],int te[])
{
    n=ne;m=me;l=le;
    adj.resize(n+1);
    t.resize(n+1);
    vis.assign(n+1,false);
    for(int x=0;x<m;x++)
    {
        adj[u[x]+1].push_back(make_pair(v[x]+1,te[x]));
        adj[v[x]+1].push_back(make_pair(u[x]+1,te[x]));
    }
    int c=0;
    for(int x=1;x<=n;x++)
    {
        if(!vis[x])
        {
        t[x].push_back(x);    
        dfs(x,x);
        ty.push_back(x);
        }
    }
    int z=ty.size();
    int dia[z]={0};
    for(int x=0;x<z;x++)
        dia[x]=get(ty[x]);
    int ans=0,ans1=0,mx=dia[0],mx2=0,mx3=0;
    /*for(int x=0;x<z;x++)
    cout<<t[x]<<" "<<dia[x]<<endl;*/
    for(int x=0;x<d.size();x++)
    ans=max(ans,d[x]);
    for(int x=1;x<z;x++)
    {
        if(dia[x]>=mx)
        {
            mx3=mx2;
            mx2=mx;
            mx=dia[x];
        }
        else if(dia[x]>=mx2)
        {
            mx3=mx2;
            mx2=dia[x];
        }
        else if(dia[x]>mx3)
        mx3=dia[x];
    }
    if(z-2>=0)
    ans1=mx+mx2+l;
    if(z-3>=0)
    ans1=max(ans1,mx3+mx2+2*l);
    return max(ans1,ans);
}    
/*int main()
{
    int ne,me,le;
    cin>>ne>>me>>le;
    int te[me],ae[me],be[me];
    for(int x=0;x<me;x++)
    cin>>ae[x]>>be[x]>>te[x];
    //for(int x=0;x<me;x++)
    //ae[x]++,be[x]++;
    cout<<travelTime(ne, me, le, ae , be , te );
}*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int x=0;x<d.size();x++)
      |                 ~^~~~~~~~~
dreaming.cpp:84:9: warning: unused variable 'c' [-Wunused-variable]
   84 |     int c=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15680 KB Output is correct
2 Correct 40 ms 15692 KB Output is correct
3 Correct 27 ms 10464 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 5 ms 1620 KB Output is correct
6 Correct 10 ms 3696 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 19 ms 6160 KB Output is correct
9 Correct 24 ms 8172 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 35 ms 10752 KB Output is correct
12 Correct 41 ms 13088 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 224 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15680 KB Output is correct
2 Correct 40 ms 15692 KB Output is correct
3 Correct 27 ms 10464 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 5 ms 1620 KB Output is correct
6 Correct 10 ms 3696 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 19 ms 6160 KB Output is correct
9 Correct 24 ms 8172 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 35 ms 10752 KB Output is correct
12 Correct 41 ms 13088 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 224 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 42 ms 15692 KB Output is correct
40 Correct 37 ms 15684 KB Output is correct
41 Correct 24 ms 10452 KB Output is correct
42 Correct 5 ms 2516 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 47 ms 11824 KB Output is correct
58 Correct 47 ms 11796 KB Output is correct
59 Correct 47 ms 11700 KB Output is correct
60 Correct 48 ms 11712 KB Output is correct
61 Correct 47 ms 11620 KB Output is correct
62 Correct 47 ms 11592 KB Output is correct
63 Correct 43 ms 11476 KB Output is correct
64 Correct 45 ms 11448 KB Output is correct
65 Correct 45 ms 11460 KB Output is correct
66 Correct 46 ms 11424 KB Output is correct
67 Correct 48 ms 11704 KB Output is correct
68 Correct 55 ms 11640 KB Output is correct
69 Correct 55 ms 11740 KB Output is correct
70 Correct 66 ms 11752 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 3 ms 596 KB Output is correct
75 Correct 2 ms 596 KB Output is correct
76 Correct 3 ms 668 KB Output is correct
77 Correct 3 ms 596 KB Output is correct
78 Correct 3 ms 596 KB Output is correct
79 Correct 2 ms 596 KB Output is correct
80 Correct 50 ms 11716 KB Output is correct
81 Correct 50 ms 11776 KB Output is correct
82 Correct 60 ms 11588 KB Output is correct
83 Correct 50 ms 11620 KB Output is correct
84 Correct 1 ms 596 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 596 KB Output is correct
87 Correct 1 ms 596 KB Output is correct
88 Correct 1 ms 596 KB Output is correct
89 Correct 1 ms 596 KB Output is correct
90 Correct 2 ms 596 KB Output is correct
91 Correct 1 ms 596 KB Output is correct
92 Correct 2 ms 596 KB Output is correct
93 Correct 1 ms 596 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 1 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 1 ms 212 KB Output is correct
101 Correct 0 ms 212 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 1 ms 212 KB Output is correct
104 Correct 5 ms 1620 KB Output is correct
105 Correct 10 ms 3700 KB Output is correct
106 Correct 0 ms 340 KB Output is correct
107 Correct 20 ms 6220 KB Output is correct
108 Correct 25 ms 8152 KB Output is correct
109 Correct 1 ms 340 KB Output is correct
110 Correct 38 ms 10740 KB Output is correct
111 Correct 46 ms 13124 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 68 ms 17472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 10696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 224 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 488 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 616 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 1 ms 596 KB Output is correct
60 Correct 2 ms 596 KB Output is correct
61 Correct 2 ms 596 KB Output is correct
62 Correct 1 ms 596 KB Output is correct
63 Correct 2 ms 596 KB Output is correct
64 Correct 2 ms 596 KB Output is correct
65 Correct 2 ms 596 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 2 ms 596 KB Output is correct
69 Correct 2 ms 596 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 596 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 1 ms 596 KB Output is correct
75 Correct 2 ms 648 KB Output is correct
76 Correct 2 ms 596 KB Output is correct
77 Correct 1 ms 596 KB Output is correct
78 Correct 2 ms 596 KB Output is correct
79 Correct 2 ms 560 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 2 ms 596 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 2 ms 596 KB Output is correct
84 Correct 2 ms 596 KB Output is correct
85 Correct 2 ms 596 KB Output is correct
86 Correct 2 ms 596 KB Output is correct
87 Correct 1 ms 596 KB Output is correct
88 Correct 3 ms 596 KB Output is correct
89 Correct 2 ms 596 KB Output is correct
90 Correct 2 ms 596 KB Output is correct
91 Correct 2 ms 596 KB Output is correct
92 Correct 1 ms 596 KB Output is correct
93 Correct 1 ms 468 KB Output is correct
94 Correct 1 ms 596 KB Output is correct
95 Correct 1 ms 596 KB Output is correct
96 Correct 1 ms 596 KB Output is correct
97 Correct 2 ms 596 KB Output is correct
98 Correct 1 ms 596 KB Output is correct
99 Correct 1 ms 596 KB Output is correct
100 Correct 1 ms 596 KB Output is correct
101 Correct 1 ms 596 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 0 ms 212 KB Output is correct
104 Correct 0 ms 212 KB Output is correct
105 Correct 0 ms 212 KB Output is correct
106 Correct 0 ms 212 KB Output is correct
107 Correct 0 ms 212 KB Output is correct
108 Correct 0 ms 212 KB Output is correct
109 Correct 0 ms 212 KB Output is correct
110 Correct 0 ms 212 KB Output is correct
111 Correct 0 ms 212 KB Output is correct
112 Correct 0 ms 340 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15680 KB Output is correct
2 Correct 40 ms 15692 KB Output is correct
3 Correct 27 ms 10464 KB Output is correct
4 Correct 5 ms 2644 KB Output is correct
5 Correct 5 ms 1620 KB Output is correct
6 Correct 10 ms 3696 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 19 ms 6160 KB Output is correct
9 Correct 24 ms 8172 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 35 ms 10752 KB Output is correct
12 Correct 41 ms 13088 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 224 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 42 ms 15692 KB Output is correct
40 Correct 37 ms 15684 KB Output is correct
41 Correct 24 ms 10452 KB Output is correct
42 Correct 5 ms 2516 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 47 ms 11824 KB Output is correct
58 Correct 47 ms 11796 KB Output is correct
59 Correct 47 ms 11700 KB Output is correct
60 Correct 48 ms 11712 KB Output is correct
61 Correct 47 ms 11620 KB Output is correct
62 Correct 47 ms 11592 KB Output is correct
63 Correct 43 ms 11476 KB Output is correct
64 Correct 45 ms 11448 KB Output is correct
65 Correct 45 ms 11460 KB Output is correct
66 Correct 46 ms 11424 KB Output is correct
67 Correct 48 ms 11704 KB Output is correct
68 Correct 55 ms 11640 KB Output is correct
69 Correct 55 ms 11740 KB Output is correct
70 Correct 66 ms 11752 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 3 ms 596 KB Output is correct
75 Correct 2 ms 596 KB Output is correct
76 Correct 3 ms 668 KB Output is correct
77 Correct 3 ms 596 KB Output is correct
78 Correct 3 ms 596 KB Output is correct
79 Correct 2 ms 596 KB Output is correct
80 Correct 50 ms 11716 KB Output is correct
81 Correct 50 ms 11776 KB Output is correct
82 Correct 60 ms 11588 KB Output is correct
83 Correct 50 ms 11620 KB Output is correct
84 Correct 1 ms 596 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 596 KB Output is correct
87 Correct 1 ms 596 KB Output is correct
88 Correct 1 ms 596 KB Output is correct
89 Correct 1 ms 596 KB Output is correct
90 Correct 2 ms 596 KB Output is correct
91 Correct 1 ms 596 KB Output is correct
92 Correct 2 ms 596 KB Output is correct
93 Correct 1 ms 596 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 1 ms 212 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 1 ms 212 KB Output is correct
101 Correct 0 ms 212 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 1 ms 212 KB Output is correct
104 Correct 5 ms 1620 KB Output is correct
105 Correct 10 ms 3700 KB Output is correct
106 Correct 0 ms 340 KB Output is correct
107 Correct 20 ms 6220 KB Output is correct
108 Correct 25 ms 8152 KB Output is correct
109 Correct 1 ms 340 KB Output is correct
110 Correct 38 ms 10740 KB Output is correct
111 Correct 46 ms 13124 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 68 ms 17472 KB Output is correct
114 Execution timed out 1086 ms 10696 KB Time limit exceeded
115 Halted 0 ms 0 KB -