제출 #2882

#제출 시각아이디문제언어결과실행 시간메모리
2882cki86201간선 파괴 (GA5_destroy)C++98
25 / 100
2500 ms2668 KiB
#include<stdio.h>
#include<vector>
using namespace std;

//for 60point code;

struct line{
	line(){}
	line(int en,int c):en(en),c(c){}
	int en,c;
};
vector <line> edge[550];
int V,E,r,l,q;
int check[550];

void DFS(int x)
{
	check[x]=q+1;
	int i;
	for(i=0;i<edge[x].size();i++){
		if(check[edge[x][i].en]==q+1)continue;
		if(edge[x][i].c>=l&&edge[x][i].c<=r)continue;
		DFS(edge[x][i].en);
	}
}

void solve()
{
	int i,ret=0;
	for(i=1;i<=V;i++){
		if(check[i]!=q+1){ret++;DFS(i);}
	}
	printf("%d\n",ret);
}

int main()
{
	scanf("%d%d",&V,&E);
	int i;
	for(i=1;i<=E;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		edge[x].push_back(line(y,i));
		edge[y].push_back(line(x,i));
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&l,&r);
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...