35112023-02-28 14:27:42horvathabelRácsháló gráfcpp17Wrong answer 7/503ms3856 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> g[201]; 
int bfs(int x){
	vector<bool> seen;
	seen.assign(201, 0);
	int tav[201];
	int mx=0;
	tav[x]=0;
	queue<int> q;
	q.push(x);
	while (!q.empty()){
		int v=q.front();
		q.pop();
		seen[v]=true;
		for (int x:g[v]){
			if (!seen[x]){
				tav[x]=tav[v]+1; 
				seen[x]=true;
				mx=max(mx,tav[x]);
				q.push(x);
			}
		}


	}
	return (mx); 
}
int main() {
	int n, m, k;
	cin>>n>>m>>k;
	for (int i=1;i<=n*m;i++){
		if ((i%m==0 or i%m-1>0)  && i%m!=1){
			 g[i].push_back(i-1);
		}
		if (i%m+1<=m && i%m!=0){
			g[i].push_back(i+1);
		}
		if (i-m>0){
		 g[i].push_back(i-m);
		} 
		if (i+m<=n*m){
			g[i].push_back(i+m);
		}

		

	}
	for (int i=0; i<k;i++){
		int x,y;
		cin>>x>>y; 
		g[x].push_back(y);
		g[y].push_back(x);
		int ans=max(bfs(1), bfs(m));
		cout<<ans<<endl; 
	}

}
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/03ms1820 KiB
2Wrong answer0/03ms2212 KiB
3Accepted2/23ms2408 KiB
4Accepted2/23ms2560 KiB
5Wrong answer0/23ms2736 KiB
6Wrong answer0/23ms2916 KiB
7Wrong answer0/23ms3128 KiB
8Wrong answer0/23ms3204 KiB
9Wrong answer0/23ms3236 KiB
10Wrong answer0/23ms3400 KiB
11Wrong answer0/23ms3620 KiB
12Wrong answer0/23ms3748 KiB
13Wrong answer0/33ms3832 KiB
14Wrong answer0/33ms3840 KiB
15Wrong answer0/33ms3840 KiB
16Wrong answer0/33ms3832 KiB
17Accepted3/33ms3840 KiB
18Wrong answer0/33ms3856 KiB
19Wrong answer0/33ms3836 KiB
20Wrong answer0/33ms3828 KiB
21Wrong answer0/33ms3832 KiB
22Wrong answer0/33ms3840 KiB