# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128054 |
2019-07-10T11:22:28 Z |
khulegub |
Flood (IOI07_flood) |
C++14 |
|
344 ms |
13072 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
using namespace std;
typedef pair<int, int> pii;
vector<vector<int> > to;
vector<pii> p;
int n;
int w;
int uld;
bool path[100010];
bool vis[100010];
void mark (int u){
vis[u] = 1;
for (int i = 0; i < 4; i++){
if(to[u][i] != 0 && !vis[to[u][i]] ){
mark (to[u][i]);
}
}
}
int dfs (int u, int pre, int dir){
// cout << u << ": ";
if (path[u]) return u; // ustga >:(
path[u] = 1;
int arr[4];
arr[0] = (dir + 1) % 4;
arr[1] = dir;
arr[2] = (dir + 3) % 4;
arr[3] = (dir + 2) % 4;
for (int i = 0; i < 4; i++){
if (dir != 0 && i == 3) continue;
if (to[u][arr[i]] != 0 && to[u][arr[i]] != pre){
// if(u == 1) cout << to[u][arr[i]] << ' ';
// cout << to[u][arr[i]] << '>';
int tmp = dfs(to[u][arr[i]], u, arr[i]);
if(tmp != -1){
uld--;
to[ to[u][arr[i]] ][ (arr[i] + 2) % 4 ] = 0;
to[u][arr[i]] = 0;
if(tmp != u) return tmp;
// HUBCoworking
}
// cout << " < ";
}
}
path[u] = 0;
// cout << u << ' ';
return -1;
}
// bool
int main() {
// freopen("in2.txt", "r", stdin);
cin >> n;
to.resize(n + 1, vector<int>(4) );
p.resize(n + 1);
vector<pii> wll;
for (int i = 1, tx, ty; i <= n; i++){
cin >> tx >> ty;
p[i] = mp(tx, ty);
}
cin >> w;
uld = w;
wll.resize(w + 1);
// cout << to[1].size();
for (int i = 1, a, b; i <= w; i++){
cin >> a >> b;
int dx = p[b].xx - p[a].xx, dy = p[b].yy - p[a].yy;
if(dy == 0){
if(dx > 0){ // b ni a giin baruun tald
to[a][1] = b;
wll[i] = mp(a,1);
to[b][3] = a;
}
else{
to[a][3] = b;
wll[i] = mp(a,3);
to[b][1] = a;
}
}
else if(dx == 0){
if(dy > 0){ // b ni a giin deed tald
to[a][0] = b;
wll[i] = mp(a,0);
to[b][2] = a;
}
else{
to[a][2] = b;
wll[i] = mp(a,2);
to[b][0] = a;
}
}
}
// cout << to[1][];
memset(vis, 0, sizeof vis);
for (int i = 1; i <= n; i++){
// cout << i << ' ';
if(!vis[i]){
dfs(i, i, 0);
mark(i);
}
}
cout << uld << '\n';
for(int i = 1; i <= w; i++){
if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << i << '\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 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
2692 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
11056 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
9136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
315 ms |
11516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
344 ms |
13072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |