Submission #66760513
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;using ll = long long;#define all(x) (x).begin(),(x).end()#define rall(x) (x).rbegin(),(x).rend()#define rep(i,a,b) for(int i=a;i<b;i++)int main(){int n, m;cin >> n >> m;vector<set<pair<int, int>>> edge(n);int a, b, w;rep(i, 0, m){cin >> a >> b >> w;a--;b--;edge[a].insert({b, w});}vector<int> dist(n, -1);vector<int> basis;dist[0] = 0;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,a,b) for(int i=a;i<b;i++)
int main(){
int n, m;
cin >> n >> m;
vector<set<pair<int, int>>> edge(n);
int a, b, w;
rep(i, 0, m){
cin >> a >> b >> w;
a--;b--;
edge[a].insert({b, w});
}
vector<int> dist(n, -1);
vector<int> basis;
dist[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int u = q.front(); q.pop();
for (auto [v, w] : edge[u]) {
int new_dist = dist[u] ^ w;
if (dist[v] == -1) {
dist[v] = new_dist;
q.push(v);
} else {
// サイクル
int cycle = dist[v] ^ new_dist;
for (int b : basis){
cycle = min(cycle, cycle ^ b);
}
if (cycle != 0) basis.push_back(cycle);
}
}
}
int ans = dist[n - 1];
if(ans != -1){
for (int b : basis){
ans = min(ans, ans ^ b);
}
}
cout << ans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | sukoeru |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1230 Byte |
| Status | WA |
| Exec Time | 1 ms |
| Memory | 3776 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 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 | 3452 KiB |
| hand_02.txt | AC | 1 ms | 3544 KiB |
| hand_03.txt | AC | 1 ms | 3416 KiB |
| hand_04.txt | AC | 1 ms | 3616 KiB |
| hand_05.txt | AC | 1 ms | 3532 KiB |
| hand_06.txt | WA | 1 ms | 3480 KiB |
| hand_07.txt | WA | 1 ms | 3476 KiB |
| hand_08.txt | WA | 1 ms | 3408 KiB |
| random_01.txt | AC | 1 ms | 3476 KiB |
| random_02.txt | AC | 1 ms | 3596 KiB |
| random_03.txt | AC | 1 ms | 3616 KiB |
| random_04.txt | AC | 1 ms | 3644 KiB |
| random_05.txt | AC | 1 ms | 3528 KiB |
| random_06.txt | AC | 1 ms | 3492 KiB |
| random_07.txt | AC | 1 ms | 3680 KiB |
| random_08.txt | AC | 1 ms | 3544 KiB |
| random_09.txt | AC | 1 ms | 3680 KiB |
| random_10.txt | AC | 1 ms | 3536 KiB |
| random_11.txt | AC | 1 ms | 3548 KiB |
| random_12.txt | AC | 1 ms | 3588 KiB |
| random_13.txt | AC | 1 ms | 3512 KiB |
| random_14.txt | AC | 1 ms | 3644 KiB |
| random_15.txt | AC | 1 ms | 3560 KiB |
| random_16.txt | AC | 1 ms | 3484 KiB |
| random_17.txt | AC | 1 ms | 3704 KiB |
| random_18.txt | AC | 1 ms | 3776 KiB |
| random_19.txt | AC | 1 ms | 3644 KiB |
| random_20.txt | AC | 1 ms | 3572 KiB |
| random_21.txt | AC | 1 ms | 3548 KiB |
| random_22.txt | AC | 1 ms | 3572 KiB |
| sample_01.txt | AC | 1 ms | 3680 KiB |
| sample_02.txt | AC | 1 ms | 3496 KiB |
| sample_03.txt | AC | 1 ms | 3544 KiB |