Submission #571340

# Submission time Handle Problem Language Result Execution time Memory
571340 2022-06-01T20:37:49 Z beaconmc Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 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);
}
 
 
ll globalmax = 0;
 
vector<pair<ll, ll>> edges[100005];
vector<ll> sussies[100005];
bool visited[100005];
 
 
int sus(vector<ll> a){
	if (a.size()==1) return 0;
 
	
	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 (auto&i : a) visited[i] = 0; 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 = 1000000000000;
	ll cur = 0;
	globalmax = max(globalmax, path[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());
 
	// for (auto&i : kindasus){
	// 	cout << i << endl;
	// }
 
	if (kindasus.size() == 1) return globalmax;
 
	if (kindasus.size()==2){
		return max(globalmax, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L);
	}
 
 
	return max(globalmax, max(kindasus[kindasus.size()-2] + kindasus[kindasus.size()-3] + 2*L, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L));
 
}

Compilation message

dreaming.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
dreaming.cpp:13:1: error: 'll' does not name a type
   13 | ll cc[100005];
      | ^~
dreaming.cpp:15:1: error: 'll' does not name a type
   15 | ll find(ll a){
      | ^~
dreaming.cpp:19:6: error: variable or field 'unite' declared void
   19 | void unite(ll a,ll b){
      |      ^~~~~
dreaming.cpp:19:12: error: 'll' was not declared in this scope
   19 | void unite(ll a,ll b){
      |            ^~
dreaming.cpp:19:17: error: 'll' was not declared in this scope
   19 | void unite(ll a,ll b){
      |                 ^~
dreaming.cpp:24:1: error: 'll' does not name a type
   24 | ll globalmax = 0;
      | ^~
dreaming.cpp:26:1: error: 'vector' does not name a type
   26 | vector<pair<ll, ll>> edges[100005];
      | ^~~~~~
dreaming.cpp:27:1: error: 'vector' does not name a type
   27 | vector<ll> sussies[100005];
      | ^~~~~~
dreaming.cpp:31:9: error: 'vector' was not declared in this scope
   31 | int sus(vector<ll> a){
      |         ^~~~~~
dreaming.cpp:8:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    7 | #include "dreaming.h"
  +++ |+#include <vector>
    8 | 
dreaming.cpp:31:16: error: 'll' was not declared in this scope
   31 | int sus(vector<ll> a){
      |                ^~
dreaming.cpp:31:20: error: 'a' was not declared in this scope
   31 | int sus(vector<ll> a){
      |                    ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:4:24: error: 'll' was not declared in this scope
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                        ^~
dreaming.cpp:119:2: note: in expansion of macro 'FOR'
  119 |  FOR(i,0,n) cc[i] = i;
      |  ^~~
dreaming.cpp:119:6: error: 'i' was not declared in this scope
  119 |  FOR(i,0,n) cc[i] = i;
      |      ^
dreaming.cpp:4:32: note: in definition of macro 'FOR'
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                                ^
dreaming.cpp:119:13: error: 'cc' was not declared in this scope
  119 |  FOR(i,0,n) cc[i] = i;
      |             ^~
dreaming.cpp:4:24: error: 'll' was not declared in this scope
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                        ^~
dreaming.cpp:121:2: note: in expansion of macro 'FOR'
  121 |  FOR(i,0,m){
      |  ^~~
dreaming.cpp:121:6: error: 'i' was not declared in this scope
  121 |  FOR(i,0,m){
      |      ^
dreaming.cpp:4:32: note: in definition of macro 'FOR'
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                                ^
dreaming.cpp:122:3: error: 'edges' was not declared in this scope
  122 |   edges[a[i]].push_back({b[i], t[i]});
      |   ^~~~~
dreaming.cpp:4:24: error: 'll' was not declared in this scope
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                        ^~
dreaming.cpp:126:2: note: in expansion of macro 'FOR'
  126 |  FOR(i,0,n){
      |  ^~~
dreaming.cpp:126:6: error: 'i' was not declared in this scope
  126 |  FOR(i,0,n){
      |      ^
dreaming.cpp:4:32: note: in definition of macro 'FOR'
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                                ^
dreaming.cpp:127:17: error: 'edges' was not declared in this scope
  127 |   for (auto&j : edges[i]){
      |                 ^~~~~
dreaming.cpp:128:4: error: 'unite' was not declared in this scope
  128 |    unite(i, j.first);
      |    ^~~~~
dreaming.cpp:4:24: error: 'll' was not declared in this scope
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                        ^~
dreaming.cpp:132:2: note: in expansion of macro 'FOR'
  132 |  FOR(i,0,n){
      |  ^~~
dreaming.cpp:132:6: error: 'i' was not declared in this scope
  132 |  FOR(i,0,n){
      |      ^
dreaming.cpp:4:32: note: in definition of macro 'FOR'
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
      |                                ^
dreaming.cpp:133:3: error: 'sussies' was not declared in this scope
  133 |   sussies[find(i)].push_back(i);
      |   ^~~~~~~
dreaming.cpp:133:11: error: 'find' was not declared in this scope
  133 |   sussies[find(i)].push_back(i);
      |           ^~~~
dreaming.cpp:135:2: error: 'vector' was not declared in this scope
  135 |  vector<ll> kindasus;
      |  ^~~~~~
dreaming.cpp:135:2: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
dreaming.cpp:135:9: error: 'll' was not declared in this scope
  135 |  vector<ll> kindasus;
      |         ^~
dreaming.cpp:135:13: error: 'kindasus' was not declared in this scope
  135 |  vector<ll> kindasus;
      |             ^~~~~~~~
dreaming.cpp:138:16: error: 'sussies' was not declared in this scope
  138 |  for (auto&i : sussies){
      |                ^~~~~~~
dreaming.cpp:140:27: error: 'sus' cannot be used as a function
  140 |   kindasus.push_back(sus(i));
      |                           ^
dreaming.cpp:143:2: error: 'sort' was not declared in this scope; did you mean 'short'?
  143 |  sort(kindasus.begin(), kindasus.end());
      |  ^~~~
      |  short
dreaming.cpp:149:35: error: 'globalmax' was not declared in this scope
  149 |  if (kindasus.size() == 1) return globalmax;
      |                                   ^~~~~~~~~
dreaming.cpp:152:14: error: 'globalmax' was not declared in this scope
  152 |   return max(globalmax, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L);
      |              ^~~~~~~~~
dreaming.cpp:152:10: error: 'max' was not declared in this scope
  152 |   return max(globalmax, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L);
      |          ^~~
dreaming.cpp:156:13: error: 'globalmax' was not declared in this scope
  156 |  return max(globalmax, max(kindasus[kindasus.size()-2] + kindasus[kindasus.size()-3] + 2*L, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L));
      |             ^~~~~~~~~
dreaming.cpp:156:24: error: 'max' was not declared in this scope
  156 |  return max(globalmax, max(kindasus[kindasus.size()-2] + kindasus[kindasus.size()-3] + 2*L, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L));
      |                        ^~~
dreaming.cpp:156:9: error: 'max' was not declared in this scope
  156 |  return max(globalmax, max(kindasus[kindasus.size()-2] + kindasus[kindasus.size()-3] + 2*L, kindasus[kindasus.size()-1] + kindasus[kindasus.size()-2] + L));
      |         ^~~