Submission #827866

# Submission time Handle Problem Language Result Execution time Memory
827866 2023-08-16T21:00:07 Z gromperen Highway Tolls (IOI18_highway) C++14
0 / 100
14 ms 2340 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
  int m = u.size();
  vector<int> vs(n);
  vector<int> w(m, 0);
  int cost = ask(w);
  for (int i =0 ; i < n; ++i) vs.push_back(i);
  int l = 0, r = m-1;
  while(l < r) {
	int mid = (l+r)/2;
	for (int i = 0; i < m; ++i) {
		if (l <= i && i <= mid) w[i] = 1;
		else w[i] = 0;
	}
	if (ask(w) == cost) {
		l = mid+1;
	} else {
		r = mid;
	}
  }

  int s1 = u[l], s2 = v[l];
  vector<vector<pair<int,int>>> adj(n);
  for (int i = 0; i < m; ++i) {
	if(i == l) continue;
	adj[u[i]].emplace_back(v[i], i);
	adj[v[i]].emplace_back(u[i], i);
  }
  vector<int> ps, qs;
  vector<int> vps, vqs;
  vps.push_back(s1);
  vqs.push_back(s2);
  vector<bool> vis(n,0);
  queue<int> q;
  q.push(s1);
  while(!q.empty()) {
	  int u = q.front(); q.pop();
	  vis[u] = 1;
	  for (auto i : adj[u]) {
		  if(!vis[i.first]) {
			  vis[i.first] = 1;
			  ps.push_back(i.second);
			  vps.push_back(i.first);
			  q.push(i.first);
		  }
	  }
  }
  vis.assign(n,false);
  q.push(s2);
  while(!q.empty()) {
	  int u = q.front(); q.pop();
	  vis[u] = 1;
	  for (auto i : adj[u]) {
		  if(!vis[i.first]) {
			  vis[i.first] = 1;
			  qs.push_back(i.second);
			  vqs.push_back(i.first);
			  q.push(i.first);
		  }
	  }
  }

  l = 0, r = ps.size()-1;
  while(l<r) {
	int mid = (l+r)/2;
	for (int i = 0; i < m; ++i) {
		if (mid < i && i <= r) w[ps[i]] = 1;
		else w[ps[i]] = 0;
	}
	if (ask(w) == cost) {
		r = mid;
	} else {
		l = mid;
	}
  }
  int ans2 = vps[l];
  l = 0, r = qs.size()-1;
  while(l<r) {
	int mid = (l+r)/2;
	for (int i = 0; i < m; ++i) {
		if (mid < i && i <= r) w[qs[i]] = 1;
		else w[qs[i]] = 0;
	}
	if (ask(w) == cost) {
		r = mid;
	} else {
		l = mid;
	}
  }
  int ans1 = vqs[l];




  answer(ans1, ans2);
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 292 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1488 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 1500 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -