Submission #300137

# Submission time Handle Problem Language Result Execution time Memory
300137 2020-09-16T19:40:29 Z Hehehe Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define DIM 100010
#define INF 2000000000
#include "dreaming.h"
#define pi pair<int, int>

const int N = 1e5 + 11;
const ll inf = 2e9;
int path[N], viz[N], s[N], dp_up[N], dp_down[N], nr;

vector<pi> v[N];
vector<int> c[N];

void dfs(int nod, int P){

    c[nr].pb(nod);
    viz[nod] = 1;

    for(auto it : v[nod]){
        if(it.ff == P)continue;
        s[nod] = max(s[nod], s[it.ff] + it.ss);
    }

    int mx1 = 0, mx2 = 0;
    for(auto it : v[nod]){
        if(it.ff == P)continue;

        if(s[it.ff] + it.ss > mx1){
            mx2 = mx1;
            mx1 = s[it.ff] + it.ss;
            continue;
        }
        if(s[it.ff] + it.ss > mx2){
            mx2 = s[it.ff] + it.ss;
            continue;
        }
    }

    dp_down[nod] = mx1 + mx2;
}

void dfs2 (int nod, int tata, int cost){

    dp_up[nod] = max (dp_up[nod],dp_up[tata]+cost);
    int maxim = 0, maxim2 = 0, p = 0;
    for (int i=0;i<v[nod].size();i++){
        int fiu = v[nod][i].first, cst = v[nod][i].second;
        if (fiu == tata)
            continue;
        if (s[fiu]+cst > maxim){
            maxim2 = maxim;
            maxim = s[fiu]+cst, p = fiu;
        } else
            if (s[fiu]+cst > maxim2)
                maxim2 = s[fiu]+cst;
    }
    for (int i=0;i<v[nod].size();i++){
        int fiu = v[nod][i].first;
        if (fiu == tata)
            continue;
        if (fiu == p)
            dp_up[fiu] = max (dp_up[fiu],maxim2+v[nod][i].second);
        else dp_up[fiu] = max (dp_up[fiu],maxim+v[nod][i].second);
    }

    for (int i=0;i<v[nod].size();i++){
        int vecin = v[nod][i].first;
        if (vecin != tata)
            dfs2 (vecin,nod,v[nod][i].second);
    }}

int travelTime (int n, int m, int l, int a[], int b[], int cost[]){

    for(int i = 0; i <= n; i++){
        v[i].clear();
    }

    for(int i = 0; i < m; i++){
        int x = a[i], y = b[i], z = cost[i];
        x++, y++;
        v[x].push_back({y, z});
        v[y].push_back({x, z});
    }

    memset(viz,0,sizeof(viz));
    memset(dp_up,0,sizeof(dp_up));
    memset(dp_down,0,sizeof(dp_down));
    memset(s,0,sizeof(s));

    for(int i = 1; i <= n; i++){
        if(viz[i])continue;

        nr++;
        dfs(i, 0);
        dfs2(i, 0, 0);
    }

    int ans = 0;
    for(int i = 1;i <= nr; i++){
        int mn = inf;
        for(auto nod : c[i]){
            int dist_max = max(dp_up[nod] + s[nod], dp_down[nod]);
            ans = max(ans, dist_max);
            int dist = max(s[nod], dp_up[nod]);
            mn = min(mn,dist);
        }
        path[i] = mn;
    }

    sort(path + 1, path + nr + 1);

    if(nr >= 2)ans = max(ans, path[nr] + path[nr - 1] + l);
    if(nr >= 3)ans = max(ans, path[nr - 1] + path[nr - 2] + 2*l);

    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:18:11: error: 'class std::vector<int>' has no member named 'pb'
   18 |     c[nr].pb(nod);
      |           ^~
dreaming.cpp:22:15: error: 'struct std::pair<int, int>' has no member named 'ff'
   22 |         if(it.ff == P)continue;
      |               ^~
dreaming.cpp:23:35: error: 'struct std::pair<int, int>' has no member named 'ff'
   23 |         s[nod] = max(s[nod], s[it.ff] + it.ss);
      |                                   ^~
dreaming.cpp:23:44: error: 'struct std::pair<int, int>' has no member named 'ss'
   23 |         s[nod] = max(s[nod], s[it.ff] + it.ss);
      |                                            ^~
dreaming.cpp:28:15: error: 'struct std::pair<int, int>' has no member named 'ff'
   28 |         if(it.ff == P)continue;
      |               ^~
dreaming.cpp:30:17: error: 'struct std::pair<int, int>' has no member named 'ff'
   30 |         if(s[it.ff] + it.ss > mx1){
      |                 ^~
dreaming.cpp:30:26: error: 'struct std::pair<int, int>' has no member named 'ss'
   30 |         if(s[it.ff] + it.ss > mx1){
      |                          ^~
dreaming.cpp:32:24: error: 'struct std::pair<int, int>' has no member named 'ff'
   32 |             mx1 = s[it.ff] + it.ss;
      |                        ^~
dreaming.cpp:32:33: error: 'struct std::pair<int, int>' has no member named 'ss'
   32 |             mx1 = s[it.ff] + it.ss;
      |                                 ^~
dreaming.cpp:35:17: error: 'struct std::pair<int, int>' has no member named 'ff'
   35 |         if(s[it.ff] + it.ss > mx2){
      |                 ^~
dreaming.cpp:35:26: error: 'struct std::pair<int, int>' has no member named 'ss'
   35 |         if(s[it.ff] + it.ss > mx2){
      |                          ^~
dreaming.cpp:36:24: error: 'struct std::pair<int, int>' has no member named 'ff'
   36 |             mx2 = s[it.ff] + it.ss;
      |                        ^~
dreaming.cpp:36:33: error: 'struct std::pair<int, int>' has no member named 'ss'
   36 |             mx2 = s[it.ff] + it.ss;
      |                                 ^~
dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i=0;i<v[nod].size();i++){
      |                  ~^~~~~~~~~~~~~~
dreaming.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i=0;i<v[nod].size();i++){
      |                  ~^~~~~~~~~~~~~~
dreaming.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i=0;i<v[nod].size();i++){
      |                  ~^~~~~~~~~~~~~~