Submission #68099575
Source Code Expand
#include <bits/stdc++.h>
#include <ctime>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define cty cout<<"Yes"<<endl
#define ctn cout<<"No"<<endl
#define dbg(x) cout<<#x<<" : "<<x<<endl
#define int long long
const int mxn = 1e6+10;
double ST,ED;
inline int read(){
int N = 0;char ch = getchar();
while (ch>'9'||ch<'0') ch = getchar();
while (ch>='0'&&ch<='9') N = N*10+ch-'0',ch = getchar();
return N;
}
int n,m;
struct node{
int u,v,w;
bool vis = true;
}x[mxn];
int fa[mxn];
int find(int i){
if(fa[i]==i) return i;
return fa[i] = find(fa[i]);
}
void LonelyLunar_solve(){
cin>>n>>m;
ll ans = 0;
for(int i = 1;i <= m; i++){
cin>>x[i].u>>x[i].v>>x[i].w;
x[i].vis = true;
}
for(int y = 30; y >= 0; y--){
for(int i = 1;i <= n; i++) fa[i] = i;
for(int i = 1;i <= m; i++){
int tu = find(x[i].u),tv = find(x[i].v);
if(tu==tv||!x[i].vis||(x[i].w>>y&1)) continue;
fa[tu] = tv;
}
if(find(n)==find(1)){
for(int i = 1;i <= m; i++) if(x[i].w>>y&1) x[i].vis = false;
}
else ans+=1<<y;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _ = 1;
ST = clock();
//cin>>_;
while(_--){
LonelyLunar_solve();
}
ED = clock();
cerr<<1000*(ED-ST)/CLOCKS_PER_SEC<<"ms\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Minimum OR Path |
| User | LonelyLunar |
| Language | C++ 20 (gcc 12.2) |
| Score | 450 |
| Code Size | 1411 Byte |
| Status | AC |
| Exec Time | 151 ms |
| Memory | 36600 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| 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_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 12 ms | 35108 KiB |
| 00_sample_01.txt | AC | 12 ms | 35028 KiB |
| 00_sample_02.txt | AC | 12 ms | 35016 KiB |
| 01_handmade_00.txt | AC | 12 ms | 35036 KiB |
| 01_handmade_01.txt | AC | 12 ms | 34948 KiB |
| 01_handmade_02.txt | AC | 65 ms | 34952 KiB |
| 01_handmade_03.txt | AC | 58 ms | 35084 KiB |
| 01_handmade_04.txt | AC | 12 ms | 35080 KiB |
| 01_handmade_05.txt | AC | 12 ms | 35072 KiB |
| 01_handmade_06.txt | AC | 12 ms | 35024 KiB |
| 01_handmade_07.txt | AC | 65 ms | 35612 KiB |
| 01_handmade_08.txt | AC | 65 ms | 35588 KiB |
| 01_handmade_09.txt | AC | 65 ms | 35644 KiB |
| 02_random_00.txt | AC | 81 ms | 36068 KiB |
| 02_random_01.txt | AC | 76 ms | 35660 KiB |
| 02_random_02.txt | AC | 55 ms | 35176 KiB |
| 02_random_03.txt | AC | 100 ms | 35556 KiB |
| 02_random_04.txt | AC | 117 ms | 35640 KiB |
| 02_random_05.txt | AC | 99 ms | 35608 KiB |
| 02_random_06.txt | AC | 95 ms | 35608 KiB |
| 02_random_07.txt | AC | 118 ms | 35920 KiB |
| 02_random_08.txt | AC | 141 ms | 36264 KiB |
| 02_random_09.txt | AC | 83 ms | 35900 KiB |
| 02_random_10.txt | AC | 136 ms | 35900 KiB |
| 02_random_11.txt | AC | 151 ms | 36024 KiB |
| 02_random_12.txt | AC | 124 ms | 35720 KiB |
| 02_random_13.txt | AC | 128 ms | 36208 KiB |
| 02_random_14.txt | AC | 148 ms | 36216 KiB |
| 02_random_15.txt | AC | 95 ms | 35152 KiB |
| 02_random_16.txt | AC | 67 ms | 35992 KiB |
| 02_random_17.txt | AC | 75 ms | 35968 KiB |
| 02_random_18.txt | AC | 72 ms | 36060 KiB |
| 02_random_19.txt | AC | 111 ms | 36532 KiB |
| 02_random_20.txt | AC | 127 ms | 36528 KiB |
| 02_random_21.txt | AC | 119 ms | 36600 KiB |