Submission #7897

# Submission time Handle Problem Language Result Execution time Memory
7897 2014-08-24T02:30:10 Z gs14004 간선 파괴 (GA5_destroy) C++
0 / 100
2500 ms 2752 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

typedef pair<int,int> pi;
vector<pi> graph[707];
int p[10005], r[10005];
    
void init(int n){
    memset(r,0,sizeof(r));
    for (int i=1; i<=n; i++) {
        p[i] = i;
    }
}
int find(int x){
    if(p[x] == x) return x;
    else return p[x] = find(p[x]);
}
void uni(int x, int y){
    x = find(x);
    y = find(y);
    if(r[x] < r[y]) p[y] = x;
    else p[x] = y;
    if(r[x] == r[y]) r[x]++;
}

int n,m;

void query(int p, int q){
    int v[707] = {};
    init(n);
    for (int i=1; i<=n; i++) {
        if(v[find(i)]) continue;
        for (int j=0; j<graph[i].size(); j++) {
            if(graph[i][j].second < p || graph[i][j].second > q){
                if (find(i) != find(graph[i][j].first)) {
                    uni(i,graph[i][j].first);
                    v[find(graph[i][j].first)] = 1;
                }
            }
        }
    }
    memset(v,0,sizeof(v));
    int r = 0;
    for (int i=1; i<=n; i++) {
        if(v[find(i)] == 0){
            v[find(i)] = 1;
            r++;
        }
    }
    printf("%d\n",r);
}

int main(){
    int x,y,q;
    scanf("%d %d",&n,&m);
    for (int i=0; i<m; i++) {
        scanf("%d %d",&x,&y);
        if(x>y) swap(x,y);
        graph[x].push_back(pi(y,i+1));
        graph[y].push_back(pi(x,i+1));
    }
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        scanf("%d %d",&x,&y);
        query(x,y);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 1564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2500 ms 2752 KB Program timed out
2 Halted 0 ms 0 KB -