답안 #571264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571264 2022-06-01T15:37:04 Z beaconmc 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 15996 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
#define double long double
#include "dreaming.h"

using namespace std;


ll cc[100005];

ll find(ll a){
    while (a!=cc[a]) cc[a] = cc[cc[a]], a = cc[a];
    return a;
}
void unite(ll a,ll b){
    cc[find(a)] = find(b);
}


vector<pair<ll, ll>> edges[100005];
vector<ll> sussies[100005];


int sus(vector<ll> a){
	if (a.size()==1) return 0;

	bool visited[100005];
	FOR(i,0,100004) visited[i] = 1;

	for (auto&i : a){
		visited[i] = 0;
	}
	vector<vector<ll>> stack;
	ll maxi = 0;
	vector<ll> path;

	stack.push_back({0,a[0]});
	visited[a[0]] = 1;

	while (stack.size()){
		vector<ll> temp;

		vector<ll> node = stack[stack.size()-1];

		stack.pop_back();

		if (maxi < node[0]) path = node, maxi = node[0];


		for (auto&i : edges[node[node.size()-1]]){
			if (!visited[i.first]){
				visited[i.first] = 1;
				temp = node;
				temp[0] += i.second;
				temp.push_back(i.first);
				stack.push_back(temp);
			}
		}
	}


	ll realsus = path[path.size()-1];


	FOR(i,0,100004) visited[i] = 1;

	for (auto&i : a){
		visited[i] = 0;
	}
	stack.clear();
	maxi = 0;
	path.clear();
	stack.push_back({0,0,realsus});
	visited[realsus] = 1;



	while (stack.size()){
		vector<ll> temp;

		vector<ll> node = stack[stack.size()-1];
		stack.pop_back();

		if (maxi < node[0]) path = node, maxi = node[0];

		for (auto&i : edges[node[node.size()-1]]){
			if (!visited[i.first]){
				visited[i.first] = 1;
				temp = node;
				temp.pop_back();
				temp[0] += i.second;
				temp.push_back(i.second);
				temp.push_back(i.first);
				stack.push_back(temp);
			}
		}
	}

	ll mini = 1000000000;
	ll cur = 0;




	FOR(i,1,path.size()-1){
		cur += path[i];
		mini = min(mini, max(path[0]-cur, cur));
	}


	return mini;

}


int travelTime(int n, int m, int L, int a[], int b[], int t[]){
	FOR(i,0,n) cc[i] = i;

	FOR(i,0,m){
		edges[a[i]].push_back({b[i], t[i]});
		edges[b[i]].push_back({a[i], t[i]});
	}

	FOR(i,0,n){
		for (auto&j : edges[i]){
			unite(i, j.first);
		}
	}

	FOR(i,0,n){
		sussies[find(i)].push_back(i);
	}
	vector<ll> kindasus;


	for (auto&i : sussies){
		if (i.size()==0) continue;
		kindasus.push_back(sus(i));
	}

	sort(kindasus.begin(), kindasus.end());


	return kindasus[kindasus.size()-2] + kindasus[kindasus.size()-1] + L;

}

// int main(){
// 	int a[8] = {0, 8, 2, 5, 5, 1, 1, 10}, b[8]= {8, 2, 7, 11, 1, 3, 9, 6}, c[8]={4, 2, 4, 3, 7, 1, 5, 3};
// 	cout << travelTime(12, 8, 2,a,b,c);






// }

Compilation message

dreaming.cpp: In function 'int sus(std::vector<long long int>)':
dreaming.cpp:4:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
  108 |  FOR(i,1,path.size()-1){
      |      ~~~~~~~~~~~~~~~~~           
dreaming.cpp:108:2: note: in expansion of macro 'FOR'
  108 |  FOR(i,1,path.size()-1){
      |  ^~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 15996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 15996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 11108 KB Output is correct
2 Incorrect 227 ms 11200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 15996 KB Time limit exceeded
2 Halted 0 ms 0 KB -