답안 #262249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262249 2020-08-12T14:26:43 Z eohomegrownapps 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int>>> adjlist; //ind,val
int n;

vector<bool> visited;
vector<int> parent;
vector<int> depth;

int fdist = 0;
int f_ind = 0;
int INF = 1e9;

void getFurthest(int ind, int par){
	//cout<<ind<<' '<<par<<'\n';
	visited[ind]=true;
	parent[ind]=par;
	for (auto p : adjlist[ind]){
		//cout<<"proc "<<p.first<<' '<<p.second<<'\n';
		if (p.first==par){continue;}
		depth[p.first]=depth[ind]+p.second;
		if (depth[p.first]>fdist){
			fdist=depth[p.first];
			f_ind=p.first;
		}
		getFurthest(p.first,ind);
	}
}


pair<int,int> getDiamDepth(int ind){
	//cout<<"check "<<ind<<'\n';
	fdist=0;f_ind=ind;
	parent[ind]=-1;
	getFurthest(ind,-1);
	int ftmp = f_ind;
	fdist=0;f_ind=ftmp;
	parent[ftmp]=-1;depth[ftmp]=0;
	getFurthest(ftmp,-1);
	//find min depth
	int cur = f_ind;
	int md = INF;
	while (cur!=-1){
		md = min(md, max(depth[cur],fdist-depth[cur]));
		cur=parent[cur];
	}
	//cout<<ind<<": "<<fdist<<' '<<md<<'\n';
	return {fdist,md};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    adjlist.resize(n);
    for (int i = 0; i<M; i++){
    	adjlist[A[i]].push_back({B[i],T[i]});
    	adjlist[B[i]].push_back({A[i],T[i]});
    }
    visited.resize(n);
    parent.resize(n,-1);
    depth.resize(n);
    int mindist = -1;
    int maxd = -1;
    int smaxd = -1;
    int tmaxd = -1;
    for (int i = 0; i<n; i++){
    	if (visited[i]){continue;}
    	auto pii = getDiamDepth(i);
    	maxdist = max(maxdist, pii.first);
    	if (pii.second>=maxd){
    		tmaxd=smaxd;
    		smaxd=maxd;
    		maxd=pii.second;
    	} else if (pii.second>=smaxd){
    		tmaxd=smaxd;
    		smaxd=pii.second;
    	} else if (pii.second>=tmaxd){
    		tmaxd=pii.second;
    	}
    }
    if (tmaxd!=-1){
    	maxdist=max(maxdist,tmaxd+smaxd+2*L);
    }
    if (smaxd!=-1){
    	maxdist=max(maxdist,maxd+smaxd+L);
    }
    return maxdist;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:70:6: error: 'maxdist' was not declared in this scope; did you mean 'mindist'?
   70 |      maxdist = max(maxdist, pii.first);
      |      ^~~~~~~
      |      mindist
dreaming.cpp:83:6: error: 'maxdist' was not declared in this scope; did you mean 'mindist'?
   83 |      maxdist=max(maxdist,tmaxd+smaxd+2*L);
      |      ^~~~~~~
      |      mindist
dreaming.cpp:86:6: error: 'maxdist' was not declared in this scope; did you mean 'mindist'?
   86 |      maxdist=max(maxdist,maxd+smaxd+L);
      |      ^~~~~~~
      |      mindist
dreaming.cpp:88:12: error: 'maxdist' was not declared in this scope; did you mean 'mindist'?
   88 |     return maxdist;
      |            ^~~~~~~
      |            mindist
dreaming.cpp:63:9: warning: unused variable 'mindist' [-Wunused-variable]
   63 |     int mindist = -1;
      |         ^~~~~~~