# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
129597 |
2019-07-12T18:06:01 Z |
khulegub |
Flood (IOI07_flood) |
C++14 |
|
293 ms |
7676 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;
bool vis[100005];
int to[100005][4];
bool path[100005];
vector<pii> p;
vector<pii> wll;
void mark(int u){
vis[u] = 1;
for (int i = 0; i < 4; i++){
if (to[u][i] != 0 and !vis[to[u][i]]){
mark( to[u][i] );
}
}
}
int dfs(int u, int dir){
if (path[u]) return u;
// if (dbg and u == 4) cout << dir;
path[u] = 1;
if (dir == -1){ //init
for (int i = 0; i < 4; i++){
int v = to[u][i];
if (v != 0){
int tmp = dfs(v, i);
if (tmp != -1){
to[u][i] = 0;
to[v][ (i + 2) % 4 ] = 0;
xac++;
if (tmp != u){
path[u] = 0;
return tmp;
}
}
}
}
}
else{
int arr[3];
arr[0] = (dir + 1) % 4;
arr[1] = dir;
arr[2] = (dir + 3) % 4;
for (int i = 0; i < 3; i++){
int v = to[u][arr[i]];
if (v != 0){
int tmp = dfs(v, arr[i]);
if (tmp != -1){
to[u][arr[i]] = 0;
to[v][ (arr[i] + 2) % 4 ] = 0;
xac++;
if (tmp != u){
path[u] = 0;
return tmp;
}
}
}
}
}
path[u] = 0;
return -1;
}
int main(){
// freopen("in.txt", "r", stdin);
cin >> n;
p.resize(n + 1);
for (int i = 1, tx, ty; i <= n; i++){
cin >> tx >> ty;
p[i] = mp(tx, ty);
}
cin >> w;
wll.resize(w + 1);
// 0 top
// 1 baruun
// 2 bot
// 3 zuun
for (int i = 1, a, b; i <= w; i++){
cin >> a >> b;
int dx = p[b].xx - p[a].xx;
int dy = p[b].yy - p[a].yy;
int dir;
if (dx != 0){ // horizontal
if (dx > 0){ // a b
to[a][1] = b;
to[b][3] = a;
dir = 1;
}
else { // b a
to[a][3] = b;
to[b][1] = a;
dir = 3;
}
}
else{ //vert
if (dy > 0){ // b ni deer
to[a][0] = b;
to[b][2] = a;
dir = 0;
}
else{
to[a][2] = b;
to[b][0] = a;
dir = 2;
}
}
wll[i] = mp(a, dir);
}
for (int i = 1; i <= n; i++){
if (!vis[i]){
// if (i == 4) dbg = 1;
dfs(i, -1);
mark(i);
// if (i == 4) dbg = 0;
// cout << i << '&' << vis[11] << ' ';
// break;
}
}
// cout << "##################\n";
cout << w - xac << '\n';
for (int i = 1; i <= w; i++){
if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << i << '\n';
// if ( to[wll[i].xx][wll[i].yy] != 0 ) cout << wll[i].xx << ' ' << to[wll[i].xx][wll[i].yy] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 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 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
1696 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
186 ms |
7672 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
5624 KB |
Output is correct |
2 |
Incorrect |
293 ms |
7676 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
265 ms |
7000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
288 ms |
7520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |