답안 #541786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541786 2022-03-24T11:44:21 Z Sho10 꿈 (IOI13_dreaming) C++17
0 / 100
694 ms 22276 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;
ll mxN=1e5+5;
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);
vector<bool>check(mxN,false);
check[node]=1;
ll mx=0;
while(!q.empty()){
    ll x=q.front();
    q.pop();
    comp.pb(x);
    viz[x]=1;
    for(auto it : g[x]){
        if(check[it.f]==0){
            dist[it.f]=dist[x]+it.s;
            q.push(it.f);
            check[it.f]=1;
            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[]){
    for(ll i=0;i<n;i++)
    {
        g[i].clear();
        viz[i]=0;
    }
for(ll i=0;i<m;i++)
{
    g[a[i]].pb(mp(b[i],t[i]));
    g[b[i]].pb(mp(a[i],t[i]));
}
vector<pair<ll,ll>>v;
for(ll i=0;i<n;i++)
{
    if(viz[i]){
        continue;
    }
    bg=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],Y[i]));
}
return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:82: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]
   82 | for(ll i=1;i<v.size();i++)
      |            ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 20960 KB Output is correct
2 Correct 694 ms 20924 KB Output is correct
3 Correct 341 ms 14732 KB Output is correct
4 Correct 58 ms 5268 KB Output is correct
5 Correct 43 ms 4656 KB Output is correct
6 Correct 93 ms 6592 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 20960 KB Output is correct
2 Correct 694 ms 20924 KB Output is correct
3 Correct 341 ms 14732 KB Output is correct
4 Correct 58 ms 5268 KB Output is correct
5 Correct 43 ms 4656 KB Output is correct
6 Correct 93 ms 6592 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 353 ms 22276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 20960 KB Output is correct
2 Correct 694 ms 20924 KB Output is correct
3 Correct 341 ms 14732 KB Output is correct
4 Correct 58 ms 5268 KB Output is correct
5 Correct 43 ms 4656 KB Output is correct
6 Correct 93 ms 6592 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -