Submission #541789

# Submission time Handle Problem Language Result Execution time Memory
541789 2022-03-24T11:48:05 Z Sho10 Dreaming (IOI13_dreaming) C++17
14 / 100
983 ms 22212 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#include "dreaming.h"
using ll=int;
using ld=long double;
int const INF=1000000005;
//ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<pair<ll,ll>>g[100005];
vector<ll>comp;
map<ll,ll>viz;
ll bg;
map<ll,ll> bfs(ll node){
map<ll,ll>dist;
dist[node]=0;
queue<ll>q;
q.push(node);
ll mx=0;
viz[node]=1;
while(!q.empty()){
    ll x=q.front();
    q.pop();
    comp.pb(x);
    viz[x]=1;
    for(auto it : g[x]){
        if(dist[it.f]==0&&it.f!=node){
            dist[it.f]=dist[x]+it.s;
            q.push(it.f);
            if(dist[it.f]>mx){
                mx=dist[it.f];
                bg=it.f;
            }
        }
    }
}
return dist;
}
int travelTime(int n,int m,int l,int a[], int b[], int t[]){
cin>>n>>m;
for(ll i=1;i<=m;i++)
{
    g[a[i-1]].pb(mp(b[i-1],t[i-1]));
    g[b[i-1]].pb(mp(a[i-1],t[i-1]));
}
vector<pair<ll,ll>>v;
for(ll i=0;i<n;i++)
{
    if(viz[i]){
        continue;
    }
    bg=i;
    bfs(i);
    map<ll,ll>x=bfs(bg);
    comp.clear();
    map<ll,ll>y=bfs(bg);
    ll ans=bg;
    ll mx=max(x[ans],y[ans]);
    for(auto it : comp){
        if(max(x[it],y[it])<mx){
            mx=max(x[it],y[it]);
            ans=it;
        }
    }
    v.pb(mp(mx,ans));
}
sort(v.begin(),v.end());
for(ll i=1;i<v.size();i++)
{
    g[v[i].s].pb(mp(v[0].s,l));
    g[v[0].s].pb(mp(v[i].s,l));
}
bg=0;
bfs(0);
map<ll,ll>x=bfs(bg);
map<ll,ll>y=bfs(bg);
int ans=0;
for(ll i=0;i<n;i++)
{
    ans=max(ans,max(x[i],b[i]));
}
return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:76:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 | for(ll i=1;i<v.size();i++)
      |            ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 930 ms 21476 KB Output is correct
2 Correct 983 ms 21368 KB Output is correct
3 Correct 519 ms 14620 KB Output is correct
4 Correct 80 ms 5368 KB Output is correct
5 Correct 55 ms 4612 KB Output is correct
6 Correct 128 ms 6524 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 291 ms 10640 KB Output is correct
9 Correct 403 ms 12440 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 639 ms 16424 KB Output is correct
12 Correct 809 ms 18320 KB Output is correct
13 Correct 5 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Incorrect 2 ms 2644 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 930 ms 21476 KB Output is correct
2 Correct 983 ms 21368 KB Output is correct
3 Correct 519 ms 14620 KB Output is correct
4 Correct 80 ms 5368 KB Output is correct
5 Correct 55 ms 4612 KB Output is correct
6 Correct 128 ms 6524 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 291 ms 10640 KB Output is correct
9 Correct 403 ms 12440 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 639 ms 16424 KB Output is correct
12 Correct 809 ms 18320 KB Output is correct
13 Correct 5 ms 2772 KB Output is correct
14 Correct 2 ms 2644 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 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 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 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Incorrect 2 ms 2644 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 356 ms 22212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Incorrect 2 ms 2644 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 930 ms 21476 KB Output is correct
2 Correct 983 ms 21368 KB Output is correct
3 Correct 519 ms 14620 KB Output is correct
4 Correct 80 ms 5368 KB Output is correct
5 Correct 55 ms 4612 KB Output is correct
6 Correct 128 ms 6524 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 291 ms 10640 KB Output is correct
9 Correct 403 ms 12440 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 639 ms 16424 KB Output is correct
12 Correct 809 ms 18320 KB Output is correct
13 Correct 5 ms 2772 KB Output is correct
14 Correct 2 ms 2644 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 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 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 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Incorrect 2 ms 2644 KB Output isn't correct
31 Halted 0 ms 0 KB -