제출 #582524

#제출 시각아이디문제언어결과실행 시간메모리
5825248e7통행료 (IOI18_highway)C++17
100 / 100
323 ms19676 KiB
#include "highway.h"
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<pii> adj[maxn], g[maxn];

ll mind;
vector<int> tmp;
int ord[maxn];
void dfs(int n, int par, int &cur, int lim) {
	ord[n] = ++cur;	
	if (cur > lim) return;
	for (auto [v, id]:adj[n]) {
		//debug(n, v);
		if (v != par && cur + 1 <= lim) {
			tmp[id] = 0;
			//debug("edge", n, v);
			dfs(v, n, cur, lim);
			if (cur > lim) return;
		} 
	}
}

int m, edges;

int type = 0;
int getind(int n, int root, vector<int> poss, vector<int> ed) {
	int low = 0, up = poss.size();
	tmp.resize(m, 0);	
	dfs(root, -1,low, 1<<30); 
	sort(poss.begin(), poss.end(), [&] (int x, int y){return ord[x] < ord[y];});
	pary(poss.begin(), poss.end());
	low = -1;
	while (low < up - 1) {
		int mid = (low + up) / 2;
		for (int i = 0;i < m;i++) tmp[i] = 1;
		for (int i:ed) tmp[i] = 0;
		int ini = 0;
		debug(poss[mid], ord[poss[mid]]);
		dfs(root, -1, ini, ord[poss[mid]]);
		pary(tmp.begin(), tmp.end());
		ll val = ask(tmp);
		if (val == mind) {
			up = mid;	
		} else {
			low = mid;
		}
	}
	debug(poss.size(), up, poss[up]);
	return poss[up];
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	int M = U.size();
	m = M;

	vector<int> ini(M, 0);
	mind = ask(ini);
	edges = mind / A;
	int low = 0, up = M;	
	while (low < up - 1) {
		int mid = (low + up) / 2;
		for (int i = 0;i < M;i++) {
			if (i < mid) ini[i] = 0;
			else ini[i] = 1;
		}
		if (ask(ini) == mind) {
			up = mid;
		} else {
			low = mid;
		}
	}

	for (int i = 0;i < M;i++) {
		g[U[i]].push_back({V[i], i});
		g[V[i]].push_back({U[i], i});
	}

	//debug(low, U[low], V[low]);
	vector<bool> vis(N, 0), from(N, 0);
	int root = U[low];	
	queue<int> que;
	que.push(root);
	que.push(V[low]);
	vis[root] = 1, vis[V[low]] = 1;
	from[V[low]] = 1;

	vector<int> su, sv, eu, ev;
	eu.push_back(low), ev.push_back(low);
	while (que.size()) {
		int cur = que.front();que.pop();
		vis[cur] = 1;
		if (from[cur]) sv.push_back(cur);
		else su.push_back(cur);

		for (auto [v, id]:g[cur]) {
			if (!vis[v]) {
				vis[v] = 1;
				from[v] = from[cur];
				adj[cur].push_back({v, id});
				adj[v].push_back({cur, id});
				if (from[cur]) ev.push_back(id);
				else eu.push_back(id);
				que.push(v);
			}
		}
	}

	//pary(su.begin(), su.end());
	//pary(sv.begin(), sv.end());
	int s = getind(N, root, su, ev);
	int t = getind(N, V[low], sv, eu);
	debug(s, t);
	answer(s, t);
}
/*
4 3 5 8 1 3
0 1
0 2
1 3
*/

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'int getind(int, int, std::vector<int>, std::vector<int>)':
highway.cpp:14:19: warning: statement has no effect [-Wunused-value]
   14 | #define pary(...) 0
      |                   ^
highway.cpp:49:2: note: in expansion of macro 'pary'
   49 |  pary(poss.begin(), poss.end());
      |  ^~~~
highway.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
highway.cpp:56:3: note: in expansion of macro 'debug'
   56 |   debug(poss[mid], ord[poss[mid]]);
      |   ^~~~~
highway.cpp:14:19: warning: statement has no effect [-Wunused-value]
   14 | #define pary(...) 0
      |                   ^
highway.cpp:58:3: note: in expansion of macro 'pary'
   58 |   pary(tmp.begin(), tmp.end());
      |   ^~~~
highway.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
highway.cpp:66:2: note: in expansion of macro 'debug'
   66 |  debug(poss.size(), up, poss[up]);
      |  ^~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
highway.cpp:130:2: note: in expansion of macro 'debug'
  130 |  debug(s, t);
      |  ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...