The NOI ONLINE improve the properties built FIG genomic sequence

Topic Link

  https://www.luogu.com.cn/problem/P6185

The meaning of problems

  It should not be difficult to understand, skip

analysis

  To be honest, when first saw this question I am a bit ignorant, I really do not know how to do, but a look at the data, okay okay, violence could get half the points, so I really took a half points. . . . .

  But some chiefs say the violence could get 60, but I would take half satisfied    I will not ah

  This question can not help but wonder how to do after the exam, so he looked at the solution to a problem, problem solution is also found. . . A little difficult to understand, mainly because I see a word, chart? ? This is clearly a number of issues and also how to link the relationship, awsl, I really still too       

     Carefully read it, I understand some of it. A look Operation: if (a1, a2) (a2, a3) (a3, a1), any of a number can then subtract their two, such as a1, a1 + 1, a2 + 1, a2-1, a3-1, a3 + 1, a1 + 1 a1 so you can make your own plus or minus two, empathy a1 replaced by any number can be, here to note that you must be an odd number of points and form a ring in order to do so, so each on the odd number can add and subtract Second, why not own an even number of points for example to understand. Look Operation II: if (a1, a2) (a2, a3) you know (a1, a3), a1 + 1, a2-1, a2 + 1, a3-1 Accordingly, a1 + 1, a3- 1, showing operation of the second is transitive, if they are seen as a link block, the block may be arbitrarily added to a China Unicom, minus 1, so if the need to add a link block and a value of the need to reduce the same, then satisfied. So we just put each operation are shrunk to two points, each operating a construction side, and then began to judge each block Unicom is not satisfied meaning of the questions.

A method for the determination, if the ring is not formed in an odd number, it is necessary to sum the number of blocks is equal to the subtraction Unicom number, because only a plus minus one, otherwise, the total number required to change is an even number, also noted loopback to determine, because since ring corresponds to (a1, a2,1) (a1, a2,2) i.e. a1 + 1, a2 + 1, a2-1, a1 + 1, so also enable any number subtraction two,

Then there is no edge for even the points, only need to change a value of 0, only to meet, because there is no side can make a difference.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int N=2e5+10;
 6 long long val[N];
 7 struct Edge{
 8     int to,next;
 9 }e[N];
10 struct Node{
11     int t,u,v;
12 }p[N];
13 int Head[N],len,sum,flag;
14 void Ins(int a,int b){
15     e[++len].to=b;e[len].next=Head[a];Head[a]=len;
16 }
17 int f[N],belong[N],a[N],b[N];
18 int find(int x){
19     return f[x]==x?x:(f[x]=find(f[x]));
20 }
21 void Mer(int a,int b){
22     int u=find(a),v=find(b);
23     if(u!=v){
24         f[u]=v;val[v]+=val[u];//并查集缩点
25     }
26 }
27 voidDFS ( int X, int bin) {
 28      belong [X] = bin;
 29      IF (bin) SUM + = Val [X];
 30      the else sum- = Val [X];
 31 is      for ( int I = Head [X]; I; I = E [I] .next) {
 32          int V = E [I] .to;
 33 is          IF (belong [V] == - . 1 ) DFS (V, ^ bin . 1 ); // use of the ^ properties 
34 is          the else  IF (belong [x] == belong [v]) // Description v have been visited earlier and the value of x as the bin, then it must be formed of the odd 
35              in Flag = . 1 ;
 36     }
37 }
38 int main(){
39 //    freopen("a.txt","r",stdin);
40     int t;
41     scanf("%d",&t);
42     while(t--){
43         int m,n,ans=1;len=0;
44         scanf("%d%d",&n,&m);
45         for(int i=1;i<=n;i++)
46             scanf("%d",&a[i]);
47         for(int i=1;i<=n;i++)
48             scanf("%d",&b[i]),val[i]=b[i]-a[i];
49         for(int i=1;i<=n;i++)
50             f[i]=i,belong[i]=-1,Head[i]=0;
51         for(int i=1;i<=m;i++){
52             scanf("%d%d%d",&p[i].t,&p[i].u,&p[i].v);
53             IF (P [I] .T == 2 ) {
 54 is                  Mer (P [I] .u, P [I] .v); // merge operation two 
55              }
 56 is          }
 57 is          for ( int I = . 1 ; I < m =; I ++ ) {
 58              IF (P [I] == .T . 1 ) {
 59                  lns (Find (P [I] .u), Find (P [I] .v)); // this point has been reduced so to merge the root 
60                  lns (Find (P [I] .v), Find (P [I] .u));
 61 is              }
 62 is          }
 63 is          for ( int I = . 1 ; I <= n-; I ++ ) {
64             if(find(i)==i&&belong[i]==-1){
65                 flag=sum=0;
66                 dfs(i,0);
67                 for(int x=Head[i];x;x=e[x].next){
68                     if(e[x].to==i)flag=1;//自环
69                 }
70                 if(Head[i]==0&&sum!=0)ans=0;//没有边连入
71                 else if(flag==1&&sum%2!=0 ) ANS = 0 ; // the odd 
72                  the else  IF (In Flag == 0 ! && SUM = 0 ) ANS = 0 ; // even-ring 
73 is              }
 74          }
 75          IF (ANS) the printf ( " YES \ n- " );
 76          the else the printf ( " NO \ n- " );
 77      }
 78 }

 

Guess you like

Origin www.cnblogs.com/anyixing-fly/p/12438806.html