求帮忙卡常
查看原帖
求帮忙卡常
1023192
K_yuxiang_rose楼主2024/12/2 21:56

rt。最后一个subtask死活过不去,不知道为啥。

#include<bits/stdc++.h>
using namespace std;
vector<int> v[1000005];
int f[1000005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n,m,r;
	cin>>n>>m>>r;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	queue<int> q;
	q.push(r);
	while(!q.empty())
	{
		int t=q.front(); q.pop();
		for(auto x:v[t])
		{
			if(!f[x]&&x!=r)
			{
				f[x]=f[t]+1;
				q.push(x);
			}
		} 
	}
	int qu;
	cin>>qu;
	cout<<"I'm here!"<<endl;
	while(qu--)
	{
		int a,b;
		cin>>a>>b;
		if(f[a]<=f[b]) cout<<"Terry"<<endl;
		else cout<<"Jom"<<endl;
	}
	return 0;
}
2024/12/2 21:56
加载中...