提出 #68169694


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T> v){for(auto i:v)O<<i<<' ';return O;}
string TMP,STR;
stringstream CIN;
void read_all(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef debug
	cerr<<"----------------------------------- START -----------------------------------\n";
	while(getline(cin,TMP))STR+=TMP,STR+='\n';
	CIN.str(STR);
	cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
#endif
}
#ifdef debug
#define cin CIN
#endif
namespace AC{
int n,m,x,y;
vector<int>g[1010];
bool vis[1010];
int vis2[1010];
int ans[1010],cnt;
bool ed=0;
bool can[1010][1010];
void dfs(){
	int u=ans[cnt-1];
	if(vis[u])return;
	vis[u]=1;
	if(vis2[u])return;
	if(u==y){
		for(int i=0;i<cnt;i++)cout<<ans[i]<<' ';
		cout<<'\n';
		ed=1;
		return;
	}
	for(auto v:g[u])if(can[u][v]){
		ans[cnt++]=v;
		dfs();
		cnt--;
		if(ed)return;
	}
	else vis2[v]++;
	for(auto v:g[u])if(!can[u][v])vis2[v]--;
	vis[u]=0;
}
void init(int x,int u){
	if(can[x][u])return;
	if(u==x)return;
	can[x][u]=1;
	for(auto v:g[u])init(x,v);
}
void solve(){
	ed=0;
	cin>>n>>m>>x>>y;
	for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)can[i][j]=0;
	for(int i=0;i<1010;i++)g[i].clear(),vis[i]=0,vis2[i]=0;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		init(i,y);
	}
	for(int i=1;i<=n;i++)sort(all(g[i]));
	cnt=0;
	ans[cnt++]=x;
	dfs();
}
}
bool ed;
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	chrono::steady_clock::time_point St=chrono::steady_clock::now();
	read_all();
	chrono::steady_clock::time_point ST=chrono::steady_clock::now();
	int t=1;
	cin>>t;
	while(t--)AC::solve();
	chrono::steady_clock::time_point ED=chrono::steady_clock::now();
	cerr<<setprecision(3)<<fixed<<"\n\n------------------------------------ END ------------------------------------\n"<<"Total Time   : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-St).count()<<" \tms\n"<<"Real  Time   : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-ST).count()<<" \tms\n"<<"             : "<<left<<setw(10)<<chrono::duration_cast<chrono::microseconds>(ED-ST).count()<<" \tμs\n\n"<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<"               "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<"               "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
}

提出情報

提出日時
問題 E - A Path in A Dictionary
ユーザ gunuozhang
言語 C++ 20 (gcc 12.2)
得点 0
コード長 2715 Byte
結果 TLE
実行時間 2207 ms
メモリ 6384 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 475
結果
AC × 1
AC × 42
TLE × 1
セット名 テストケース
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 3848 KiB
hand_00.txt AC 31 ms 5132 KiB
hand_01.txt AC 8 ms 4920 KiB
hand_02.txt AC 31 ms 5416 KiB
hand_03.txt AC 8 ms 5020 KiB
hand_04.txt AC 15 ms 4072 KiB
hand_05.txt AC 85 ms 6216 KiB
hand_06.txt AC 82 ms 5952 KiB
hand_07.txt AC 5 ms 4836 KiB
hand_08.txt AC 88 ms 6024 KiB
hand_09.txt AC 89 ms 6076 KiB
hand_10.txt AC 17 ms 5040 KiB
hand_11.txt AC 1 ms 3780 KiB
random_00.txt AC 1 ms 3848 KiB
random_01.txt AC 2 ms 3804 KiB
random_02.txt AC 2 ms 3856 KiB
random_03.txt AC 2 ms 3852 KiB
random_04.txt AC 2 ms 3744 KiB
random_05.txt AC 2 ms 3728 KiB
random_06.txt AC 2 ms 3848 KiB
random_07.txt AC 5 ms 3884 KiB
random_08.txt TLE 2207 ms 3416 KiB
random_09.txt AC 4 ms 3820 KiB
random_10.txt AC 5 ms 3952 KiB
random_11.txt AC 6 ms 3956 KiB
random_12.txt AC 2 ms 3988 KiB
random_13.txt AC 2 ms 3980 KiB
random_14.txt AC 4 ms 3928 KiB
random_15.txt AC 9 ms 4064 KiB
random_16.txt AC 12 ms 4108 KiB
random_17.txt AC 17 ms 4216 KiB
random_18.txt AC 2 ms 4396 KiB
random_19.txt AC 1 ms 3956 KiB
random_20.txt AC 85 ms 5840 KiB
random_21.txt AC 4 ms 4088 KiB
random_22.txt AC 35 ms 4936 KiB
random_23.txt AC 56 ms 5736 KiB
random_24.txt AC 5 ms 4808 KiB
random_25.txt AC 15 ms 4828 KiB
random_26.txt AC 100 ms 6112 KiB
random_27.txt AC 90 ms 5784 KiB
random_28.txt AC 90 ms 6384 KiB
random_29.txt AC 89 ms 5920 KiB