Submission #63512912


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <bitset>
#include <set>
#define ll long long
#define N 500010
using namespace std;
ll read(){
	char cc;
	while(1){cc=getchar();if((cc>='0'&&cc<='9')||cc=='-')break;}
	ll sum=0,flag=1;
	cc=='-'?flag=-1:sum=(cc^48);
	while(1){cc=getchar();if(!(cc>='0'&&cc<='9'))break;sum=(sum<<1)+(sum<<3)+(cc^48);}
	return sum*flag;
}
void write(ll x){
	if(!x)putchar('0');
	if(x<0){x=-x;putchar('-');}
	ll cc[25],cntt=0;
	while(x){cc[++cntt]=x%10;x/=10;}
	for(ll i=cntt;i>=1;i--)putchar(cc[i]+'0');
	putchar(' ');
	// putchar('\n');
}

vector <pair<ll,ll> >b[N];
ll n,m,a[N],t[32],flag=0,vis[N],s[N],shu,S,col[N],c[N],cnt=0;

void dfs(ll x){
	if(flag)return ;
	vis[x]=1;
	col[x]=cnt;
	for(ll i=0;i<30;i++)if((s[x]>>i)&1)t[i]++;
	shu++;
	for(pair<ll,ll> y:b[x]){
		if(flag)return ;
		ll v=y.first,w=y.second;
		if(vis[v]){
			if(w!=(s[x]^s[v])){flag=1;return ;}
		}
		else {
			s[v]=s[x]^w;
			dfs(v);
		}
	}
}	
int main(){
	n=read();m=read();
	for(ll u,v,w,i=1;i<=m;i++){
		u=read();v=read();w=read();
		b[u].push_back(make_pair(v,w));
		b[v].push_back(make_pair(u,w));
	}
	for(ll i=1;i<=n&&!flag;i++)if(!vis[i]){
		shu=0;cnt++;
		memset(t,0,sizeof(t));
		dfs(i);
		if(flag)break;
		S=0;
		for(ll j=0;j<30;j++)if(shu-t[j]<t[j])S|=(1<<j);
		c[cnt]=S;
	}
	if(flag){printf("-1\n");return 0;}
	for(ll i=1;i<=n;i++)write(s[i]^c[col[i]]);
	return 0;
}/*















*/

Submission Info

Submission Time
Task E - Min of Restricted Sum
User yixiuge777
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1556 Byte
Status AC
Exec Time 59 ms
Memory 19888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 38
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, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 3476 KiB
00_sample_01.txt AC 3 ms 3392 KiB
00_sample_02.txt AC 3 ms 3476 KiB
01_handmade_00.txt AC 2 ms 3468 KiB
01_handmade_01.txt AC 14 ms 8164 KiB
01_handmade_02.txt AC 3 ms 3512 KiB
01_handmade_03.txt AC 3 ms 3388 KiB
01_handmade_04.txt AC 3 ms 3472 KiB
01_handmade_05.txt AC 3 ms 3476 KiB
01_handmade_06.txt AC 14 ms 8152 KiB
01_handmade_07.txt AC 38 ms 19888 KiB
01_handmade_08.txt AC 29 ms 19876 KiB
01_handmade_09.txt AC 12 ms 8116 KiB
02_random_00.txt AC 37 ms 13076 KiB
02_random_01.txt AC 40 ms 17156 KiB
02_random_02.txt AC 52 ms 16704 KiB
02_random_03.txt AC 58 ms 18960 KiB
02_random_04.txt AC 22 ms 13840 KiB
02_random_05.txt AC 41 ms 17260 KiB
02_random_06.txt AC 44 ms 14708 KiB
02_random_07.txt AC 59 ms 18932 KiB
02_random_08.txt AC 29 ms 13544 KiB
02_random_09.txt AC 30 ms 16044 KiB
02_random_10.txt AC 14 ms 8572 KiB
02_random_11.txt AC 32 ms 16180 KiB
02_random_12.txt AC 20 ms 10024 KiB
02_random_13.txt AC 28 ms 18188 KiB
02_random_14.txt AC 16 ms 9876 KiB
02_random_15.txt AC 24 ms 16756 KiB
02_random_16.txt AC 22 ms 10524 KiB
02_random_17.txt AC 29 ms 18180 KiB
02_random_18.txt AC 26 ms 14084 KiB
02_random_19.txt AC 57 ms 18724 KiB
02_random_20.txt AC 11 ms 6192 KiB
02_random_21.txt AC 51 ms 17976 KiB
02_random_22.txt AC 29 ms 9760 KiB
02_random_23.txt AC 45 ms 13392 KiB
02_random_24.txt AC 11 ms 8472 KiB