답안 #412752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412752 2021-05-27T12:55:34 Z losmi247 꿈 (IOI13_dreaming) C++14
0 / 100
57 ms 13892 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
typedef long long ll;
const int N = 1e5+23;

int n,m,l;
int a[N],b[N],t[N];
vector <pair<int,int>> g[N];
int rut[N],parent[N],komp[N];
int dep[N],mxdepdole[N];
int maxd[N];


vector <int> sad;
void dfs(int x,int par){
    sad.push_back(x);
    parent[x] = par;
    mxdepdole[x] = dep[x];
    for(auto f : g[x]){
        int u = f.first;
        if(u == par) continue;
        komp[u] = komp[x];

        dep[u] = dep[x]+f.second;
        dfs(u,x);
        mxdepdole[x] = max(mxdepdole[x],mxdepdole[u]);
    }
}

void dfs1(int x,int par,int ostali){
    maxd[x] = max(dep[x]+ostali,mxdepdole[x]-dep[x]);
    for(auto f : g[x]){
        int u = f.first;
        if(u == par) continue;
        dfs1(u,x,ostali);
    }
}

int travelTime(int br1,int br2,int br3,int *jed,int *dva,int *tri){
    n = br1;
    m = br2;
    l = br3;
    for(int i = 0; i < m; i++){ a[i+1] = jed[i]+1; b[i+1] = dva[i]+1; t[i+1] = tri[i]; }



    if(m == n-1) return 0;

    for(int i = 1; i <= m; i++){
        g[a[i]].push_back({b[i],t[i]});
        g[b[i]].push_back({a[i],t[i]});
    }
    int cnt = 1;
    vector <int> minmaxds;
    for(int i = 1; i <= n; i++){
        if(komp[i]) continue;

        komp[i] = cnt;
        rut[cnt] = i;
        sad.clear();
        dfs(i,0);


        vector <int> pref(g[i].size(),0),suf(g[i].size(),0);
        for(int j = 0; j < g[i].size(); j++){
            pref[j] = g[i][j].second+mxdepdole[g[i][j].first];
            if(j > 0) pref[j] = max(pref[j],pref[j-1]);
        }
        for(int j = g[i].size()-1; j >= 0; j--){
            suf[j] = g[i][j].second+mxdepdole[g[i][j].first];
            if(j < g[i].size()-1) suf[j] = max(suf[j],suf[j+1]);
        }
        for(int j = 0; j < g[i].size(); j++){
            int u = g[i][j].first;

            int ost = 0;
            if(j > 0) ost = max(ost,pref[j-1]);
            if(j < g[i].size()-1) ost = max(ost,suf[j+1]);

            dfs1(u,i,ost);
        }
        maxd[i] = mxdepdole[i];

        int minmaxd = 2e9;
        for(auto f : sad) minmaxd = min(minmaxd,maxd[f]);
        minmaxds.push_back(minmaxd);

        cnt++;
    }
    cnt--;
    assert(cnt == n-m);

    sort(minmaxds.begin(),minmaxds.end());

    vector <int> v;
    int maxi = 0,koji = -1;
    for(int i = 0; i < minmaxds.size()-1; i++){
        v.push_back(l+minmaxds.back()+minmaxds[i]);
        if(minmaxds[i] > maxi){
            maxi = minmaxds[i];
            koji = i;
        }
    }
    for(int i = 0; i < minmaxds.size()-1; i++){
        if(i == koji) continue;
        v.push_back(2*l+maxi+minmaxds[i]);
    }
    sort(v.begin(),v.end());

    return v.back();
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int j = 0; j < g[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
dreaming.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             if(j < g[i].size()-1) suf[j] = max(suf[j],suf[j+1]);
      |                ~~^~~~~~~~~~~~~~~
dreaming.cpp:74:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int j = 0; j < g[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
dreaming.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             if(j < g[i].size()-1) ost = max(ost,suf[j+1]);
      |                ~~^~~~~~~~~~~~~~~
dreaming.cpp:98:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(int i = 0; i < minmaxds.size()-1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
dreaming.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for(int i = 0; i < minmaxds.size()-1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 8228 KB Output is correct
2 Correct 32 ms 8308 KB Output is correct
3 Correct 32 ms 8664 KB Output is correct
4 Correct 34 ms 8664 KB Output is correct
5 Correct 40 ms 8728 KB Output is correct
6 Correct 35 ms 9648 KB Output is correct
7 Correct 37 ms 8940 KB Output is correct
8 Correct 34 ms 8604 KB Output is correct
9 Correct 30 ms 8580 KB Output is correct
10 Correct 34 ms 8896 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 13 ms 6504 KB Output is correct
13 Correct 12 ms 6508 KB Output is correct
14 Correct 13 ms 6472 KB Output is correct
15 Correct 12 ms 6556 KB Output is correct
16 Correct 15 ms 6472 KB Output is correct
17 Correct 12 ms 6212 KB Output is correct
18 Correct 13 ms 6508 KB Output is correct
19 Correct 13 ms 6556 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Incorrect 2 ms 2636 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -