답안 #210650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210650 2020-03-18T01:04:38 Z peuch 꿈 (IOI13_dreaming) C++17
0 / 100
95 ms 20216 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;

const int MAXN = 1e5 + 10; 

int marc[MAXN], dist[MAXN], longDist[2][MAXN];

vector<int> ar[MAXN];
vector<int> wg[MAXN];
vector<int> group;

int dfs1(int cur);
int dfs2(int cur);
int dfs3(int cur);

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i = 0; i < M; i++){
		ar[A[i]].push_back(B[i]);
		ar[B[i]].push_back(A[i]);
		wg[A[i]].push_back(T[i]);
		wg[B[i]].push_back(T[i]);
	}
	for(int i = 0; i < N; i++){
		if(marc[i] == 3) continue;
		dist[i] = 0;
		int side1 = dfs1(i);
		longDist[0][side1] = 0;
		int side2 = dfs2(side1);
		// printf("group: %d ends = %d and %d\n", group.size(), side1, side2);
		longDist[1][side2] = 0;
		group.push_back(dfs3(side2));
	}
	// printf("%d\n", group.size());
	// for(int i = 0; i < group.size(); i++)
	// 	printf("%d ", group[i]);
	// printf("\n");
	int ret = 0;
	for(int i = 1; i < group.size(); i++){
		ret = max(ret, group[i] + group[i - 1] + L);
		group[i] = min(max(group[i], group[i - 1] + L), max(group[i - 1], group[i] + L));
	}
    return ret;
}

int dfs1(int cur){
	marc[cur] = 1;
	int ret = cur;
	int auxRet = dist[cur];
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 1) continue;
		dist[viz] = dist[cur] + len;
		int dfsVal = dfs1(viz);
		if(dist[dfsVal] > auxRet) ret = dfsVal, auxRet = dist[dfsVal];
 	} 
 	return ret;
}

int dfs2(int cur){
	marc[cur] = 2;
	int ret = cur;
	int auxRet = longDist[0][cur];
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 2) continue;
		longDist[0][viz] = longDist[0][cur] + len;
		int dfsVal = dfs2(viz);
		if(longDist[0][dfsVal] > auxRet) ret = dfsVal, auxRet = longDist[0][dfsVal];
 	} 
 	return ret;
}

int dfs3(int cur){
	marc[cur] = 3;
	int ret = max(longDist[0][cur], longDist[1][cur]);
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 3) continue;
		longDist[1][viz] = longDist[1][cur] + len;
		ret = min(ret, dfs3(viz));
 	} 
 	return ret;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < group.size(); i++){
                 ~~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int)':
dreaming.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs3(int)':
dreaming.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11640 KB Output is correct
2 Incorrect 43 ms 11640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -