답안 #154144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154144 2019-09-18T14:54:31 Z nicolaalexandra 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
#define DIM 100010
#define INF 2000000000
#include "dreaming.h"
using namespace std;
ifstream fin ("dreaming.in");
ofstream fout ("dreaming.out");
int nr,n,m,l,i;
int dp_down[DIM]; /// cel mai lung drum in subarborele lui i
int dp_up[DIM]; /// cel mai lung drum din i in afara subarborelui lui i
int s[DIM],viz[DIM],v[DIM],a[DIM],b[DIM],cost[DIM];
vector <pair<int,int> > L[DIM];
vector <int> comp[DIM];
void dfs (int nod, int tata){
    viz[nod] = 1;
    comp[nr].push_back(nod);
    for (int i=0;i<L[nod].size();i++){
        int vecin = L[nod][i].first;
        if (vecin != tata){
            dfs (vecin,nod);
            s[nod] = max (s[nod],s[vecin]+L[nod][i].second);
        }}
    int maxim = 0, maxim2 = 0;
    for (int i=0;i<L[nod].size();i++){
        int vecin = L[nod][i].first, cost = L[nod][i].second;
        if (vecin == tata)
            continue;
        if (s[vecin]+cost > maxim){
            maxim2 = maxim;
            maxim = s[vecin]+cost;
        } else {
            if (s[vecin]+cost > maxim2)
                maxim2 = s[vecin]+cost;
        }}
    dp_down[nod] = maxim+maxim2;
}
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<L[nod].size();i++){
        int fiu = L[nod][i].first, cst = L[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<L[nod].size();i++){
        int fiu = L[nod][i].first;
        if (fiu == tata)
            continue;
        if (fiu == p)
            dp_up[fiu] = max (dp_up[fiu],maxim2+L[nod][i].second);
        else dp_up[fiu] = max (dp_up[fiu],maxim+L[nod][i].second);
    }

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

int timeTravel (int n, int m, int l, int a[], int b[], int cost[]){
    for (int i=1;i<=n;i++)
        L[i].clear();
    for (int i=0;i<m;i++){
        int x = a[i], y = b[i], cst = cost[i];
        x++, y++;
        L[x].push_back(make_pair(y,cst));
        L[y].push_back(make_pair(x,cst));
    }
    memset (viz,0,sizeof viz);
    memset (dp_up,0,sizeof dp_up);
    memset (dp_down,0,sizeof dp_down);
    memset (s,0,sizeof s);
    nr = 0;
    for (int i=1;i<=n;i++){
        if (!viz[i]){
            nr++;
            dfs (i,0);
            dfs2 (i,0,0);
        }}
    int sol = 0;
    for (int i=1;i<=nr;i++){
        /// incerc sa aleg cel mai bun nod reprezentant pt componenta conexa i
        int mini = INF;
        for (auto nod:comp[i]){
            /// distanta maxima in componenta i
            int dist_max = max (dp_up[nod]+s[nod],dp_down[nod]);
            sol = max (sol,dist_max);
            /// incerc sa l aleg pe nod reprezentant
            int dist = max (s[nod],dp_up[nod]);
            mini = min (mini,dist);
        }
        v[i] = mini;
    }

    sort (v+1,v+nr+1);
    if (nr >= 2)
        sol = max (sol,v[nr-1]+v[nr]+l);
    if (nr >= 3)
        sol = max (sol,v[nr-1]+v[nr-2]+2*l);

    return sol;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
dreaming.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:44:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
dreaming.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
dreaming.cpp:64:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
/tmp/ccdE2Zgb.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status