Submission #54324

# Submission time Handle Problem Language Result Execution time Memory
54324 2018-07-03T07:23:19 Z 노영훈(#1472) Flood (IOI07_flood) C++11
20 / 100
301 ms 12116 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, m;

struct node {
    int x, y, idx;
    pii to[4]; // r, u, l, d (ccw), (ver, eidx)
} P[MX];

map<int, int> Index;

struct edge {
    int u, v;
    int state; // 0: unvisited, 1: currently active, 2: will collapse, 3: will not collapse
} E[MX*2];

void vertex_input(){
    cin>>n;
    for(int i=1; i<=n; i++){
        int x, y; cin>>x>>y;
        P[i].x=x, P[i].y=y, P[i].idx=i;
    }
    sort(P+1, P+n+1, [](node &a, node &b){
        if(a.x==b.x) return a.y<b.y;
        return a.x<b.x;
    });
    for(int i=1; i<=n; i++)
        Index[P[i].idx]=i;
}

void edge_input(){
    cin>>m;
    for(int i=1, u, v; i<=m; i++){
        cin>>u>>v;
        u=Index[u], v=Index[v];
        E[i]={u,v,0};
        node &a=P[u], &b=P[v];
        if(a.x==b.x){
            if(a.y<b.y)
                a.to[1]=pii(v,i), b.to[3]=pii(u,i);
            if(a.y>b.y)
                a.to[3]=pii(v,i), b.to[1]=pii(u,i);
        }
        if(a.y==b.y){
            if(a.x<b.x)
                a.to[0]=pii(v,i), b.to[2]=pii(u,i);
            if(a.x>b.x)
                a.to[2]=pii(v,i), b.to[0]=pii(u,i);
        }
    }
}

bool valid(int x){
    for(int k=0; k<4; k++)
        if(E[P[x].to[k].second].state==0) return true;
    return false;
}

int found;
int dep[MX], now;
void dfs(int v, int dir){
    // cout<<P[v].x<<' '<<P[v].y<<'\n';
    dep[v]=++now;
    for(int kk=dir+1; kk<dir+4 + (dep[v]==0); kk++){
        int k=kk%4;
        int x,eidx; tie(x,eidx)=P[v].to[k];
        if(eidx==0 || E[eidx].state>=2){
            continue;
        }
        if(E[eidx].state==0){
            E[eidx].state=1;
            dfs(x, (k+2)%4);
            E[eidx].state=3;
        }
        else if(E[eidx].state==1){
            found=eidx;
            break;
        }
        if(found>0){
            E[eidx].state=2;
            if(found==eidx){
                found=-1;
            }
            else{
                break;
            }
        }
    }
    // cout<<'\n';
    now--;
}

void solve(){
    for(int i=1; i<=n; i++){
        if(!valid(i)) continue;
        found=-1;
        // cout<<"CYCLING\n";
        dfs(i, 3);
        // cout<<"DONE\n";
    }
}

void show(){
    int cnt=0;
    for(int i=1; i<=m; i++)
        if(E[i].state==3) cnt++;
    cout<<cnt<<'\n';
    for(int i=1; i<=m; i++)
        if(E[i].state==3)
            cout<<i<<'\n';
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    vertex_input();
    edge_input();
    solve();
    show();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4712 KB Output is correct
2 Correct 5 ms 4892 KB Output is correct
3 Correct 5 ms 4892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4892 KB Output is correct
2 Incorrect 5 ms 4892 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 6376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 11872 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 11872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 257 ms 11872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 12116 KB Output isn't correct
2 Halted 0 ms 0 KB -