Submission #1063213


Source Code Expand

#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,lint> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,m,q;
vector<pi> g[100005];

lint xsum[100005];
bool vis[100005];

int cnt;
lint cycle[200005];
int dep[100005];
void dfs(int v,int p,lint sum,int d){
  xsum[v]=sum;
  dep[v]=d;
  vis[v]=1;
  for(auto e:g[v]){
    if(e.fr==p) continue;
    if(vis[e.fr]){
      if(dep[e.fr]<dep[v]) cycle[cnt++]=xsum[v]^xsum[e.fr]^e.sc;
      continue;
    }
    dfs(e.fr,v,sum^e.sc,d+1);
  }
}
int main(){
  cin>>n>>m>>q;
  REP(i,m){
    int a,b;
    lint c;
    scanf("%d%d%lld",&a,&b,&c);
    g[a].pb({b,c});
    g[b].pb({a,c});
  }
  dfs(0,-1,0ll,0);
  assert(cnt==m-n+1);

  int seek=0;
  int toflip[65];
  memset(toflip,-1,sizeof(toflip));
  for(int i=59;i>=0;--i){
    bool ok=false;
    REPN(j,cnt,seek) if(cycle[j]>>i&1){
      ok=true;
      swap(cycle[j],cycle[seek]);
      break;
    }
    if(!ok) continue;
    REP(j,cnt) if(j!=seek && cycle[j]>>i&1) cycle[j]^=cycle[seek];
    toflip[i]=seek;
    ++seek;
  }

  REP(hoge,q){
    int a,b;scanf("%d%d",&a,&b);
    lint res=xsum[a]^xsum[b];

    for(int i=59;i>=0;--i) if(!(res>>i&1) && ~toflip[i]){
      res^=cycle[toflip[i]];
    }
    cout<<res<<endl;
  }
  return 0;
}



Submission Info

Submission Time
Task K - XOR回廊
User hogloid
Language C++11 (GCC 4.8.1)
Score 200
Code Size 2440 Byte
Status AC
Exec Time 471 ms
Memory 17580 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:73:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%lld",&a,&b,&c);
                               ^
./Main.cpp:97:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int a,b;scanf("%d%d",&a,&b);
                                ^

Judge Result

Set Name Partial 1 All
Score / Max Score 60 / 60 140 / 140
Status
AC × 21
AC × 64
Set Name Test Cases
Partial 1 0_00_sample_00, 0_01_Teuchi_01, 0_10_PerfectRandom_00_000004_000004, 0_10_PerfectRandom_01_000005_000007, 0_10_PerfectRandom_02_000009_000013, 0_21_Star_02_000009_000008, 0_21_Star_03_000012_000011, 0_22_BinaryTree_01_000005_000004, 0_23_RandomTree_00_000004_000003, 0_25_Ring_00_000003_000003, 0_25_Ring_01_000020_000020, 0_26_Complete_00_000004_000006, 0_26_Complete_01_000005_000010, 0_27_Random_00_000002_000001, 0_27_Random_01_000005_000010, 0_27_Random_03_000013_000013, 0_30_Island_00_000004_000004, 0_30_Island_01_000007_000006, 0_30_Island_02_000009_000008, 0_40_Corner_00_000010_000020, 0_40_Corner_01_000021_000020
All 0_00_sample_00, 0_01_Teuchi_01, 0_10_PerfectRandom_00_000004_000004, 0_10_PerfectRandom_01_000005_000007, 0_10_PerfectRandom_02_000009_000013, 0_21_Star_02_000009_000008, 0_21_Star_03_000012_000011, 0_22_BinaryTree_01_000005_000004, 0_23_RandomTree_00_000004_000003, 0_25_Ring_00_000003_000003, 0_25_Ring_01_000020_000020, 0_26_Complete_00_000004_000006, 0_26_Complete_01_000005_000010, 0_27_Random_00_000002_000001, 0_27_Random_01_000005_000010, 0_27_Random_03_000013_000013, 0_30_Island_00_000004_000004, 0_30_Island_01_000007_000006, 0_30_Island_02_000009_000008, 0_40_Corner_00_000010_000020, 0_40_Corner_01_000021_000020, 1_01_Teuchi_00, 1_10_PerfectRandom_03_000013_000021, 1_10_PerfectRandom_04_000021_000106, 1_10_PerfectRandom_05_000029_000210, 1_10_PerfectRandom_06_000236_007490, 1_10_PerfectRandom_07_000843_061761, 1_10_PerfectRandom_08_004086_126064, 1_10_PerfectRandom_09_007303_126754, 1_10_PerfectRandom_10_064317_081046, 1_10_PerfectRandom_11_069565_075242, 1_20_Line_08_003103_003102, 1_20_Line_09_002580_002579, 1_20_Line_10_069209_069208, 1_22_BinaryTree_06_000398_000397, 1_23_RandomTree_05_000060_000059, 1_24_SkewTree_04_000069_000068, 1_24_SkewTree_07_000796_000795, 1_24_SkewTree_11_098814_098813, 1_25_Ring_02_001000_001000, 1_25_Ring_03_100000_100000, 1_26_Complete_02_000067_002211, 1_26_Complete_03_000500_124750, 1_27_Random_02_000008_000022, 1_27_Random_04_000039_000581, 1_27_Random_05_000050_000407, 1_27_Random_06_000307_020347, 1_27_Random_07_000551_065255, 1_27_Random_08_006629_062527, 1_27_Random_09_009865_050301, 1_27_Random_10_042323_075720, 1_27_Random_11_043628_107061, 1_30_Island_03_000013_000063, 1_30_Island_04_000094_000093, 1_30_Island_05_000039_000038, 1_30_Island_06_000364_000363, 1_30_Island_07_000951_000952, 1_30_Island_08_005937_005936, 1_30_Island_09_008024_008090, 1_30_Island_10_011040_047244, 1_30_Island_11_046719_053967, 1_30_Island_12_099995_164170, 1_30_Island_13_099996_159191, 1_30_Island_14_099992_157444
Case Name Status Exec Time Memory
0_00_sample_00 AC 34 ms 3244 KB
0_01_Teuchi_01 AC 23 ms 3352 KB
0_10_PerfectRandom_00_000004_000004 AC 23 ms 3348 KB
0_10_PerfectRandom_01_000005_000007 AC 23 ms 3348 KB
0_10_PerfectRandom_02_000009_000013 AC 23 ms 3348 KB
0_21_Star_02_000009_000008 AC 24 ms 3300 KB
0_21_Star_03_000012_000011 AC 23 ms 3224 KB
0_22_BinaryTree_01_000005_000004 AC 24 ms 3180 KB
0_23_RandomTree_00_000004_000003 AC 23 ms 3304 KB
0_25_Ring_00_000003_000003 AC 23 ms 3348 KB
0_25_Ring_01_000020_000020 AC 23 ms 3224 KB
0_26_Complete_00_000004_000006 AC 23 ms 3268 KB
0_26_Complete_01_000005_000010 AC 23 ms 3352 KB
0_27_Random_00_000002_000001 AC 21 ms 3348 KB
0_27_Random_01_000005_000010 AC 23 ms 3352 KB
0_27_Random_03_000013_000013 AC 23 ms 3348 KB
0_30_Island_00_000004_000004 AC 23 ms 3340 KB
0_30_Island_01_000007_000006 AC 23 ms 3216 KB
0_30_Island_02_000009_000008 AC 23 ms 3352 KB
0_40_Corner_00_000010_000020 AC 294 ms 3344 KB
0_40_Corner_01_000021_000020 AC 324 ms 3352 KB
1_01_Teuchi_00 AC 27 ms 4584 KB
1_10_PerfectRandom_03_000013_000021 AC 22 ms 3348 KB
1_10_PerfectRandom_04_000021_000106 AC 24 ms 3288 KB
1_10_PerfectRandom_05_000029_000210 AC 23 ms 3348 KB
1_10_PerfectRandom_06_000236_007490 AC 27 ms 3752 KB
1_10_PerfectRandom_07_000843_061761 AC 54 ms 7464 KB
1_10_PerfectRandom_08_004086_126064 AC 97 ms 11108 KB
1_10_PerfectRandom_09_007303_126754 AC 110 ms 11748 KB
1_10_PerfectRandom_10_064317_081046 AC 253 ms 10408 KB
1_10_PerfectRandom_11_069565_075242 AC 260 ms 9388 KB
1_20_Line_08_003103_003102 AC 36 ms 3624 KB
1_20_Line_09_002580_002579 AC 31 ms 3604 KB
1_20_Line_10_069209_069208 AC 294 ms 12972 KB
1_22_BinaryTree_06_000398_000397 AC 25 ms 3348 KB
1_23_RandomTree_05_000060_000059 AC 23 ms 3348 KB
1_24_SkewTree_04_000069_000068 AC 23 ms 3344 KB
1_24_SkewTree_07_000796_000795 AC 26 ms 3352 KB
1_24_SkewTree_11_098814_098813 AC 394 ms 9756 KB
1_25_Ring_02_001000_001000 AC 27 ms 3476 KB
1_25_Ring_03_100000_100000 AC 407 ms 17580 KB
1_26_Complete_02_000067_002211 AC 25 ms 3436 KB
1_26_Complete_03_000500_124750 AC 110 ms 8620 KB
1_27_Random_02_000008_000022 AC 23 ms 3348 KB
1_27_Random_04_000039_000581 AC 24 ms 3352 KB
1_27_Random_05_000050_000407 AC 23 ms 3344 KB
1_27_Random_06_000307_020347 AC 34 ms 4592 KB
1_27_Random_07_000551_065255 AC 54 ms 6380 KB
1_27_Random_08_006629_062527 AC 78 ms 7592 KB
1_27_Random_09_009865_050301 AC 85 ms 6952 KB
1_27_Random_10_042323_075720 AC 199 ms 9896 KB
1_27_Random_11_043628_107061 AC 248 ms 12200 KB
1_30_Island_03_000013_000063 AC 23 ms 3348 KB
1_30_Island_04_000094_000093 AC 22 ms 3352 KB
1_30_Island_05_000039_000038 AC 23 ms 3344 KB
1_30_Island_06_000364_000363 AC 23 ms 3348 KB
1_30_Island_07_000951_000952 AC 27 ms 3480 KB
1_30_Island_08_005937_005936 AC 44 ms 3564 KB
1_30_Island_09_008024_008090 AC 55 ms 3908 KB
1_30_Island_10_011040_047244 AC 89 ms 6076 KB
1_30_Island_11_046719_053967 AC 196 ms 6700 KB
1_30_Island_12_099995_164170 AC 471 ms 13352 KB
1_30_Island_13_099996_159191 AC 462 ms 13096 KB
1_30_Island_14_099992_157444 AC 469 ms 12972 KB