Submission #1078846

#TimeUsernameProblemLanguageResultExecution timeMemory
1078846Rawlat_vanakCyberland (APIO23_cyberland)C++17
Compilation error
0 ms0 KiB
vector<vector<pii>> graph;
vector<int> parent,sz;

int find(int u){
	while(u!=parent[u]) u=parent[u];
	return parent[u];
}

void unite(int a,int b){
	a=find(a);b=find(b);
	if(a==b) return;
	if(sz[b]>sz[a]) swap(a,b);
	parent[b]=a;
	sz[a]+=sz[b];

}

double solve(int n,int m,int k,int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){

	parent.resize(n);
	for(int i=0;i<n;i++){
		parent[i]=i;
	}
	sz.resize(n,1);
	graph.resize(n);
	for(int i=0;i<n;i++){
		graph[x[i]].pb({y[i],c[i]});
		graph[y[i]].pb({x[i],c[i]});
		unite(x[i],y[i]);
	}

	priority_queue<pii> q;
	vector<vector<double>> dist(n,vector<double>(k+1,1e15));
	vector<bool> visited(n,false);
	
	for(int j=0;j<=k;j++){
		if(find(0)==find(h)){
			dist[0][j]=0;
			q.push({0,0});
		}
		visited[0]=false;
		for(int i=1;i<n;i++){
			visited[i]=false;
			if(arr[i]==0 and find(i)==find(h)){
				dist[i][j]=0;
				q.push({0,i});
			}
		}
		while(!q.empty()){
				pii u=q.top();
				int v=u.s;
				q.pop();
				if(visited[v]) continue;
				visited[v]=true;
				for(pii w: graph[v]){
					int x=w.f,c=w.s;
					if(arr[x]==1){
						if(dist[w.f][j]>dist[v][j]+w.s){
							dist[w.f][j]=dist[v][j]+w.s;
							q.push({-dist[w.f][j],w.f});
						}
					}else if(arr[x]==2){
						if(dist[w.f][j]>dist[v][j]+w.s){
							dist[w.f][j]=dist[v][j]+w.s;
							q.push({-dist[w.f][j],w.f});
						}
						if(j>=1){
							if(dist[x][j]>(dist[v][j-1]+c)/2){
								dist[x][j]=(dist[v][j-1]+c)/2;
								q.push({-dist[x][j],x});
							}
						}
					}
				}
		}
	}
	double ans=1e15;
	for(int i=0;i<=k;i++){
		ans=min(ans,dist[h][i]);
	}

	for(int i=0;i<n;i++){
		graph[i].clear();
		dist[i].clear();
		parent.clear();
		visited.clear();
		sz.clear();
	}
	if(ans==1e15){
		return -1;
	}else{
		return ans;
	}

}

Compilation message (stderr)

cyberland.cpp:1:1: error: 'vector' does not name a type
    1 | vector<vector<pii>> graph;
      | ^~~~~~
cyberland.cpp:2:1: error: 'vector' does not name a type
    2 | vector<int> parent,sz;
      | ^~~~~~
cyberland.cpp: In function 'int find(int)':
cyberland.cpp:5:11: error: 'parent' was not declared in this scope
    5 |  while(u!=parent[u]) u=parent[u];
      |           ^~~~~~
cyberland.cpp:6:9: error: 'parent' was not declared in this scope
    6 |  return parent[u];
      |         ^~~~~~
cyberland.cpp: In function 'void unite(int, int)':
cyberland.cpp:12:5: error: 'sz' was not declared in this scope
   12 |  if(sz[b]>sz[a]) swap(a,b);
      |     ^~
cyberland.cpp:12:18: error: 'swap' was not declared in this scope
   12 |  if(sz[b]>sz[a]) swap(a,b);
      |                  ^~~~
cyberland.cpp:13:2: error: 'parent' was not declared in this scope
   13 |  parent[b]=a;
      |  ^~~~~~
cyberland.cpp:14:2: error: 'sz' was not declared in this scope
   14 |  sz[a]+=sz[b];
      |  ^~
cyberland.cpp: At global scope:
cyberland.cpp:18:39: error: 'vector' has not been declared
   18 | double solve(int n,int m,int k,int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
      |                                       ^~~~~~
cyberland.cpp:18:45: error: expected ',' or '...' before '<' token
   18 | double solve(int n,int m,int k,int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
      |                                             ^
cyberland.cpp: In function 'double solve(int, int, int, int, int)':
cyberland.cpp:20:2: error: 'parent' was not declared in this scope
   20 |  parent.resize(n);
      |  ^~~~~~
cyberland.cpp:24:2: error: 'sz' was not declared in this scope
   24 |  sz.resize(n,1);
      |  ^~
cyberland.cpp:25:2: error: 'graph' was not declared in this scope
   25 |  graph.resize(n);
      |  ^~~~~
cyberland.cpp:27:9: error: 'x' was not declared in this scope
   27 |   graph[x[i]].pb({y[i],c[i]});
      |         ^
cyberland.cpp:27:19: error: 'y' was not declared in this scope
   27 |   graph[x[i]].pb({y[i],c[i]});
      |                   ^
cyberland.cpp:27:24: error: 'c' was not declared in this scope
   27 |   graph[x[i]].pb({y[i],c[i]});
      |                        ^
cyberland.cpp:32:2: error: 'priority_queue' was not declared in this scope
   32 |  priority_queue<pii> q;
      |  ^~~~~~~~~~~~~~
cyberland.cpp:32:17: error: 'pii' was not declared in this scope
   32 |  priority_queue<pii> q;
      |                 ^~~
cyberland.cpp:32:22: error: 'q' was not declared in this scope
   32 |  priority_queue<pii> q;
      |                      ^
cyberland.cpp:33:2: error: 'vector' was not declared in this scope
   33 |  vector<vector<double>> dist(n,vector<double>(k+1,1e15));
      |  ^~~~~~
cyberland.cpp:33:16: error: expected primary-expression before 'double'
   33 |  vector<vector<double>> dist(n,vector<double>(k+1,1e15));
      |                ^~~~~~
cyberland.cpp:34:9: error: expected primary-expression before 'bool'
   34 |  vector<bool> visited(n,false);
      |         ^~~~
cyberland.cpp:38:4: error: 'dist' was not declared in this scope
   38 |    dist[0][j]=0;
      |    ^~~~
cyberland.cpp:41:3: error: 'visited' was not declared in this scope
   41 |   visited[0]=false;
      |   ^~~~~~~
cyberland.cpp:44:7: error: 'arr' was not declared in this scope
   44 |    if(arr[i]==0 and find(i)==find(h)){
      |       ^~~
cyberland.cpp:45:5: error: 'dist' was not declared in this scope
   45 |     dist[i][j]=0;
      |     ^~~~
cyberland.cpp:50:8: error: expected ';' before 'u'
   50 |     pii u=q.top();
      |        ^~
      |        ;
cyberland.cpp:51:11: error: 'u' was not declared in this scope
   51 |     int v=u.s;
      |           ^
cyberland.cpp:55:12: error: expected ';' before 'w'
   55 |     for(pii w: graph[v]){
      |            ^~
      |            ;
cyberland.cpp:75:3: error: expected primary-expression before '}' token
   75 |   }
      |   ^
cyberland.cpp:74:6: error: expected ';' before '}' token
   74 |     }
      |      ^
      |      ;
   75 |   }
      |   ~   
cyberland.cpp:75:3: error: expected primary-expression before '}' token
   75 |   }
      |   ^
cyberland.cpp:74:6: error: expected ')' before '}' token
   74 |     }
      |      ^
      |      )
   75 |   }
      |   ~   
cyberland.cpp:55:8: note: to match this '('
   55 |     for(pii w: graph[v]){
      |        ^
cyberland.cpp:75:3: error: expected primary-expression before '}' token
   75 |   }
      |   ^
cyberland.cpp:79:15: error: 'dist' was not declared in this scope
   79 |   ans=min(ans,dist[h][i]);
      |               ^~~~
cyberland.cpp:79:7: error: 'min' was not declared in this scope
   79 |   ans=min(ans,dist[h][i]);
      |       ^~~
cyberland.cpp:84:3: error: 'dist' was not declared in this scope
   84 |   dist[i].clear();
      |   ^~~~
cyberland.cpp:86:3: error: 'visited' was not declared in this scope
   86 |   visited.clear();
      |   ^~~~~~~