Submission #66743668


Source Code Expand

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define MaxN 1005
int n, m;
vector < pair<int, int > > e[MaxN];
bool f[MaxN][1<<10];
queue <int> q, s;
int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		e[u].push_back(make_pair(v, w));
		// e[v].push_back(make_pair(u, w));
	}
	f[1][0] = 1;
	q.push(1);
	s.push(0);
	while (!q.empty()) {
		int u = q.front(), sta = s.front();
		q.pop(), s.pop();
		for(auto [v, w] : e[u]) {
			if (f[v][sta ^ w] == 0) {
				f[v][sta ^ w] = 1;
				q.push(v);
				s.push(sta ^ w);
			}
		}
	}
	for(int ss = 0; ss < (1<<10); ss++) {
		if (f[n][ss] == 1) {
			cout << ss << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Submission Info

Submission Time
Task D - XOR Shortest Walk
User gobywind
Language C++ 20 (gcc 12.2)
Score 400
Code Size 776 Byte
Status AC
Exec Time 8 ms
Memory 4624 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 33
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.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, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 1 ms 3568 KiB
hand_02.txt AC 1 ms 3448 KiB
hand_03.txt AC 1 ms 3580 KiB
hand_04.txt AC 1 ms 3516 KiB
hand_05.txt AC 1 ms 3520 KiB
hand_06.txt AC 1 ms 3528 KiB
hand_07.txt AC 1 ms 3568 KiB
hand_08.txt AC 1 ms 3524 KiB
random_01.txt AC 1 ms 3536 KiB
random_02.txt AC 2 ms 4332 KiB
random_03.txt AC 1 ms 3452 KiB
random_04.txt AC 2 ms 3936 KiB
random_05.txt AC 1 ms 3544 KiB
random_06.txt AC 1 ms 3804 KiB
random_07.txt AC 1 ms 3568 KiB
random_08.txt AC 2 ms 4080 KiB
random_09.txt AC 1 ms 3604 KiB
random_10.txt AC 2 ms 4460 KiB
random_11.txt AC 1 ms 3540 KiB
random_12.txt AC 2 ms 4228 KiB
random_13.txt AC 3 ms 3836 KiB
random_14.txt AC 6 ms 4100 KiB
random_15.txt AC 2 ms 3620 KiB
random_16.txt AC 1 ms 3592 KiB
random_17.txt AC 2 ms 4624 KiB
random_18.txt AC 2 ms 4528 KiB
random_19.txt AC 7 ms 4568 KiB
random_20.txt AC 5 ms 4124 KiB
random_21.txt AC 8 ms 4204 KiB
random_22.txt AC 8 ms 4120 KiB
sample_01.txt AC 1 ms 3676 KiB
sample_02.txt AC 1 ms 3672 KiB
sample_03.txt AC 1 ms 3672 KiB