Submission #66739952
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ull unsigned long long
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define s second
#define f first
#define pb push_back
#define oo 1000000000000000000ll
#define all(a) (a).begin(), a.end()
#define rall(a) (a).rbegin(), a.rend()
#define mp make_pair
void calc(int u, int x, vector<vector<int>>& dp, vector<vector<pii>>& red){
if (dp[u][x] != -1) return;
dp[u][x] = 0;
for (auto [from, w] : red[u]){
calc(from, x ^ w, dp, red);
if (dp[from][x ^ w]) dp[u][x] = 1;
}
}
void solve() {
int MX = (1 << 10);
int n, m; cin >> n >> m;
vector<vector<pii>> red(n+1);
for (int i = 0; i < m; ++i){
int a, b, w; cin >> a >> b >> w;
red[b].pb({a, w});
}
vector<vector<int>> dp(n+1, vector<int>(MX, -1));
dp[1][0] = 1;
for (int i = 0; i < MX; ++i){
calc(n, i, dp, red);
if (dp[n][i]){
cout << i << "\n";
return;
}
}
cout << "-1\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tst; tst = 1;
//cin >> tst;
while (tst--){
solve();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | snasibov05 |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 1395 Byte |
| Status | AC |
| Exec Time | 20 ms |
| Memory | 20772 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| 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 | 3432 KiB |
| hand_02.txt | AC | 1 ms | 3508 KiB |
| hand_03.txt | AC | 1 ms | 3472 KiB |
| hand_04.txt | AC | 1 ms | 3556 KiB |
| hand_05.txt | AC | 1 ms | 3472 KiB |
| hand_06.txt | AC | 1 ms | 3392 KiB |
| hand_07.txt | AC | 1 ms | 3428 KiB |
| hand_08.txt | AC | 1 ms | 3484 KiB |
| random_01.txt | AC | 1 ms | 3612 KiB |
| random_02.txt | AC | 10 ms | 8000 KiB |
| random_03.txt | AC | 1 ms | 3500 KiB |
| random_04.txt | AC | 3 ms | 6148 KiB |
| random_05.txt | AC | 1 ms | 3560 KiB |
| random_06.txt | AC | 4 ms | 4916 KiB |
| random_07.txt | AC | 1 ms | 3524 KiB |
| random_08.txt | AC | 10 ms | 7488 KiB |
| random_09.txt | AC | 1 ms | 3628 KiB |
| random_10.txt | AC | 18 ms | 9848 KiB |
| random_11.txt | AC | 1 ms | 3496 KiB |
| random_12.txt | AC | 11 ms | 8092 KiB |
| random_13.txt | AC | 6 ms | 7076 KiB |
| random_14.txt | AC | 11 ms | 12840 KiB |
| random_15.txt | AC | 3 ms | 4808 KiB |
| random_16.txt | AC | 3 ms | 8188 KiB |
| random_17.txt | AC | 5 ms | 11256 KiB |
| random_18.txt | AC | 11 ms | 11164 KiB |
| random_19.txt | AC | 4 ms | 11180 KiB |
| random_20.txt | AC | 4 ms | 11256 KiB |
| random_21.txt | AC | 20 ms | 20696 KiB |
| random_22.txt | AC | 20 ms | 20772 KiB |
| sample_01.txt | AC | 1 ms | 3456 KiB |
| sample_02.txt | AC | 1 ms | 3528 KiB |
| sample_03.txt | AC | 4 ms | 11232 KiB |