답안 #349168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349168 2021-01-16T20:57:39 Z Kerim 통행료 (IOI18_highway) C++17
100 / 100
336 ms 20048 KB
#include "highway.h"
#include "bits/stdc++.h"
#define MAXN 130009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int M,N;
PII edge[MAXN];
vector<int>A,B,AA,BB;
vector<PII>adj[MAXN],gr[MAXN];
int col[MAXN];
void dfs(int nd,int pr){
	tr(it,gr[nd])
		if(it->ff!=pr){
			col[it->ss]=1;
			dfs(it->ff,nd);
		}
}
void find_pair(int N, vector<int> U, vector<int> V, int a, int b) {
  	M=U.size();::N=N;
  	for(int i=0;i<M;i++)
  		edge[i]=mp(U[i],V[i]);
	vector<int>w(M,0),ans;
	ll dis=ask(w);
	int low=0,high=M-1;
	while(low<high){
		int mid=(low+high)>>1;
		for(int i=0;i<M;i++)
			w[i]=(i>mid);
		if(ask(w)==dis)high=mid;
		else low=mid+1;
	}PII v=edge[low];
	for(int i=0;i<M;i++){
		w[i]=1;
		gr[edge[i].ff].pb(mp(edge[i].ss,i));
		gr[edge[i].ss].pb(mp(edge[i].ff,i));
	}
	queue<int>p;
	vector<int>d(N,INF);
	p.push(v.ff);d[v.ff]=0;
	p.push(v.ss);d[v.ss]=0;
	while(!p.empty()){
		int nd=p.front();p.pop();
		tr(it,gr[nd])
			if(umin(d[it->ff],d[nd]+1))
				w[it->ss]=0,p.push(it->ff);	
	}
	for(int i=0;i<N;i++)gr[i].clear();
	int ban=-1;
	for(int i=0;i<M;i++){
		if(edge[i]==v)ban=i,w[i]=0;
		if(!w[i]){
			gr[edge[i].ff].pb(mp(edge[i].ss,i));
			gr[edge[i].ss].pb(mp(edge[i].ff,i));
		}
		else
			col[i]=2;	
	}
	dfs(v.ss,v.ff);
	for(int j=0;j<2;j++){
		for(int i=0;i<N;i++)adj[i].clear();
		vector<int>vis(N,0);
		int s=v.ff,tmp=0;if(j)s=v.ss;
		vector<int>id(N),par(M);
		for(int i=0;i<M;i++){
			if(i!=ban and col[i]==j){
				adj[edge[i].ff].pb(mp(edge[i].ss,i));
				adj[edge[i].ss].pb(mp(edge[i].ff,i));
			}
			if(col[i]==2)w[i]=1;
			else w[i]=0;
		}
		queue<int>q;q.push(s);vis[s]=1;
		while(!q.empty()){
			int nd=q.front();q.pop();
			tr(it,adj[nd])
				if(!vis[it->ff]){
					id[tmp++]=it->ss;par[it->ss]=it->ff;
					vis[it->ff]=1;q.push(it->ff);	
				}
		}
		int st=-1,en=tmp-1;
		while(st<en){
			int mid=(st+en+1)>>1;
			for(int i=0;i<tmp;i++)
				w[id[i]]=(i>=mid);
			if(ask(w)==dis)en=mid-1;
			else st=mid;
		}
		if(st==-1)
			ans.pb(s);
		else
			ans.pb(par[id[st]]);
	}
	answer(ans[0],ans[1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6508 KB Output is correct
2 Correct 5 ms 6508 KB Output is correct
3 Correct 6 ms 6532 KB Output is correct
4 Correct 5 ms 6508 KB Output is correct
5 Correct 5 ms 6508 KB Output is correct
6 Correct 5 ms 6508 KB Output is correct
7 Correct 5 ms 6500 KB Output is correct
8 Correct 5 ms 6500 KB Output is correct
9 Correct 5 ms 6656 KB Output is correct
10 Correct 5 ms 6508 KB Output is correct
11 Correct 5 ms 6508 KB Output is correct
12 Correct 5 ms 6508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6532 KB Output is correct
2 Correct 15 ms 7684 KB Output is correct
3 Correct 230 ms 17488 KB Output is correct
4 Correct 188 ms 17528 KB Output is correct
5 Correct 194 ms 17532 KB Output is correct
6 Correct 169 ms 17336 KB Output is correct
7 Correct 175 ms 17524 KB Output is correct
8 Correct 182 ms 17544 KB Output is correct
9 Correct 194 ms 17512 KB Output is correct
10 Correct 235 ms 17448 KB Output is correct
11 Correct 229 ms 17332 KB Output is correct
12 Correct 177 ms 17864 KB Output is correct
13 Correct 195 ms 16592 KB Output is correct
14 Correct 217 ms 16560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7916 KB Output is correct
2 Correct 42 ms 9264 KB Output is correct
3 Correct 52 ms 9780 KB Output is correct
4 Correct 144 ms 17996 KB Output is correct
5 Correct 141 ms 18880 KB Output is correct
6 Correct 158 ms 16668 KB Output is correct
7 Correct 133 ms 16132 KB Output is correct
8 Correct 141 ms 17588 KB Output is correct
9 Correct 131 ms 17040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6508 KB Output is correct
2 Correct 21 ms 7660 KB Output is correct
3 Correct 130 ms 15260 KB Output is correct
4 Correct 190 ms 17476 KB Output is correct
5 Correct 167 ms 17428 KB Output is correct
6 Correct 196 ms 17176 KB Output is correct
7 Correct 204 ms 17184 KB Output is correct
8 Correct 231 ms 17184 KB Output is correct
9 Correct 180 ms 17492 KB Output is correct
10 Correct 180 ms 17200 KB Output is correct
11 Correct 197 ms 17216 KB Output is correct
12 Correct 179 ms 16696 KB Output is correct
13 Correct 202 ms 16912 KB Output is correct
14 Correct 176 ms 17568 KB Output is correct
15 Correct 181 ms 17528 KB Output is correct
16 Correct 184 ms 17540 KB Output is correct
17 Correct 194 ms 17428 KB Output is correct
18 Correct 252 ms 17556 KB Output is correct
19 Correct 181 ms 17208 KB Output is correct
20 Correct 190 ms 18040 KB Output is correct
21 Correct 148 ms 18172 KB Output is correct
22 Correct 147 ms 17884 KB Output is correct
23 Correct 155 ms 17968 KB Output is correct
24 Correct 178 ms 18088 KB Output is correct
25 Correct 184 ms 16692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7660 KB Output is correct
2 Correct 30 ms 7788 KB Output is correct
3 Correct 221 ms 18060 KB Output is correct
4 Correct 269 ms 18556 KB Output is correct
5 Correct 261 ms 19592 KB Output is correct
6 Correct 253 ms 19576 KB Output is correct
7 Correct 329 ms 19548 KB Output is correct
8 Correct 333 ms 19564 KB Output is correct
9 Correct 187 ms 15532 KB Output is correct
10 Correct 221 ms 15740 KB Output is correct
11 Correct 245 ms 16676 KB Output is correct
12 Correct 284 ms 18376 KB Output is correct
13 Correct 258 ms 18936 KB Output is correct
14 Correct 329 ms 19404 KB Output is correct
15 Correct 336 ms 19312 KB Output is correct
16 Correct 219 ms 16560 KB Output is correct
17 Correct 182 ms 18200 KB Output is correct
18 Correct 168 ms 18676 KB Output is correct
19 Correct 214 ms 18304 KB Output is correct
20 Correct 229 ms 18640 KB Output is correct
21 Correct 321 ms 19720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7660 KB Output is correct
2 Correct 26 ms 7788 KB Output is correct
3 Correct 200 ms 18116 KB Output is correct
4 Correct 229 ms 18264 KB Output is correct
5 Correct 274 ms 18460 KB Output is correct
6 Correct 315 ms 19604 KB Output is correct
7 Correct 213 ms 18136 KB Output is correct
8 Correct 219 ms 18276 KB Output is correct
9 Correct 231 ms 18560 KB Output is correct
10 Correct 248 ms 19764 KB Output is correct
11 Correct 266 ms 19572 KB Output is correct
12 Correct 253 ms 19532 KB Output is correct
13 Correct 242 ms 16768 KB Output is correct
14 Correct 176 ms 15748 KB Output is correct
15 Correct 189 ms 16720 KB Output is correct
16 Correct 191 ms 15864 KB Output is correct
17 Correct 189 ms 16820 KB Output is correct
18 Correct 170 ms 15832 KB Output is correct
19 Correct 285 ms 18340 KB Output is correct
20 Correct 253 ms 19024 KB Output is correct
21 Correct 318 ms 19376 KB Output is correct
22 Correct 264 ms 19456 KB Output is correct
23 Correct 288 ms 19352 KB Output is correct
24 Correct 310 ms 19364 KB Output is correct
25 Correct 264 ms 19588 KB Output is correct
26 Correct 269 ms 19460 KB Output is correct
27 Correct 159 ms 18584 KB Output is correct
28 Correct 206 ms 18448 KB Output is correct
29 Correct 175 ms 18784 KB Output is correct
30 Correct 212 ms 18572 KB Output is correct
31 Correct 162 ms 18376 KB Output is correct
32 Correct 187 ms 18136 KB Output is correct
33 Correct 197 ms 18860 KB Output is correct
34 Correct 205 ms 18648 KB Output is correct
35 Correct 155 ms 18404 KB Output is correct
36 Correct 204 ms 18232 KB Output is correct
37 Correct 213 ms 18712 KB Output is correct
38 Correct 166 ms 18496 KB Output is correct
39 Correct 264 ms 19960 KB Output is correct
40 Correct 275 ms 20048 KB Output is correct
41 Correct 303 ms 19660 KB Output is correct
42 Correct 323 ms 19576 KB Output is correct