답안 #140903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140903 2019-08-06T03:05:29 Z cfalas 꿈 (IOI13_dreaming) C++14
18 / 100
1000 ms 12152 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#include "dreaming.h"

typedef pair<long long, long long> ii;
typedef vector<ii> vii;
vector<vii> adj;
long long longest[1000000];
long long ans=0;
long long minm;
long long maxans=0;
vector<bool> vis;
// O(N)
bool dfs(long long s, long long pre=-1){
	vis[s] = true;
	if(minm==-1) minm = longest[s];
	else minm = min(minm, longest[s]);
	maxans = max(ans, maxans);
	for(long long i=0;i<adj[s].size();i++){
		if(adj[s][i].F!=pre){
			ans+=adj[s][i].S;
			dfs(adj[s][i].F, s);
			ans-=adj[s][i].S;
		}
	}
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
	adj.assign(n+1, vii());
	vis.assign(n+1, false);
	// O(N)
	for(long long i=0;i<m;i++){
		adj[A[i]].push_back(ii(B[i], T[i]));
		adj[B[i]].push_back(ii(A[i], T[i]));
	}
	long long maxlong = 0;
	// O(N^2)
	for(long long i=0;i<n;i++){
		vis.assign(n+1, false);
		maxans = 0;
		ans = 0;
		dfs(i);
		longest[i] = maxans;
		//cout<<longest[i]<<" ";
		maxlong = max(maxans, maxlong);
	}
	if(n==m+1) return maxlong;
	// O(N)
	vis.assign(n+1, false);
	ans = 0;
	//cout<<endl;
	long long max1=0, max2=0;
	long long max3=0;
	// O(N^2)
	for(long long i=0;i<n;i++){
		if(!vis[i]){
			minm = -1;
			dfs(i);
			//cout<<minm<<" ";
			if(minm>max1) max3=max2, max2=max1, max1=minm;
			else if(minm>max2) max3=max2, max2=minm;
			else if(minm>max3) max3=minm;
		}
	}
	if(n-m-1>=3)
	return max(max1+max2+L, max(maxlong, max2+max3+2*L));
	else
		return max(max1+max2+L, maxlong);
}

Compilation message

dreaming.cpp: In function 'bool dfs(long long int, long long int)':
dreaming.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(long long i=0;i<adj[s].size();i++){
                    ~^~~~~~~~~~~~~~
dreaming.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 5668 KB Output is correct
2 Correct 119 ms 5624 KB Output is correct
3 Correct 121 ms 5644 KB Output is correct
4 Correct 110 ms 5636 KB Output is correct
5 Correct 109 ms 5584 KB Output is correct
6 Correct 116 ms 5880 KB Output is correct
7 Correct 119 ms 6008 KB Output is correct
8 Correct 100 ms 5564 KB Output is correct
9 Correct 104 ms 5532 KB Output is correct
10 Correct 111 ms 5752 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 78 ms 3448 KB Output is correct
13 Correct 81 ms 3560 KB Output is correct
14 Correct 79 ms 3576 KB Output is correct
15 Correct 79 ms 3576 KB Output is correct
16 Correct 78 ms 3448 KB Output is correct
17 Correct 78 ms 3460 KB Output is correct
18 Correct 82 ms 3576 KB Output is correct
19 Correct 78 ms 3448 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 78 ms 3556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 12152 KB Time limit exceeded
2 Halted 0 ms 0 KB -