1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std;
typedef long long LL;
const int maxn=1e5+5;
int n,a[maxn][4],m; pair<pair<int,int>,pair<int,int>> ans[maxn];
int main() { scanf("%d",&n); fo(j,1,3) fo(i,1,n) scanf("%d",&a[i][j]); int cnt=0, w1, w2; fo(i,1,n) if (a[i][1]==a[i][2] && a[i][1]==a[i][3]) { ans[++m]=make_pair(make_pair(i,a[i][1]),make_pair(i,a[i][1]^1)); } else { bool idp=1; fo(j,1,i-1) if (a[i][1]==a[j][1] && a[i][2]==a[j][2] && a[i][3]==a[j][3]) { idp=0; ans[++m]=make_pair(make_pair(j,0),make_pair(i,0)); ans[++m]=make_pair(make_pair(j,1),make_pair(i,1)); break; } else if (a[i][1]!=a[j][1] && a[i][2]!=a[j][2] && a[i][3]!=a[j][3]) { idp=0; ans[++m]=make_pair(make_pair(j,0),make_pair(i,1)); ans[++m]=make_pair(make_pair(j,1),make_pair(i,0)); break; } if (idp) { ++cnt; if (cnt==1) w1=i; else w2=i; } } if (cnt!=2) puts("-1"); else { int df; if (a[w1][1]!=a[w1][2] && a[w1][1]!=a[w1][3]) df=1; else if (a[w1][2]!=a[w1][1] && a[w1][2]!=a[w1][3]) df=2; else df=3; ans[++m]=make_pair(make_pair(w1,a[w1][df]^1),make_pair(w2,a[w2][df]^1)); printf("%d\n",m); fo(i,1,m) { if (ans[i].first.second) putchar('!'); printf("x%d -> ",ans[i].first.first); if (ans[i].second.second) putchar('!'); printf("x%d\n",ans[i].second.first); } } }
|