CF Question Collection PART 5 #266 div 2 E_html/css_WEB-ITnose
【原题】
E. Information Graph
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:
Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.
Input
The first line contains two integers n and m (1?≤?n,?m?≤?105) ? the number of employees and the number of events.
Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1?≤?t?≤?3).
It is guaranteed that the input has at least one query of the third type.
Output
For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.
Sample test(s)
input
4 91 4 32 43 3 11 2 32 23 1 21 3 12 23 1 3
output
YESNOYES
【题意】意思看了半天~就是有N个人,M个操作。每次操作有3种。
①把x的父亲置为y。
②从x开始发新的一份文件(是从1开始标号的)。从x开始,一直传递到最远的祖先。
③询问x号文件有没有落到y的手里。
【分析】即要简单地判断y是否是x的祖先。一开始有思维定势,觉得要求一遍LCA。但是后来想了想,可以直接用DFS序搞出同一棵树的深度,再用并查集维护是否在同一棵树上。代码很简单。
【代码】
#include<cstdio>#include<vector>#define N 200005#define pb push_backusing namespace std;vector<int>son[N],ask[N];struct arr{int x,y,id,opt;}a[N];int f[N],L[N],R[N],fa[N],ans[N];int i,n,m,now,num,id,tot,P,j;inline int get(int u){return f[u]==u?f[u]:f[u]=get(f[u]);}void dfs(int k){ L[k]=++tot; for (int i=0;i<son[k].size();i++) dfs(son[k][i]); R[k]=tot;}int main(){ scanf("%d%d",&n,&m); for (i=1;i<=m;i++) { scanf("%d%d",&a[i].opt,&a[i].x);a[i].id=i; if (a[i].opt!=2) scanf("%d",&a[i].y); if (a[i].opt==1) son[a[i].y].pb(a[i].x),fa[a[i].x]=1; if (a[i].opt==3) ask[a[i].y].pb(a[i].id); } for (i=1;i<=n;i++) if (!fa[i]) dfs(i); for (i=1;i<=n;i++) f[i]=i;now=0; for (i=1;i<=m;i++) { if ((P=a[i].opt)==1) {f[get(a[i].x)]=get(a[i].y);continue;} if (P==3) {puts(ans[i]?"YES":"NO");continue;}now++; for (j=0;j<ask[now].size();j++) { id=ask[now][j];num=a[id].x; if (get(num)==get(a[i].x)&&L[num]<=L[a[i].x]&&R[num]>=R[a[i].x]) ans[id]=1; } }}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Mouse macros assign a series of complex operations to the mouse buttons, which can be simply understood as mouse shortcut key settings. After clicking the button to set the mouse macro, you can complete some operations that are usually impossible to do. So how to set mouse macros when playing CF? Let’s take a look at the cf Logitech mouse macro setting tutorial. 1. First, install the Logitech game software on your computer, and then click as shown by the arrow in the picture to open the custom button setting interface. Next, you need to select a key, such as the left key, click the small arrow, and then select "Edit Command" in the pop-up menu, so that you can open the left key macro setting interface. 3. Then click the button, as shown by the red arrow in the picture, click the text box and enter any key. Note that such as A

CSS method to realize that a div is missing a corner: 1. Create an HTML sample file and define a div; 2. Set the width and height background color for the div; 3. Add a pseudo class to the div that needs to delete a corner, and set the pseudo class to Use the same color as the background color, then rotate it 45 degrees, and then position it to the corner that needs to be removed.

The difference between iframe and div is that iframe is mainly used to introduce external content, which can load content from other websites or divide a web page into multiple areas. Each area has its own independent browsing context, while div is mainly used to divide and organize content. block for layout and style control.

Preface Recently, there is a browser script based on ChatGPTAPI on GitHub, openai-translator. In a short period of time, the star has reached 12k. In addition to supporting translation, it also supports polishing and summarizing functions. In addition to browser plug-ins, it also uses tauri packaging. If you have a desktop client, aside from the fact that tauri uses the rust part, the browser part is still relatively simple to implement. Today we will implement it manually. The interface provided by openAI, for example, we can copy the following code and initiate a request in the browser console to complete the translation //Example constOPENAI_API_KEY="s

The div box model is a model used for web page layout. It treats elements in a web page as rectangular boxes. This model contains four parts: content area, padding, border and margin. The advantage of the div box model is that it can easily control the layout of the web page and the spacing between elements. By adjusting the size of the content area, inner margin, border and outer margin, various layout effects can be achieved. The box model also provides some Properties and methods can dynamically change the style and behavior of the box through CSS and JavaScript.

The differences are: 1. div is a block-level element, and span is an inline element; 2. div will automatically occupy a line, while span will not automatically wrap; 3. div is used to wrap larger structures and layouts, and span is used to wrap Text or other inline elements; 4. div can contain other block-level elements and inline elements, and span can contain other inline elements.

Adjustment steps: 1. On the Win10 system desktop, right-click the start button and select "Settings"; 2. Click the "System" icon; 3. Click the "Display" menu item in the left sidebar; 4. Click "Display Adapter" on the right Properties" shortcut link; 5. Click the "List all modes" button; 6. Select "1024*768 True Color 60 Hz" from all modes; 7. Click the "Monitor" label above and set it to 60 Hz; 8. Click "OK" and then restart the computer.

The methods are: 1. Set the two div elements to the "float:left;" attribute; 2. Use CSS's flex layout to easily display elements side by side; 3. Use CSS's grid layout to also display elements side by side.
