107272024-04-10 19:50:32111Útvonalakcpp17Runtime error 0/100187ms84688 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("ki.txt","w",stdout);
#endif
	int N,M,K;
	cin>>N>>M>>K;
	vector<vector<int>>g(N+1);
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int>v(N+1),w(N+1),p(N+1),a(N+1);
	vector<vector<int>>c(N+1),cc;
	auto dfs=[&](auto self,int i)->unordered_set<int>{
		unordered_set<int>s;
		w[i]=v[i];
		for(int j:g[i]){
			if(j==p[i]){
				continue;
			}
			if(v[j]){
				if(v[j]<v[i]){
					w[i]=min(w[i],v[j]);
				}
				continue;
			}
			v[j]=v[i]+1;
			p[j]=i;
			auto z=self(self,j);
			if(w[j]>=v[i]){
				a[i]=1;
				z.insert(i);
				for(int k:z){
					c[k].push_back(cc.size());
				}
				cc.emplace_back(z.begin(),z.end());
			}
			else{
				w[i]=min(w[i],w[j]);
				if(s.size()<z.size()){
					swap(s,z);
				}
				s.insert(z.begin(),z.end());
			}
		}
		s.insert(i);
		return s;
	};
	v[1]=1;
	dfs(dfs,1);
	return 1;
	vector<vector<int>>q(N+1);
	for(int i=0;i<K;i++){
		int a,b;
		cin>>a>>b;
		q[a].push_back(i);
		q[b].push_back(i);
	}
	vector<int>ans(K,-1);
	auto dfs2=[&](auto self,int i,int p)->unordered_map<int,int>{
		unordered_map<int,int>s;
		for(int x:q[i]){
			s[x]=0;
		}
		for(int j:c[i]){
			if(j==p){
				continue;
			}
			unordered_map<int,int>t;
			for(int k:cc[j]){
				if(k==i||!a[k]){
					continue;
				}
				auto z=self(self,k,j);
				if(t.size()<z.size()){
					swap(t,z);
				}
				for(auto[x,y]:z){
					if(t.count(x)){
						ans[x]=t[x]+y+cc[j].size();
						t.erase(x);
					}
					else{
						t[x]=y;
					}
				}
			}
			for(int k:cc[j]){
				if(k==i||a[k]){
					continue;
				}
				for(int x:q[k]){
					if(t.count(x)){
						ans[x]=t[x]+cc[j].size();
						t.erase(x);
					}
					else{
						t[x]=0;
					}
				}
			}
			for(auto[x,y]:t){
				if(s.count(x)){
					ans[x]=s[x]+y+cc[j].size();
					s.erase(x);
				}
				else{
					s[x]=y+cc[j].size()-1;
				}
			}
		}
		return s;
	};
	dfs2(dfs2,1,-1);
	for(int i:ans){
		cout<<i-2<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1976 KiB
2Runtime error158ms42528 KiB
subtask20/15
3Runtime error4ms2856 KiB
4Runtime error4ms3412 KiB
5Runtime error7ms5512 KiB
6Runtime error14ms6576 KiB
7Runtime error74ms22840 KiB
8Runtime error180ms43168 KiB
subtask30/15
9Runtime error4ms3460 KiB
10Runtime error4ms3928 KiB
11Runtime error7ms5944 KiB
12Runtime error12ms7252 KiB
13Runtime error56ms23904 KiB
14Runtime error134ms45016 KiB
15Runtime error145ms69204 KiB
subtask40/15
16Runtime error4ms4488 KiB
17Runtime error7ms5156 KiB
18Runtime error14ms7356 KiB
19Runtime error76ms23512 KiB
20Runtime error180ms43992 KiB
subtask50/15
21Runtime error3ms3516 KiB
22Runtime error3ms3872 KiB
23Runtime error4ms4664 KiB
24Runtime error3ms4004 KiB
25Runtime error4ms4368 KiB
26Runtime error4ms4232 KiB
subtask60/40
27Runtime error3ms3832 KiB
28Runtime error177ms44040 KiB
29Runtime error4ms2856 KiB
30Runtime error4ms3412 KiB
31Runtime error7ms5512 KiB
32Runtime error14ms6576 KiB
33Runtime error74ms22840 KiB
34Runtime error180ms43168 KiB
35Runtime error4ms3460 KiB
36Runtime error4ms3928 KiB
37Runtime error7ms5944 KiB
38Runtime error12ms7252 KiB
39Runtime error56ms23904 KiB
40Runtime error134ms45016 KiB
41Runtime error145ms69204 KiB
42Runtime error4ms4488 KiB
43Runtime error7ms5156 KiB
44Runtime error14ms7356 KiB
45Runtime error76ms23512 KiB
46Runtime error180ms43992 KiB
47Runtime error3ms3516 KiB
48Runtime error3ms3872 KiB
49Runtime error4ms4664 KiB
50Runtime error3ms4004 KiB
51Runtime error4ms4368 KiB
52Runtime error4ms4232 KiB
53Runtime error149ms76460 KiB
54Runtime error4ms4636 KiB
55Runtime error7ms6852 KiB
56Runtime error14ms8012 KiB
57Runtime error78ms24148 KiB
58Runtime error93ms27436 KiB
59Runtime error125ms84688 KiB
60Runtime error187ms44928 KiB
61Runtime error167ms42700 KiB
62Runtime error158ms42692 KiB