Submission #1014135

# Submission time Handle Problem Language Result Execution time Memory
1014135 2024-07-04T12:06:10 Z Belphegor Highway Tolls (IOI18_highway) C++14
100 / 100
153 ms 12532 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int sz = 100000;
vector<pi>tree[sz+5];
int visited[sz+5];
int parent_a[sz+5],parent_b[sz+5];
int dist_a[sz+5],dist_b[sz+5];
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
	int m = U.size();
	for(int i=0; i<U.size(); i++){
		int a = U[i],b = V[i];
		tree[a].emplace_back(pi(b,i));
		tree[b].emplace_back(pi(a,i));
	}
	vector<int>w(m,0);
	ll d = ask(w);
  
	int l = 0,r = m-2;
	while(l<=r){
		int M = (l+r)>>1;
		for(int i=0; i<=M; i++) w[i] = 1;
		if(ask(w)==d) l = M+1;
		else r = M-1;
		for(int i=0; i<=M; i++) w[i] = 0;
	}
	int e = l;
	int a = U[e],b = V[e];
    for(int i=0; i<n; i++) dist_a[i] = dist_b[i] = -1;
	
    dist_a[a] = 0; parent_a[a] = e;
	queue<int>q; q.push(a);
	while(!q.empty()){
		int cur = q.front(); q.pop();
		for(pi p : tree[cur]){
			int nxt = p.first;
			int id = p.second;
			if(dist_a[nxt] == -1){
				dist_a[nxt] = dist_a[cur] + 1;
              	parent_a[nxt] = id;
				q.push(nxt);
			}
		}
	}
	dist_b[b] = 0; parent_b[b] = e;
	q.push(b);
	while(!q.empty()){
		int cur = q.front(); q.pop();
		for(pi p : tree[cur]){
			int nxt = p.first;
			int id = p.second;
			if(dist_b[nxt] == -1){
				dist_b[nxt] = dist_b[cur] + 1;
              	parent_b[nxt] = id;
				q.push(nxt);
			}
		}
	}
	vector<pi>c1,c2;
	for(int i=0; i<n; i++){
		if(dist_a[i] < dist_b[i]) c1.emplace_back(pi(i,parent_a[i]));
	}
    sort(c1.begin(),c1.end(),[&](const pi&x,const pi&y){
      return dist_a[x.first] > dist_a[y.first];
    });
	for(int i=0; i<n; i++){
		if(dist_b[i] < dist_a[i]) c2.emplace_back(pi(i,parent_b[i]));
	}
     sort(c2.begin(),c2.end(),[&](const pi&x,const pi&y){
      return dist_b[x.first] > dist_b[y.first];
    });
    for(int i=0; i<m; i++) w[i] = 1;
  	for(pi p : c1) w[p.second] = 0;
  	for(pi p : c2) w[p.second] = 0;
    l = 0,r = c1.size()-1;
  	while(l<=r){
      int M = (l+r)>>1;
      for(int i=0; i<=M; i++) w[c1[i].second] = 1;
      if(ask(w) > d) r = M-1;
      else l = M+1;
      for(int i=0; i<=M; i++) w[c1[i].second] = 0;
    }
    a = c1[l].first;
  l = 0,r = c2.size()-1;
  while(l<=r){
    int M = (l+r)>>1;
    for(int i=0; i<=M; i++) w[c2[i].second] = 1;
    if(ask(w) > d) r = M-1;
    else l = M+1;
    for(int i=0; i<=M; i++) w[c2[i].second] = 0;
  }
  b = c2[l].first;
	answer(a,b);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:13:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i=0; i<U.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 9 ms 3672 KB Output is correct
3 Correct 89 ms 10516 KB Output is correct
4 Correct 89 ms 10524 KB Output is correct
5 Correct 78 ms 10520 KB Output is correct
6 Correct 95 ms 10396 KB Output is correct
7 Correct 83 ms 10440 KB Output is correct
8 Correct 81 ms 10440 KB Output is correct
9 Correct 83 ms 10448 KB Output is correct
10 Correct 80 ms 10448 KB Output is correct
11 Correct 115 ms 9748 KB Output is correct
12 Correct 79 ms 9784 KB Output is correct
13 Correct 83 ms 9952 KB Output is correct
14 Correct 93 ms 9788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3668 KB Output is correct
2 Correct 16 ms 4316 KB Output is correct
3 Correct 24 ms 5128 KB Output is correct
4 Correct 63 ms 9624 KB Output is correct
5 Correct 85 ms 9668 KB Output is correct
6 Correct 75 ms 9844 KB Output is correct
7 Correct 67 ms 9880 KB Output is correct
8 Correct 67 ms 9548 KB Output is correct
9 Correct 65 ms 9964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 9 ms 3688 KB Output is correct
3 Correct 72 ms 8892 KB Output is correct
4 Correct 84 ms 10520 KB Output is correct
5 Correct 89 ms 10392 KB Output is correct
6 Correct 80 ms 10440 KB Output is correct
7 Correct 75 ms 10704 KB Output is correct
8 Correct 79 ms 10524 KB Output is correct
9 Correct 99 ms 10352 KB Output is correct
10 Correct 93 ms 10544 KB Output is correct
11 Correct 103 ms 9916 KB Output is correct
12 Correct 85 ms 10008 KB Output is correct
13 Correct 93 ms 9916 KB Output is correct
14 Correct 100 ms 9748 KB Output is correct
15 Correct 78 ms 10764 KB Output is correct
16 Correct 80 ms 10400 KB Output is correct
17 Correct 93 ms 9916 KB Output is correct
18 Correct 97 ms 9872 KB Output is correct
19 Correct 74 ms 10332 KB Output is correct
20 Correct 89 ms 9984 KB Output is correct
21 Correct 74 ms 11344 KB Output is correct
22 Correct 72 ms 11340 KB Output is correct
23 Correct 80 ms 10776 KB Output is correct
24 Correct 73 ms 10688 KB Output is correct
25 Correct 83 ms 10000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3720 KB Output is correct
2 Correct 11 ms 3672 KB Output is correct
3 Correct 99 ms 10772 KB Output is correct
4 Correct 110 ms 11288 KB Output is correct
5 Correct 130 ms 12532 KB Output is correct
6 Correct 118 ms 11860 KB Output is correct
7 Correct 123 ms 12204 KB Output is correct
8 Correct 132 ms 12032 KB Output is correct
9 Correct 102 ms 9208 KB Output is correct
10 Correct 89 ms 9656 KB Output is correct
11 Correct 96 ms 10324 KB Output is correct
12 Correct 126 ms 11176 KB Output is correct
13 Correct 124 ms 11524 KB Output is correct
14 Correct 124 ms 12000 KB Output is correct
15 Correct 110 ms 11892 KB Output is correct
16 Correct 97 ms 10108 KB Output is correct
17 Correct 77 ms 10888 KB Output is correct
18 Correct 75 ms 10944 KB Output is correct
19 Correct 77 ms 11052 KB Output is correct
20 Correct 78 ms 11064 KB Output is correct
21 Correct 123 ms 12228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3672 KB Output is correct
2 Correct 11 ms 3572 KB Output is correct
3 Correct 117 ms 10528 KB Output is correct
4 Correct 119 ms 10740 KB Output is correct
5 Correct 110 ms 10932 KB Output is correct
6 Correct 153 ms 12260 KB Output is correct
7 Correct 94 ms 10840 KB Output is correct
8 Correct 93 ms 10936 KB Output is correct
9 Correct 100 ms 11024 KB Output is correct
10 Correct 128 ms 11980 KB Output is correct
11 Correct 134 ms 12060 KB Output is correct
12 Correct 116 ms 11936 KB Output is correct
13 Correct 98 ms 10324 KB Output is correct
14 Correct 112 ms 9648 KB Output is correct
15 Correct 102 ms 10364 KB Output is correct
16 Correct 93 ms 9648 KB Output is correct
17 Correct 101 ms 10312 KB Output is correct
18 Correct 106 ms 9720 KB Output is correct
19 Correct 140 ms 11184 KB Output is correct
20 Correct 126 ms 11572 KB Output is correct
21 Correct 148 ms 12168 KB Output is correct
22 Correct 132 ms 11988 KB Output is correct
23 Correct 117 ms 12064 KB Output is correct
24 Correct 130 ms 11884 KB Output is correct
25 Correct 128 ms 12200 KB Output is correct
26 Correct 119 ms 11992 KB Output is correct
27 Correct 66 ms 11016 KB Output is correct
28 Correct 75 ms 10980 KB Output is correct
29 Correct 93 ms 11000 KB Output is correct
30 Correct 70 ms 10912 KB Output is correct
31 Correct 90 ms 10816 KB Output is correct
32 Correct 81 ms 10900 KB Output is correct
33 Correct 76 ms 11072 KB Output is correct
34 Correct 75 ms 10864 KB Output is correct
35 Correct 94 ms 11028 KB Output is correct
36 Correct 74 ms 10816 KB Output is correct
37 Correct 71 ms 10920 KB Output is correct
38 Correct 81 ms 11060 KB Output is correct
39 Correct 122 ms 12284 KB Output is correct
40 Correct 107 ms 12208 KB Output is correct
41 Correct 109 ms 12208 KB Output is correct
42 Correct 109 ms 12120 KB Output is correct