結果

問題 No.1776 Love Triangle 2 (Hard)
ユーザー HIR180HIR180
提出日時 2022-11-29 20:39:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 863 ms / 10,000 ms
コード長 2,719 bytes
コンパイル時間 3,146 ms
コンパイル使用メモリ 220,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 13:04:52
合計ジャッジ時間 29,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 7 ms
5,376 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 100 ms
5,376 KB
testcase_05 AC 192 ms
5,376 KB
testcase_06 AC 193 ms
5,376 KB
testcase_07 AC 71 ms
5,376 KB
testcase_08 AC 127 ms
5,376 KB
testcase_09 AC 13 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 12 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 20 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 14 ms
5,376 KB
testcase_22 AC 12 ms
5,376 KB
testcase_23 AC 11 ms
5,376 KB
testcase_24 AC 12 ms
5,376 KB
testcase_25 AC 13 ms
5,376 KB
testcase_26 AC 12 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 11 ms
5,376 KB
testcase_29 AC 23 ms
5,376 KB
testcase_30 AC 32 ms
5,376 KB
testcase_31 AC 86 ms
5,376 KB
testcase_32 AC 143 ms
5,376 KB
testcase_33 AC 181 ms
5,376 KB
testcase_34 AC 185 ms
5,376 KB
testcase_35 AC 178 ms
5,376 KB
testcase_36 AC 151 ms
5,376 KB
testcase_37 AC 111 ms
5,376 KB
testcase_38 AC 35 ms
5,376 KB
testcase_39 AC 21 ms
5,376 KB
testcase_40 AC 57 ms
5,376 KB
testcase_41 AC 86 ms
5,376 KB
testcase_42 AC 91 ms
5,376 KB
testcase_43 AC 77 ms
5,376 KB
testcase_44 AC 35 ms
5,376 KB
testcase_45 AC 204 ms
5,376 KB
testcase_46 AC 45 ms
5,376 KB
testcase_47 AC 11 ms
5,376 KB
testcase_48 AC 33 ms
5,376 KB
testcase_49 AC 12 ms
5,376 KB
testcase_50 AC 28 ms
5,376 KB
testcase_51 AC 74 ms
5,376 KB
testcase_52 AC 117 ms
5,376 KB
testcase_53 AC 147 ms
5,376 KB
testcase_54 AC 153 ms
5,376 KB
testcase_55 AC 148 ms
5,376 KB
testcase_56 AC 156 ms
5,376 KB
testcase_57 AC 85 ms
5,376 KB
testcase_58 AC 123 ms
5,376 KB
testcase_59 AC 21 ms
5,376 KB
testcase_60 AC 43 ms
5,376 KB
testcase_61 AC 58 ms
5,376 KB
testcase_62 AC 28 ms
5,376 KB
testcase_63 AC 26 ms
5,376 KB
testcase_64 AC 39 ms
5,376 KB
testcase_65 AC 11 ms
5,376 KB
testcase_66 AC 18 ms
5,376 KB
testcase_67 AC 24 ms
5,376 KB
testcase_68 AC 11 ms
5,376 KB
testcase_69 AC 328 ms
5,376 KB
testcase_70 AC 647 ms
5,376 KB
testcase_71 AC 651 ms
5,376 KB
testcase_72 AC 228 ms
5,376 KB
testcase_73 AC 428 ms
5,376 KB
testcase_74 AC 23 ms
5,376 KB
testcase_75 AC 19 ms
5,376 KB
testcase_76 AC 18 ms
5,376 KB
testcase_77 AC 16 ms
5,376 KB
testcase_78 AC 15 ms
5,376 KB
testcase_79 AC 14 ms
5,376 KB
testcase_80 AC 16 ms
5,376 KB
testcase_81 AC 15 ms
5,376 KB
testcase_82 AC 19 ms
5,376 KB
testcase_83 AC 33 ms
5,376 KB
testcase_84 AC 24 ms
5,376 KB
testcase_85 AC 20 ms
5,376 KB
testcase_86 AC 18 ms
5,376 KB
testcase_87 AC 16 ms
5,376 KB
testcase_88 AC 17 ms
5,376 KB
testcase_89 AC 20 ms
5,376 KB
testcase_90 AC 15 ms
5,376 KB
testcase_91 AC 16 ms
5,376 KB
testcase_92 AC 18 ms
5,376 KB
testcase_93 AC 17 ms
5,376 KB
testcase_94 AC 44 ms
5,376 KB
testcase_95 AC 95 ms
5,376 KB
testcase_96 AC 304 ms
5,376 KB
testcase_97 AC 628 ms
5,376 KB
testcase_98 AC 852 ms
5,376 KB
testcase_99 AC 863 ms
5,376 KB
testcase_100 AC 792 ms
5,376 KB
testcase_101 AC 551 ms
5,376 KB
testcase_102 AC 394 ms
5,376 KB
testcase_103 AC 109 ms
5,376 KB
testcase_104 AC 33 ms
5,376 KB
testcase_105 AC 118 ms
5,376 KB
testcase_106 AC 256 ms
5,376 KB
testcase_107 AC 59 ms
5,376 KB
testcase_108 AC 230 ms
5,376 KB
testcase_109 AC 66 ms
5,376 KB
testcase_110 AC 59 ms
5,376 KB
testcase_111 AC 51 ms
5,376 KB
testcase_112 AC 24 ms
5,376 KB
testcase_113 AC 42 ms
5,376 KB
testcase_114 AC 43 ms
5,376 KB
testcase_115 AC 79 ms
5,376 KB
testcase_116 AC 252 ms
5,376 KB
testcase_117 AC 493 ms
5,376 KB
testcase_118 AC 714 ms
5,376 KB
testcase_119 AC 722 ms
5,376 KB
testcase_120 AC 691 ms
5,376 KB
testcase_121 AC 406 ms
5,376 KB
testcase_122 AC 486 ms
5,376 KB
testcase_123 AC 537 ms
5,376 KB
testcase_124 AC 50 ms
5,376 KB
testcase_125 AC 53 ms
5,376 KB
testcase_126 AC 87 ms
5,376 KB
testcase_127 AC 55 ms
5,376 KB
testcase_128 AC 47 ms
5,376 KB
testcase_129 AC 38 ms
5,376 KB
testcase_130 AC 38 ms
5,376 KB
testcase_131 AC 37 ms
5,376 KB
testcase_132 AC 30 ms
5,376 KB
testcase_133 AC 26 ms
5,376 KB
testcase_134 AC 20 ms
5,376 KB
testcase_135 AC 64 ms
5,376 KB
testcase_136 AC 62 ms
5,376 KB
testcase_137 AC 51 ms
5,376 KB
testcase_138 AC 77 ms
5,376 KB
testcase_139 AC 130 ms
5,376 KB
testcase_140 AC 105 ms
5,376 KB
testcase_141 AC 61 ms
5,376 KB
testcase_142 AC 109 ms
5,376 KB
testcase_143 AC 70 ms
5,376 KB
testcase_144 AC 21 ms
5,376 KB
testcase_145 AC 23 ms
5,376 KB
testcase_146 AC 48 ms
5,376 KB
testcase_147 AC 21 ms
5,376 KB
testcase_148 AC 41 ms
5,376 KB
testcase_149 AC 37 ms
5,376 KB
testcase_150 AC 51 ms
5,376 KB
testcase_151 AC 25 ms
5,376 KB
testcase_152 AC 40 ms
5,376 KB
testcase_153 AC 57 ms
5,376 KB
testcase_154 AC 37 ms
5,376 KB
testcase_155 AC 194 ms
5,376 KB
testcase_156 AC 297 ms
5,376 KB
testcase_157 AC 148 ms
5,376 KB
testcase_158 AC 184 ms
5,376 KB
testcase_159 AC 206 ms
5,376 KB
testcase_160 AC 93 ms
5,376 KB
testcase_161 AC 136 ms
5,376 KB
testcase_162 AC 372 ms
5,376 KB
testcase_163 AC 433 ms
5,376 KB
testcase_164 AC 426 ms
5,376 KB
testcase_165 AC 163 ms
5,376 KB
testcase_166 AC 89 ms
5,376 KB
testcase_167 AC 92 ms
5,376 KB
testcase_168 AC 53 ms
5,376 KB
testcase_169 AC 87 ms
5,376 KB
testcase_170 AC 148 ms
5,376 KB
testcase_171 AC 213 ms
5,376 KB
testcase_172 AC 123 ms
5,376 KB
testcase_173 AC 325 ms
5,376 KB
testcase_174 AC 125 ms
5,376 KB
testcase_175 AC 129 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
using ull=unsigned;

ull _sm[256][256];
template<bool is_pre = false>
ull nim_product(ull a, ull b, int k = 32){
	if(min(a, b) <= 1) return a*b;
	if(!is_pre and k <= 8) return _sm[a][b];
	k >>= 1;
	
	ull au = (a>>k), al = a & (((ull)1<<k)-1);
	ull bu = (b>>k), bl = b & (((ull)1<<k)-1);
	
	ull go1 = nim_product<is_pre>(au, bu, k);
	ull go2 = nim_product<is_pre>(al, bl, k);
	ull go3 = nim_product<is_pre>(au^al, bu^bl, k);
	
	return ((go2^go3)<<k)^nim_product(go1, ((ull)1<<(k-1)), k)^go2;
}
void init_np(){
	rep(a,256)rep(b,256) _sm[a][b]=nim_product<true>(a,b,8);
}
constexpr int NL=150;
ull dp[3*NL+5][NL+5][4], cs[NL+5][NL+5];
int n,m,x,y,z;
bool bad[NL+5][NL+5], rem[NL+5];

int main(){
	ios::sync_with_stdio(0);
	init_np();
	
	cin>>n>>m;
	cin>>x>>y>>z; x--;y--;z--;
	rep(i,n) bad[i][i]=true;
	rep(i,m){
		int a,b;cin>>a>>b;
		a--;b--;
		bad[a][b]=bad[b][a]=true;
	}
	rep(i, n) rep(j, i) if(!bad[i][j]){
		cs[i][j] = cs[j][i] = mt()>>32;
	}
	int goal = x, need = -1, M = 3;
	vc<int>ans{x};
	rem[x] = true;
	while(need != 1){
		memset(dp, 0, sizeof(dp));
		dp[x][1][0] = 1;
		
		repn(len, n){
			rep(state, 3*n){
				rep(mask, 4){
					if(dp[state][len][mask] == 0) continue;
					
					int pre=-1, now=state;
					if(state>=n){
						pre=state%n;
						if(state/n==1)now=y;
						else now=z;
					}
					rep(nxt, n){
						if(pre == nxt or rem[nxt] or bad[now][nxt]) continue;
						if(nxt == y and (mask&1)) continue;
						if(nxt == z and (mask&2)) continue;
						
						int nstate = nxt, nmask = mask;
						if(nxt == y) nstate = n+now, nmask|=1;
						else if(nxt == z) nstate = n+n+now, nmask|=2;
						dp[nstate][len+1][nmask] ^= nim_product(dp[state][len][mask], cs[now][nxt]);
					}
				}
			}
			if(need == -1 or need == len){
				rep(now, n){
					if(bad[now][goal] or rem[now]) continue;
					int lb=now, ub=now;
					if(now == y) lb=n, ub=2*n-1;
					else if(now == z) lb = 2*n, ub=3*n-1;
					
					rng(state, lb, ub+1){
						if(dp[state][len][M]){
							ans.pb(now);
							need = len-1;
							if(now==y) M^=1;
							else if(now==z) M^=2;
							goal = now;
							rem[goal] = true;
							goto nxt;
						}
					}
				}
			}
		}
		cout<<-1<<'\n';
		return 0;
		nxt:;
	}
	cout<<si(ans)<<'\n';
	for(auto e:ans) cout << ++e << " ";
	cout<<++x<<'\n';
}
0