Submission #66752922
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/**
* テンプレート出典:http://qiita.com/sorachandu/items/041169d34b9f9b99bcf7
*/
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(13); } }init;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
#define rep(i, x, limit) for (int i = (int)x; i < (int)limit; i++)
#define REP(i, x, limit) for (int i = (int)x; i <= (int)limit; i++)
#define repl(i, x, limit) for (ll i = (ll)x; i < (ll)limit; i++)
#define REPL(i, x, limit) for (ll i = (ll)x; i <= (ll)limit; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa " "
#define Yes cout << "Yes" << el
#define No cout << "No" << el
#define YES cout << "YES" << el
#define NO cout << "NO" << el
#define eps (1e-10)
#define Equals(a,b) (fabs((a) - (b)) < eps )
#define debug(x) cerr << #x << " = " << x << el
const double pi = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
//std::pairをstd::coutに渡すために"<<"処理を書き換えた物
template<typename T1, typename T2>
std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){
os << "{" << p.first << "," << p.second << "}";
return os;
}
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
bool compare = a < b;
if(compare) a = b;
return compare;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
bool compare = a > b;
if(compare) a = b;
return compare;
}
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
vector<vector<pii>> G;
vi dist;
vi base2(10,0);
vb visited;
void check(int x) {
for (int i = 9; i >= 0; i--) {
if ((x & (1 << i)) == 0) continue;
if (base2[i] == 0) {
base2[i] = x;
return;
}
x ^= base2[i];
}
}
int get_answer(int x) {
for (int i = 9; i >= 0; i--) {
if (base2[i] != 0) {
x = min(x, x ^ base2[i]);
}
}
return x;
}
int main(void){
int N, M;
cin >> N >> M;
G.resize(N + 1);
for (int i = 0; i < M; i++) {
int a, b, w;
cin >> a >> b >> w;
G[a].push_back({b, w});
}
dist.resize(N+1, -1);
dist[1] = 0;
queue<int> q;
q.push(1);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto& e : G[v]) {
int next_v = e.first;
int weight = e.second;
if (dist[next_v] == -1) {
dist[next_v] = dist[v] ^ weight;
q.push(next_v);
}
}
}
if (dist[N] == -1) {
cout << -1 << endl;
return 0;
}
visited.resize(N + 1, false);
for (int v = 1; v <= N; v++) {
if (dist[v] != -1) {
for (auto e : G[v]) {
int next_v = e.first;
int weight = e.second;
if (dist[next_v] != -1) {
int cycle_xor = dist[v] ^ weight ^ dist[next_v];
if (cycle_xor != 0) {
check(cycle_xor);
}
}
}
}
}
int result = get_answer(dist[N]);
cout << result << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - XOR Shortest Walk |
| User |
shojin_debu |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
3831 Byte |
| Status |
WA |
| Exec Time |
3 ms |
| Memory |
3680 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 |
3 ms |
3496 KiB |
| hand_02.txt |
AC |
1 ms |
3524 KiB |
| hand_03.txt |
AC |
1 ms |
3680 KiB |
| hand_04.txt |
AC |
1 ms |
3560 KiB |
| hand_05.txt |
AC |
1 ms |
3448 KiB |
| hand_06.txt |
WA |
1 ms |
3496 KiB |
| hand_07.txt |
WA |
1 ms |
3416 KiB |
| hand_08.txt |
WA |
1 ms |
3612 KiB |
| random_01.txt |
AC |
1 ms |
3448 KiB |
| random_02.txt |
AC |
1 ms |
3592 KiB |
| random_03.txt |
AC |
1 ms |
3492 KiB |
| random_04.txt |
AC |
1 ms |
3520 KiB |
| random_05.txt |
AC |
1 ms |
3556 KiB |
| random_06.txt |
AC |
1 ms |
3464 KiB |
| random_07.txt |
AC |
1 ms |
3560 KiB |
| random_08.txt |
AC |
1 ms |
3592 KiB |
| random_09.txt |
AC |
1 ms |
3552 KiB |
| random_10.txt |
AC |
1 ms |
3592 KiB |
| random_11.txt |
AC |
1 ms |
3548 KiB |
| random_12.txt |
AC |
1 ms |
3488 KiB |
| random_13.txt |
AC |
1 ms |
3508 KiB |
| random_14.txt |
AC |
1 ms |
3640 KiB |
| random_15.txt |
AC |
1 ms |
3564 KiB |
| random_16.txt |
AC |
1 ms |
3524 KiB |
| random_17.txt |
AC |
1 ms |
3516 KiB |
| random_18.txt |
AC |
1 ms |
3616 KiB |
| random_19.txt |
AC |
1 ms |
3512 KiB |
| random_20.txt |
AC |
1 ms |
3540 KiB |
| random_21.txt |
AC |
1 ms |
3600 KiB |
| random_22.txt |
AC |
1 ms |
3552 KiB |
| sample_01.txt |
AC |
1 ms |
3548 KiB |
| sample_02.txt |
AC |
1 ms |
3644 KiB |
| sample_03.txt |
AC |
1 ms |
3588 KiB |