提出 #66779449
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll=long long;
int n,m;
vector<vector<pair<int,int>>> graph;
vector<tuple<int,int,int>> edges;
vector<int> d;
vector<bool> visited;
vector<int> basis;
queue<int> q;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
graph.resize(n+1);
edges.resize(m);
d.assign(n+1,-1);
visited.assign(n+1,false);
for(int i=0;i<m;i++){
int u,v,w;cin>>u>>v>>w;
graph[u].push_back({v,w});
edges[i]=make_tuple(u,v,w);
}
d[1]=0;
visited[1]=true;
q.push(1);
while(!q.empty()){
int u=q.front();q.pop();
for(auto&p:graph[u]){
int v=p.first,w=p.second;
if(!visited[v]){
visited[v]=true;
d[v]=d[u]^w;
q.push(v);
}
}
}
if(!visited[n]){
cout<<-1<<endl;
return 0;
}
for(auto&e:edges){
int u,v,w;tie(u,v,w)=e;
if(visited[u]&&visited[v]){
int x=d[u]^w^d[v];
for(int b:basis)x=min(x,x^b);
if(x!=0)basis.push_back(x);
}
}
sort(basis.begin(),basis.end(),greater<int>());
ll ans=d[n];
for(int b:basis)ans=min(ans,ans^b);
cout<<ans<<endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - XOR Shortest Walk |
| ユーザ | vladkonoval |
| 言語 | C++ 17 (gcc 12.2) |
| 得点 | 0 |
| コード長 | 1138 Byte |
| 結果 | WA |
| 実行時間 | 2 ms |
| メモリ | 3584 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 400 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| hand_01.txt | AC | 1 ms | 3384 KiB |
| hand_02.txt | AC | 1 ms | 3512 KiB |
| hand_03.txt | AC | 1 ms | 3512 KiB |
| hand_04.txt | AC | 1 ms | 3448 KiB |
| hand_05.txt | AC | 1 ms | 3448 KiB |
| hand_06.txt | WA | 2 ms | 3408 KiB |
| hand_07.txt | WA | 1 ms | 3408 KiB |
| hand_08.txt | WA | 1 ms | 3448 KiB |
| random_01.txt | AC | 1 ms | 3512 KiB |
| random_02.txt | AC | 2 ms | 3424 KiB |
| random_03.txt | AC | 1 ms | 3444 KiB |
| random_04.txt | AC | 2 ms | 3540 KiB |
| random_05.txt | AC | 1 ms | 3496 KiB |
| random_06.txt | AC | 1 ms | 3420 KiB |
| random_07.txt | AC | 1 ms | 3584 KiB |
| random_08.txt | AC | 2 ms | 3488 KiB |
| random_09.txt | AC | 1 ms | 3448 KiB |
| random_10.txt | AC | 2 ms | 3472 KiB |
| random_11.txt | AC | 1 ms | 3516 KiB |
| random_12.txt | AC | 2 ms | 3564 KiB |
| random_13.txt | AC | 1 ms | 3448 KiB |
| random_14.txt | AC | 2 ms | 3520 KiB |
| random_15.txt | AC | 1 ms | 3520 KiB |
| random_16.txt | AC | 2 ms | 3416 KiB |
| random_17.txt | AC | 2 ms | 3584 KiB |
| random_18.txt | AC | 2 ms | 3580 KiB |
| random_19.txt | AC | 2 ms | 3508 KiB |
| random_20.txt | AC | 1 ms | 3508 KiB |
| random_21.txt | AC | 1 ms | 3476 KiB |
| random_22.txt | AC | 2 ms | 3576 KiB |
| sample_01.txt | AC | 1 ms | 3516 KiB |
| sample_02.txt | AC | 2 ms | 3412 KiB |
| sample_03.txt | AC | 1 ms | 3540 KiB |