답안 #502628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502628 2022-01-06T11:02:44 Z NintsiChkhaidze 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 15808 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define ll long long
using namespace std;

const int N = 100005;
vector <pair<int,ll> > v[N];
vector <int> vec;
int p[N],fix[N],I;
ll diameter,d[N],D,l;

void dfs(int x,ll d,int par){
	if (d > D) {I = x,D = d;}
	for (int j=0;j<v[x].size();j++){
		int to = v[x][j].f,w = v[x][j].s;
		if (to == par) continue;
		dfs(to,d + w,x);
	}
}
ll upd(ll d1,ll d2){
	ll d_new = min(max(d1 + l,d2),max(d1,d2 + l));
	diameter = max(diameter,d1 + l + d2);
	return d_new;
}

int P(int x){
	if (x == p[x]) return x;
	return p[x] = P(p[x]);
}
void dsu(int u,int v){
	int up = P(u),vp = P(v);
	if (up == vp) return;
	if (up > vp) swap(up,vp);
	p[vp] = up;
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
	l = L;
	for (int i = 0; i < n; i++)
		p[i] = i,v[i].clear(),d[i] = 1e9;

	for (int i = 0; i < m; i++){
		v[A[i]].pb({B[i],T[i]});
		v[B[i]].pb({A[i],T[i]});
		dsu(A[i],B[i]);
	}

	for (int i = 0; i < n; i++){
		p[i] = P(i);
		D = 0;
		dfs(i,0,i);
		d[p[i]] = min(d[p[i]],D);
		if (!fix[p[i]]) fix[p[i]] = 1,vec.pb(p[i]);
	}

	D = 0;
	dfs(vec[0],0,vec[0]);
	D = 0;
	dfs(I,0,I);
	diameter = D;

	for (int i=1; i<vec.size(); i++)
		d[vec[i]] = upd(d[vec[i - 1]],d[vec[i]]);
	
	return diameter;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, long long int, int)':
dreaming.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int j=0;j<v[x].size();j++){
      |               ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (int i=1; i<vec.size(); i++)
      |                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 15808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Incorrect 2 ms 2636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 15808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7200 KB Output is correct
2 Incorrect 19 ms 7256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Incorrect 2 ms 2636 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 15808 KB Time limit exceeded
2 Halted 0 ms 0 KB -