답안 #125642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125642 2019-07-06T06:57:43 Z nxteru 꿈 (IOI13_dreaming) C++14
18 / 100
94 ms 13820 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define PB push_back
#define F first
#define S second
#define INF 1000000001
int n,m,dp[100005];
vector<P>g[100005];
bool vis[100005];
void dfs1(int v,int p){
	vis[v]=true;
	dp[v]=0;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i].F,c=g[v][i].S;
		if(u==p)continue;
		dfs1(u,v);
		dp[v]=max(dp[v],dp[u]+c);
	}
}
int dfs2(int v,int p,int x){
	int l[g[v].size()],r[g[v].size()];
	for(int i=0;i<g[v].size();i++)l[i]=0,r[i]=0;
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i].F,c=g[v][i].S;
		if(u==p){
			dp[v]=max(dp[v],x+c);
			l[i]=x+c,r[i]=x+c;
		}else l[i]=dp[u]+c,r[i]=dp[u]+c;
	}
	int res=dp[v];
	for(int i=1;i<g[v].size();i++)l[i]=max(l[i],l[i-1]);
	for(int i=g[v].size()-1;i>0;i--)r[i-1]=max(r[i-1],r[i]);
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i].F;
		if(u==p)continue;
		int c=0;
		if(i>0)c=max(c,l[i-1]);
		if(i+1<g[v].size())c=max(c,r[i+1]);
		res=min(res,dfs2(u,v,c));
	}
	return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n=N,m=M;
	for(int i=0;i<m;i++){
		g[A[i]].PB(P(B[i],T[i]));
		g[B[i]].PB(P(A[i],T[i]));
	}
	vector<int>p;
	for(int i=n-1;i>=0;i--){
		if(!vis[i]){
			dfs1(i,-1);
			p.PB(dfs2(i,-1,0));
		}
	}
	sort(p.begin(),p.end(),greater<int>());
	for(int i=1;i<p.size();i++)p[i]+=L;
	p.PB(0);
	sort(p.begin(),p.end(),greater<int>());
	return p[0]+p[1];
}

Compilation message

dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int, int, int)':
dreaming.cpp:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++)l[i]=0,r[i]=0;
              ~^~~~~~~~~~~~
dreaming.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
dreaming.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<g[v].size();i++)l[i]=max(l[i],l[i-1]);
              ~^~~~~~~~~~~~
dreaming.cpp:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[v].size();i++){
              ~^~~~~~~~~~~~
dreaming.cpp:40:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i+1<g[v].size())c=max(c,r[i+1]);
      ~~~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:59:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<p.size();i++)p[i]+=L;
              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 6056 KB Output is correct
2 Correct 33 ms 6136 KB Output is correct
3 Correct 35 ms 6136 KB Output is correct
4 Correct 43 ms 6140 KB Output is correct
5 Correct 30 ms 6136 KB Output is correct
6 Correct 34 ms 6572 KB Output is correct
7 Correct 35 ms 6236 KB Output is correct
8 Correct 31 ms 6008 KB Output is correct
9 Correct 32 ms 6136 KB Output is correct
10 Correct 31 ms 6264 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 10 ms 3828 KB Output is correct
13 Correct 10 ms 3828 KB Output is correct
14 Correct 9 ms 3800 KB Output is correct
15 Correct 10 ms 3956 KB Output is correct
16 Correct 10 ms 3868 KB Output is correct
17 Correct 9 ms 3700 KB Output is correct
18 Correct 10 ms 3956 KB Output is correct
19 Correct 10 ms 3828 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2808 KB Output is correct
23 Correct 10 ms 3828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -