Submission #63534343


Source Code Expand

Copy
#ifndef ONLINE_JUDGE//atcoder ABC325D
#define _GLIBCXX_DEBUG//[]TLE ABC311E4TLE
#endif//ONLINE JUDGE
//★TLETLE
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld = long double;
using Pii=pair<int,int>;
using Pll=pair<ll,ll>;
using TT=tuple<int,int,int>;
#define mPP(a,b) make_pair(a,b)
#define mTT(a,b,c) make_tuple(a,b,c)
#define rep1(a) for(int i = 0; i < (int)(a); i++)
#define rep2(i, a) for(int i = 0; i < (int)(a); i++)
#define rep3(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep4(i, a, b, c) for(int i = (int)(a); i < (int)(b); i += c)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#ifndef ONLINE_JUDGE//なんか手元ではデバックモードになって、atcoder上ではデバックモードにならないらしい ABC325Dはこれで通った
#define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4のデバックTLEなどに注意
#endif//これと上のONLINE JUDGEが絶対必要
//★TLEにならないはずなのにTLEになったらオンラインジャッジを消してデバックモードのまま提出をする。

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
using ull=unsigned long long;
using ld = long double;
using Pii=pair<int,int>;
using Pll=pair<ll,ll>;
using TT=tuple<int,int,int>;
#define mPP(a,b) make_pair(a,b)
#define mTT(a,b,c) make_tuple(a,b,c)

#define rep1(a)          for(int i = 0; i < (int)(a); i++)
#define rep2(i, a)       for(int i = 0; i < (int)(a); i++)
#define rep3(i, a, b)    for(int i = (int)(a); i < (int)(b); i++)
#define rep4(i, a, b, c) for(int i = (int)(a); i < (int)(b); i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i,n) for(int i = (int)(n)-1; i >= 0; --i)
#define RREP(i,advanced,n) for(int i = (int)(n)-1; i >= advanced; --i)
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
#define ALL(a,middle,last) a.begin()+middle,a.begin()+last
#define w_np(a) while(next_permutation(all(a)))
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define mycin(vec) for(auto &v:vec) cin >> v;
#define mycout(vec) for(auto &v:vec) cout << v << " ";
// #define mycout(vec) for(auto &v:vec) cout << v << endl;
#define dame cout<<-1<<endl
#define YES cout<<"Yes"<<endl
#define YEAH { cout << "Yes" << endl; return 0; }
#define NO cout<<"No"<<endl
#define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} // if(ans[i])YN;
#define UQ(v) v.erase( unique(all(v)), v.end() );
#define MHT(x1,x2,y1,y2) (abs(x1-x2)+abs(y1-y2)) // マンハッタン距離 = |x1-x2|+|y1-y2|  座標の絶対値の和
#define YKD(x1,x2,y1,y2) ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) // ユークリッド距離  座標の差の二乗の和
// #define YKD(x1,x2,y1,y2) (pow(x1-x2,2) + pow(y1-y2,2)) // でっかい数のとき 数が 1e10 みたいに表記される場合に注意
#define displace(vec) rotate(vec.begin(),vec.begin()+1,vec.end()) // abcd -> bcda のように一つ要素をずらす
#define DISPLACE(vec,First,Middle,Last) rotate(vec.begin()+First,vec.begin()+Middle,vec.begin()+Last)
// ……a[F-1] (( a[F] a[F+1] …… a[M-1] a[M] a[M+1] …… a[L-1] )) a[L]…… -> ……a[F-1] (( a[M] a[M+1] …… a[L-1] …… a[F] a[F+1] …… a[M-1] )) a[L]……
template<typename T> using vc = vector<T>;
template<class T> using PQ = priority_queue<T, vc<T>>; // 大きい順に取り出す
template<class T> using PQ_G = priority_queue<T, vc<T>, greater<T>>; // 小さい順に取り出す
ll pow2(ll x) { return x * x; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vc<ll> di = { 1,-1,0,0 };
vc<ll> dj = { 0,0,1,-1 };
// vc<ll> di={1,1,0,-1,-1,-1,0,1};
// vc<ll> dj={0,1,1,1,0,-1,-1,-1};
// int INF = 2e9;
ll INF = 2e18;

const int SIZE = 70;

using P = pair<int,bitset<SIZE>>;

vc<bool> seen(100,false);

int n;
ll ans = INF;

void dfs(int pos, bitset<SIZE> sum, vc<vc<P>> &g)
{
    if(pos == n-1) {
        chmin(ans,(ll)sum.to_ullong());
        return;
    }
    seen[pos] = true;
    rep(i,g[pos].size()) {
        int nex = g[pos][i].first;
        if(!seen[nex]) {
            dfs(nex,sum^g[pos][i].second,g);
        }
    }
    seen[pos] = false;
    
}

int main()
{
    
    int m; cin >> n >> m;
    vc<vc<P>> g(n);
    rep(i,m) {
        ll u,v,w; cin >> u >> v >> w; u--,v--;
        bitset<SIZE> bit(w);
        g[u].push_back(mPP(v,bit));
        g[v].push_back(mPP(u,bit));
        // cout << u << " " << v << " " << bit << endl;
    }
    
    bitset<SIZE> ss(0);
    dfs(0,ss,g);
    cout << ans << endl;
    
}

Submission Info

Submission Time
Task D - Minimum XOR Path
User gerira
Language C++ 20 (gcc 12.2)
Score 400
Code Size 4211 Byte
Status AC
Exec Time 5 ms
Memory 3684 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 32
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KB
00_sample_01.txt AC 1 ms 3448 KB
00_sample_02.txt AC 1 ms 3488 KB
01_test_00.txt AC 1 ms 3496 KB
01_test_01.txt AC 1 ms 3456 KB
01_test_02.txt AC 1 ms 3492 KB
01_test_03.txt AC 1 ms 3412 KB
01_test_04.txt AC 1 ms 3448 KB
01_test_05.txt AC 1 ms 3484 KB
01_test_06.txt AC 1 ms 3540 KB
01_test_07.txt AC 1 ms 3468 KB
01_test_08.txt AC 1 ms 3472 KB
01_test_09.txt AC 1 ms 3492 KB
01_test_10.txt AC 1 ms 3468 KB
01_test_11.txt AC 1 ms 3540 KB
01_test_12.txt AC 1 ms 3608 KB
01_test_13.txt AC 1 ms 3536 KB
01_test_14.txt AC 1 ms 3612 KB
01_test_15.txt AC 1 ms 3468 KB
01_test_16.txt AC 1 ms 3452 KB
01_test_17.txt AC 3 ms 3544 KB
01_test_18.txt AC 1 ms 3448 KB
01_test_19.txt AC 4 ms 3540 KB
01_test_20.txt AC 4 ms 3540 KB
01_test_21.txt AC 4 ms 3484 KB
01_test_22.txt AC 5 ms 3684 KB
01_test_23.txt AC 5 ms 3492 KB
01_test_24.txt AC 1 ms 3480 KB
01_test_25.txt AC 1 ms 3492 KB
01_test_26.txt AC 1 ms 3528 KB
01_test_27.txt AC 1 ms 3492 KB
01_test_28.txt AC 1 ms 3464 KB


2025-03-28 (Fri)
17:51:35 +00:00