Submission #129843

# Submission time Handle Problem Language Result Execution time Memory
129843 2019-07-13T10:32:38 Z khulegub Flood (IOI07_flood) C++14
100 / 100
113 ms 13040 KB
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long i64;
int xac = 0;
int n;
int w;
// bool dbg = 0;
pii to[100010][4];
bool path[100010];
int arr[4][4];
vector<int> uld;
vector<pair<pair<int, int> , int> > p;

int dfs(int u, int dir){
	if (path[u]) return u;
	path[u] = 1;
	for (int i = 0; i < 4; i++){
		int v = to[u][arr[dir][i]].xx;
		if (v != 0){
			to[u][arr[dir][i]].xx = 0;
			to[v][ (arr[dir][i] + 2) % 4 ].xx = 0;
			int tmp = dfs(v, arr[dir][i]);
			if (tmp != -1){
				if (tmp != u){
					path[u] = 0;
					return tmp;
				}
			}
			else{
				uld.pb(to[u][arr[dir][i]].yy);
			}
		}
	}
	path[u] = 0;
	return -1;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("in.txt", "r", stdin);
	cin >> n;
	for (int i = 0; i < 4; i++){
		arr[i][0] = (i + 1) % 4;
		arr[i][1] = i;
		arr[i][2] = (i + 3) % 4;
		arr[i][3] = (i + 2) % 4;
	}
	p.resize(n + 1);
	p[0] = mp(mp(-1,-1),-1);
	for (int i = 1, tx, ty; i <= n; i++){
		cin >> tx >> ty;
		p[i] = mp(mp(tx,ty), i);
	}
	cin >> w;
	for (int i = 1, a, b; i <= w; i++){
		cin >> a >> b;
		int dir, dx, dy;
		dx = p[b].xx.xx - p[a].xx.xx;
		dy = p[b].xx.yy - p[a].xx.yy;
		
		if (dx != 0){
			if (dx > 0) dir = 1;
			else dir = 3;
		}
		else{
			if (dy > 0) dir = 0;
			else dir = 2;
		}
		to[a][dir] = mp(b, i);
		to[b][(dir + 2) % 4] = mp(a, i);
	}
	sort(p.begin(), p.end());
	for (int i = 1; i <= n; i++){
		dfs(p[i].yy, 0);
	}
	cout << uld.size() << '\n';

	for (int a : uld){
		cout << a << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 6660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 5216 KB Output is correct
2 Correct 107 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 6392 KB Output is correct
2 Correct 113 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 6520 KB Output is correct
2 Correct 95 ms 13040 KB Output is correct