Submission #964565

# Submission time Handle Problem Language Result Execution time Memory
964565 2024-04-17T06:12:53 Z ReLice Dreaming (IOI13_dreaming) C++17
47 / 100
229 ms 22208 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define ll int
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
const ll mod=1e9+7;
const ld eps=1e-9;
const ll N=1e5+7;
ll d[N];
vector<set<pair<ll,ll>>> g(N);
ll mx,x;
void dfs(ll v,ll p){
    if(chmax(mx,d[v]))x=v;
    for(auto i : g[v]){
        if(i.fr==p) continue;
        d[i.fr]=d[v]+i.sc;
        dfs(i.fr,v);
    }
}
int travelTime(ll n, ll m, ll l, ll a[], ll b[], ll t[]) {
    ll i,j;
    set<pair<ll,ll>> st;
    for(i=0;i<m;i++){
        a[i]++;
        b[i]++;
        g[a[i]].ins({b[i],t[i]});
        g[b[i]].ins({a[i],t[i]});
    }
    ll ans=0;
    for(i=1;i<=n;i++){
        if(!d[i]){
            mx=0;
            dfs(i,0);
            mx=0;
            d[x]=0;
            dfs(x,0);
            chmax(ans,mx);
        }
    }
    vll v;
    for(i=1;i<=n;i++){
        d[i]=0;
        if(g[i].sz==0){
            v.pb(i);
        }else if(g[i].sz==1){
            st.ins({g[i].begin()->sc,i});
        }
    }
    while(st.sz){
        ll x=st.begin()->sc;
        st.erase(st.begin());
        for(auto i : g[x]){
            g[i.fr].erase(g[i.fr].find({x,i.sc}));
            chmax(d[i.fr],d[x]+i.sc);
            if(g[i.fr].sz==0)v.pb(i.fr);
            else if(g[i.fr].sz==1)st.ins({d[i.fr]+g[i.fr].begin()->sc,i.fr});
        }
        g[x].clear();
    }
    for(i=0;i<v.sz;i++) v[i]=d[v[i]];
    sort(all(v));
    if(v.sz>1)chmax(ans,v.bc+v[v.sz-2]+l);
    return ans;
}/*
signed main(){
    ll n,m,l;
    cin>>n>>m>>l;
    ll a[m],b[m],t[m];
    for(ll i=0;i<m;i++) cin>>a[i];
    for(ll i=0;i<m;i++) cin>>b[i];
    for(ll i=0;i<m;i++) cin>>t[i];
    cout<<travelTime(n,m,l,a,b,t)<<endl;
}*/
/*
12 8 2
0 8 2 5 5 1 1 10
8 2 7 11 1 3 9 6
4 2 4 3 7 1 5 3
*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(i=0;i<v.sz;i++) v[i]=d[v[i]];
      |              ^
dreaming.cpp:47:10: warning: unused variable 'j' [-Wunused-variable]
   47 |     ll i,j;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 100 ms 20936 KB Output is correct
2 Correct 71 ms 21040 KB Output is correct
3 Correct 48 ms 15392 KB Output is correct
4 Correct 9 ms 7264 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 21 ms 8540 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 35 ms 11112 KB Output is correct
9 Correct 57 ms 13136 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 113 ms 15728 KB Output is correct
12 Correct 146 ms 18108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4968 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 20936 KB Output is correct
2 Correct 71 ms 21040 KB Output is correct
3 Correct 48 ms 15392 KB Output is correct
4 Correct 9 ms 7264 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 21 ms 8540 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 35 ms 11112 KB Output is correct
9 Correct 57 ms 13136 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 113 ms 15728 KB Output is correct
12 Correct 146 ms 18108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4968 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 77 ms 20820 KB Output is correct
40 Correct 77 ms 21032 KB Output is correct
41 Correct 45 ms 15696 KB Output is correct
42 Correct 8 ms 7328 KB Output is correct
43 Correct 2 ms 4952 KB Output is correct
44 Correct 2 ms 4952 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 2 ms 4952 KB Output is correct
48 Correct 2 ms 4952 KB Output is correct
49 Correct 2 ms 5156 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4952 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Correct 2 ms 4960 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 1 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 146 ms 17800 KB Output is correct
58 Correct 137 ms 17672 KB Output is correct
59 Correct 225 ms 18032 KB Output is correct
60 Correct 207 ms 18060 KB Output is correct
61 Correct 209 ms 18528 KB Output is correct
62 Correct 199 ms 18364 KB Output is correct
63 Correct 159 ms 18260 KB Output is correct
64 Correct 229 ms 18456 KB Output is correct
65 Correct 145 ms 18480 KB Output is correct
66 Correct 205 ms 18772 KB Output is correct
67 Correct 162 ms 17968 KB Output is correct
68 Correct 147 ms 17748 KB Output is correct
69 Correct 179 ms 18052 KB Output is correct
70 Correct 154 ms 17932 KB Output is correct
71 Correct 1 ms 4952 KB Output is correct
72 Correct 3 ms 5432 KB Output is correct
73 Correct 4 ms 5464 KB Output is correct
74 Correct 5 ms 5724 KB Output is correct
75 Correct 4 ms 5468 KB Output is correct
76 Correct 4 ms 5468 KB Output is correct
77 Correct 4 ms 5468 KB Output is correct
78 Correct 4 ms 5468 KB Output is correct
79 Correct 4 ms 5468 KB Output is correct
80 Correct 124 ms 18244 KB Output is correct
81 Correct 116 ms 18108 KB Output is correct
82 Correct 158 ms 18260 KB Output is correct
83 Correct 172 ms 18264 KB Output is correct
84 Correct 3 ms 5468 KB Output is correct
85 Correct 3 ms 5212 KB Output is correct
86 Correct 4 ms 5468 KB Output is correct
87 Correct 3 ms 5468 KB Output is correct
88 Correct 3 ms 5288 KB Output is correct
89 Correct 3 ms 5464 KB Output is correct
90 Correct 3 ms 5428 KB Output is correct
91 Correct 4 ms 5536 KB Output is correct
92 Correct 4 ms 5468 KB Output is correct
93 Correct 3 ms 5468 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 1 ms 4956 KB Output is correct
96 Correct 2 ms 4956 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 2 ms 4956 KB Output is correct
99 Correct 1 ms 4956 KB Output is correct
100 Correct 2 ms 4956 KB Output is correct
101 Correct 2 ms 4956 KB Output is correct
102 Correct 2 ms 4956 KB Output is correct
103 Correct 2 ms 4952 KB Output is correct
104 Correct 11 ms 6488 KB Output is correct
105 Correct 24 ms 8604 KB Output is correct
106 Correct 1 ms 4956 KB Output is correct
107 Correct 31 ms 10968 KB Output is correct
108 Correct 65 ms 13084 KB Output is correct
109 Correct 2 ms 5212 KB Output is correct
110 Correct 78 ms 15812 KB Output is correct
111 Correct 142 ms 18116 KB Output is correct
112 Correct 2 ms 5212 KB Output is correct
113 Correct 140 ms 22208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 11976 KB Output is correct
2 Incorrect 31 ms 12124 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4968 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 5 ms 5468 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 3 ms 5468 KB Output is correct
32 Incorrect 2 ms 5212 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 20936 KB Output is correct
2 Correct 71 ms 21040 KB Output is correct
3 Correct 48 ms 15392 KB Output is correct
4 Correct 9 ms 7264 KB Output is correct
5 Correct 10 ms 6492 KB Output is correct
6 Correct 21 ms 8540 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 35 ms 11112 KB Output is correct
9 Correct 57 ms 13136 KB Output is correct
10 Correct 2 ms 5464 KB Output is correct
11 Correct 113 ms 15728 KB Output is correct
12 Correct 146 ms 18108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4968 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 77 ms 20820 KB Output is correct
40 Correct 77 ms 21032 KB Output is correct
41 Correct 45 ms 15696 KB Output is correct
42 Correct 8 ms 7328 KB Output is correct
43 Correct 2 ms 4952 KB Output is correct
44 Correct 2 ms 4952 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 2 ms 4952 KB Output is correct
48 Correct 2 ms 4952 KB Output is correct
49 Correct 2 ms 5156 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4952 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Correct 2 ms 4960 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 1 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 146 ms 17800 KB Output is correct
58 Correct 137 ms 17672 KB Output is correct
59 Correct 225 ms 18032 KB Output is correct
60 Correct 207 ms 18060 KB Output is correct
61 Correct 209 ms 18528 KB Output is correct
62 Correct 199 ms 18364 KB Output is correct
63 Correct 159 ms 18260 KB Output is correct
64 Correct 229 ms 18456 KB Output is correct
65 Correct 145 ms 18480 KB Output is correct
66 Correct 205 ms 18772 KB Output is correct
67 Correct 162 ms 17968 KB Output is correct
68 Correct 147 ms 17748 KB Output is correct
69 Correct 179 ms 18052 KB Output is correct
70 Correct 154 ms 17932 KB Output is correct
71 Correct 1 ms 4952 KB Output is correct
72 Correct 3 ms 5432 KB Output is correct
73 Correct 4 ms 5464 KB Output is correct
74 Correct 5 ms 5724 KB Output is correct
75 Correct 4 ms 5468 KB Output is correct
76 Correct 4 ms 5468 KB Output is correct
77 Correct 4 ms 5468 KB Output is correct
78 Correct 4 ms 5468 KB Output is correct
79 Correct 4 ms 5468 KB Output is correct
80 Correct 124 ms 18244 KB Output is correct
81 Correct 116 ms 18108 KB Output is correct
82 Correct 158 ms 18260 KB Output is correct
83 Correct 172 ms 18264 KB Output is correct
84 Correct 3 ms 5468 KB Output is correct
85 Correct 3 ms 5212 KB Output is correct
86 Correct 4 ms 5468 KB Output is correct
87 Correct 3 ms 5468 KB Output is correct
88 Correct 3 ms 5288 KB Output is correct
89 Correct 3 ms 5464 KB Output is correct
90 Correct 3 ms 5428 KB Output is correct
91 Correct 4 ms 5536 KB Output is correct
92 Correct 4 ms 5468 KB Output is correct
93 Correct 3 ms 5468 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 1 ms 4956 KB Output is correct
96 Correct 2 ms 4956 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 2 ms 4956 KB Output is correct
99 Correct 1 ms 4956 KB Output is correct
100 Correct 2 ms 4956 KB Output is correct
101 Correct 2 ms 4956 KB Output is correct
102 Correct 2 ms 4956 KB Output is correct
103 Correct 2 ms 4952 KB Output is correct
104 Correct 11 ms 6488 KB Output is correct
105 Correct 24 ms 8604 KB Output is correct
106 Correct 1 ms 4956 KB Output is correct
107 Correct 31 ms 10968 KB Output is correct
108 Correct 65 ms 13084 KB Output is correct
109 Correct 2 ms 5212 KB Output is correct
110 Correct 78 ms 15812 KB Output is correct
111 Correct 142 ms 18116 KB Output is correct
112 Correct 2 ms 5212 KB Output is correct
113 Correct 140 ms 22208 KB Output is correct
114 Correct 56 ms 11976 KB Output is correct
115 Incorrect 31 ms 12124 KB Output isn't correct
116 Halted 0 ms 0 KB -