提出 #68164887


ソースコード 拡げる

#include<fstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<cmath>
#include<numbers>
#include<algorithm>
#include<string>
#include<set>
#include<stack>
#include<random>
#include<bitset>
#include<cassert>
#include<exception>

using namespace std;
using ll=long long;
using uset=unordered_set<long long>;

int H,W;
vector<string> strs;

struct point{
	int x,y;
	point():x(0),y(0){}
	point(int x,int y):x(x),y(y){}

	point operator+(const point& a){
		return point(a.x+x,a.y+y);
	}
	bool rangeCheck(){
		return 0<=x&&x<W&&0<=y&&y<H;
	}
	bool mapCheck(){
		return rangeCheck()&&strs[y][x]=='.';
	}
	bool operator<(const point& a)const{
		if(x!=a.x)return x<a.x;
		return y<a.y;
	}
};

template<typename T>
bool chmax(T& a,const T& b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<typename T>
bool chmin(T& a,const T& b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

int main(){
	vector<vector<int>> aans;
	int T;
	cin>>T;

	while(T--){
		int N,M,X,Y;
		cin>>N>>M>>X>>Y;
		X--;Y--;
		
		vector graph(N,vector<int>());
		for(int i=0;i<M;i++){
			int a,b;
			cin>>a>>b;
			a--;b--;
			graph[a].push_back(b);
			graph[b].push_back(a);
		}
		for(int i=0;i<N;i++){
			sort(graph[i].rbegin(),graph[i].rend());
		}

		stack<point> st;
		vector<int> visited(N, -32915);
		st.push({X,-1});

		while(!st.empty()){
			auto v=st.top();
			st.pop();
			if(visited[v.x]!=-32915)continue;
			visited[v.x]=v.y;

			if(v.x==Y){
				break;
			}	
			
			for(int u:graph[v.x]){
				if(visited[u]==-32915){
					st.push({u,v.x});
				}
			}
		}
		vector<int> ans;
		int t=Y;
		while(t!=-1){
			ans.push_back(t+1);
			t=visited[t];
		}

		reverse(ans.begin(), ans.end());
		aans.push_back(ans);
	}

	for(auto& v:aans){
		for(auto & i:v){
			cout<<i<<" ";
		}
		cout<<endl;
	}

	return 0;
}

提出情報

提出日時
問題 E - A Path in A Dictionary
ユーザ Satsuki15
言語 C++ 20 (gcc 12.2)
得点 475
コード長 2011 Byte
結果 AC
実行時間 17 ms
メモリ 4728 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 1
AC × 43
セット名 テストケース
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3468 KiB
hand_00.txt AC 16 ms 4520 KiB
hand_01.txt AC 1 ms 3484 KiB
hand_02.txt AC 16 ms 4540 KiB
hand_03.txt AC 1 ms 3540 KiB
hand_04.txt AC 13 ms 3660 KiB
hand_05.txt AC 16 ms 4664 KiB
hand_06.txt AC 17 ms 4576 KiB
hand_07.txt AC 1 ms 3608 KiB
hand_08.txt AC 14 ms 4280 KiB
hand_09.txt AC 15 ms 4392 KiB
hand_10.txt AC 2 ms 3640 KiB
hand_11.txt AC 2 ms 3580 KiB
random_00.txt AC 1 ms 3556 KiB
random_01.txt AC 1 ms 3616 KiB
random_02.txt AC 2 ms 3644 KiB
random_03.txt AC 2 ms 3564 KiB
random_04.txt AC 2 ms 3484 KiB
random_05.txt AC 3 ms 3700 KiB
random_06.txt AC 1 ms 3504 KiB
random_07.txt AC 1 ms 3660 KiB
random_08.txt AC 2 ms 3548 KiB
random_09.txt AC 4 ms 3532 KiB
random_10.txt AC 6 ms 3528 KiB
random_11.txt AC 7 ms 3576 KiB
random_12.txt AC 1 ms 3420 KiB
random_13.txt AC 1 ms 3684 KiB
random_14.txt AC 2 ms 3520 KiB
random_15.txt AC 7 ms 3696 KiB
random_16.txt AC 10 ms 3688 KiB
random_17.txt AC 14 ms 3668 KiB
random_18.txt AC 1 ms 3572 KiB
random_19.txt AC 1 ms 3488 KiB
random_20.txt AC 15 ms 4380 KiB
random_21.txt AC 3 ms 3576 KiB
random_22.txt AC 15 ms 4248 KiB
random_23.txt AC 16 ms 4564 KiB
random_24.txt AC 1 ms 3592 KiB
random_25.txt AC 1 ms 3580 KiB
random_26.txt AC 16 ms 4428 KiB
random_27.txt AC 16 ms 4500 KiB
random_28.txt AC 16 ms 4648 KiB
random_29.txt AC 16 ms 4728 KiB