国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
題目大意:
解法:
代碼:
Home Web Front-end HTML Tutorial codeforces Round #259(div2) EProblem Solution Report_html/css_WEB-ITnose

codeforces Round #259(div2) EProblem Solution Report_html/css_WEB-ITnose

Jun 24, 2016 am 11:55 AM

E. Little Pony and Summer Sun Celebration

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration.

Twilight Sparkle wanted to track the path of Nightmare Moon. Unfortunately, she didn't know the exact path. What she knew is the parity of the number of times that each place Nightmare Moon visited. Can you help Twilight Sparkle to restore any path that is consistent with this information?

Ponyville can be represented as an undirected graph (vertices are places, edges are roads between places) without self-loops and multi-edges. The path can start and end at any place (also it can be empty). Each place can be visited multiple times. The path must not visit more than?4n?places.

Input

The first line contains two integers?n?and?m?(2?≤?n?≤?105;?0?≤?m?≤?105) ? the number of places and the number of roads in Ponyville. Each of the following?m?lines contains two integers?ui,?vi?(1?≤?ui,?vi?≤?n;?ui?≠?vi), these integers describe a road between places?ui?and?vi.

The next line contains?n?integers:?x1,?x2,?...,?xn?(0?≤?xi?≤?1)?? the parity of the number of times that each place must be visited. If?xi?=?0, then the?i-th place must be visited even number of times, else it must be visited odd number of times.

Output

Output the number of visited places?k?in the first line (0?≤?k?≤?4n). Then output?k?integers ? the numbers of places in the order of path. Ifxi?=?0, then the?i-th place must appear in the path even number of times, else?i-th place must appear in the path odd number of times. Note, that given road system has no self-loops, therefore any two neighbouring places in the path must be distinct.

If there is no required path, output?-1. If there multiple possible paths, you can output any of them.

Sample test(s)

input

3 21 22 31 1 1

output

31 2 3

input

5 71 21 31 41 53 43 54 50 1 0 1 0

output

102 1 3 4 5 4 5 4 3 1 

input

2 00 0

output

題目大意:

給出一張圖,有N個點,M條邊,并給出每個點要求訪問次數(shù)的奇偶性。,要求輸出訪問路徑。

解法:

首先我們可以明確一點,這就是一個圖的遍歷,找一個點,設(shè)為起點,建立一個搜索遍歷樹,對于樹每一個點,我們完全可以控制奇偶性,假設(shè):

? ? ? ?目前訪問的點為v,父節(jié)點為fa,如若點v不符合當前的奇偶性,則就讓父節(jié)點到v繞一次,這樣 odd[v] ^= 1, fa[v] ^= 1,這樣我們可以完全保證完全控制子節(jié)點,將不符合要求的奇偶性調(diào)整成符合要求的奇偶性。同時父節(jié)點的奇偶性也在改變。

? ? ? ?通過上述的操作,我們可以每次保證子節(jié)點的奇偶性符合要求,然而父節(jié)點的奇偶性如若不符合要求,則可以通過調(diào)整父節(jié)點 與 父節(jié)點的父節(jié)點來調(diào)整奇偶性,這樣我們就可以奇偶性傳遞,最終傳遞到根節(jié)點。根節(jié)點如若不符合該如何調(diào)整呢?由于我們是走遍歷樹,到達葉節(jié)點還要回來的,意味著我們要走至少兩次根節(jié)點,一次是出發(fā),一次是最后一次回歸。我們可以將根節(jié)點 r1 調(diào)整到根節(jié)點的其中一個子節(jié)點r2,使得奇偶性再次得到調(diào)整

代碼:

#include <cstdio>#include <vector>#define N_max 123456using namespace std;int n, m, fa[N_max], want[N_max];int Odd_n, Odd_x, haveOdd[N_max];vector <int> G[N_max], ans;int getf(int x) {	return (fa[x] == x) ? x : fa[x] = getf(fa[x]);}void addedge(int x, int y) {	G[x].push_back(y);}void init() {	scanf("%d%d", &n, &m);	for (int i = 1; i <= n; i++)  fa[i] = i;	for (int i = 1; i <= m; i++) {		int x, y;		scanf("%d%d", &x, &y);		int tmpx=getf(x);		int tmpy=getf(y);		if (tmpx != tmpy) {			fa[tmpx] = tmpy;			addedge(x, y);			addedge(y, x);		}	}	for (int i = 1; i <= n; i++) {		scanf("%d", &want[i]);		if (want[i])  haveOdd[getf(i)] = 1;	}	for (int i = 1; i <= n; i++)		if (haveOdd[i]) {			Odd_n++;			Odd_x = i;		}}void dfs(int now, int pre) {	ans.push_back(now);	want[now] ^= 1;	for (int i = 0; i < G[now].size(); i++) {		int nex = G[now][i];		if (nex == pre)  continue;		dfs(nex, now);		ans.push_back(now);		want[now] ^= 1;		if (want[nex]) {			ans.push_back(nex);			want[nex] ^= 1;			ans.push_back(now);			want[now] ^= 1;		}	}}void solve() {	if (Odd_n == 0) {		printf("0\n");		return;	}	if (Odd_n > 1) {		printf("-1\n");		return;	}	dfs(Odd_x, -1);	int x = 0;	if (want[Odd_x])  x=1;	printf("%d\n", ans.size() - x);	for (int i = x; i < ans.size(); i++)		printf("%d ", ans[i]);}int main() {	init();	solve();}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
Configuring Document Metadata Within the HTML head Element Configuring Document Metadata Within the HTML head Element Jul 09, 2025 am 02:30 AM

Metadata in HTMLhead is crucial for SEO, social sharing, and browser behavior. 1. Set the page title and description, use and keep it concise and unique; 2. Add OpenGraph and Twitter card information to optimize social sharing effects, pay attention to the image size and use debugging tools to test; 3. Define the character set and viewport settings to ensure multi-language support is adapted to the mobile terminal; 4. Optional tags such as author copyright, robots control and canonical prevent duplicate content should also be configured reasonably.

Best HTML tutorial for beginners in 2025 Best HTML tutorial for beginners in 2025 Jul 08, 2025 am 12:25 AM

TolearnHTMLin2025,chooseatutorialthatbalanceshands-onpracticewithmodernstandardsandintegratesCSSandJavaScriptbasics.1.Prioritizehands-onlearningwithstep-by-stepprojectslikebuildingapersonalprofileorbloglayout.2.EnsureitcoversmodernHTMLelementssuchas,

HTML for email templates tutorial HTML for email templates tutorial Jul 10, 2025 pm 02:01 PM

How to make HTML mail templates with good compatibility? First, you need to build a structure with tables to avoid using div flex or grid layout; secondly, all styles must be inlined and cannot rely on external CSS; then the picture should be added with alt description and use a public URL, and the buttons should be simulated with a table or td with background color; finally, you must test and adjust the details on multiple clients.

What are the most commonly used global attributes in html? What are the most commonly used global attributes in html? Jul 10, 2025 am 10:58 AM

class, id, style, data-, and title are the most commonly used global attributes in HTML. class is used to specify one or more class names to facilitate style setting and JavaScript operations; id provides unique identifiers for elements, suitable for anchor jumps and JavaScript control; style allows for inline styles to be added, suitable for temporary debugging but not recommended for large-scale use; data-properties are used to store custom data, which is convenient for front-end and back-end interaction; title is used to add mouseover prompts, but its style and behavior are limited by the browser. Reasonable selection of these attributes can improve development efficiency and user experience.

How to handle forms submission in HTML without a server? How to handle forms submission in HTML without a server? Jul 09, 2025 am 01:14 AM

When there is no backend server, HTML form submission can still be processed through front-end technology or third-party services. Specific methods include: 1. Use JavaScript to intercept form submissions to achieve input verification and user feedback, but the data will not be persisted; 2. Use third-party serverless form services such as Formspree to collect data and provide email notification and redirection functions; 3. Use localStorage to store temporary client data, which is suitable for saving user preferences or managing single-page application status, but is not suitable for long-term storage of sensitive information.

Implementing Native Lazy Loading for Images in HTML Implementing Native Lazy Loading for Images in HTML Jul 12, 2025 am 12:48 AM

Native lazy loading is a built-in browser function that enables lazy loading of pictures by adding loading="lazy" attribute to the tag. 1. It does not require JavaScript or third-party libraries, and is used directly in HTML; 2. It is suitable for pictures that are not displayed on the first screen below the page, picture gallery scrolling add-ons and large picture resources; 3. It is not suitable for pictures with first screen or display:none; 4. When using it, a suitable placeholder should be set to avoid layout jitter; 5. It should optimize responsive image loading in combination with srcset and sizes attributes; 6. Compatibility issues need to be considered. Some old browsers do not support it. They can be used through feature detection and combined with JavaScript solutions.

How to add a video as a background in HTML? How to add a video as a background in HTML? Jul 08, 2025 am 12:03 AM

To add a video background to a web page, the key is to use HTML tags correctly and optimize relevant attributes. 1. Use tags as background and use CSS positioning to fill the page or local area; 2. The video format is preferred.mp4, and WebM is added to consider compatibility; 3. Add muted and playsinline attributes to ensure automatic playback on the mobile side; 4. Control the video size to optimize the loading speed, and it is recommended to keep it at tens of MB; 5. Add loops to achieve seamless loop playback; 6. It can be flexibly applied to full screen or local blocks, and different effects are achieved by adjusting the container size and positioning method. The above steps can achieve a stable and beautiful video background.

How to make a responsive iframe? How to make a responsive iframe? Jul 09, 2025 am 01:39 AM

To make iframes responsive, the core is to use CSS to control the aspect ratio and combine it with the wrapping container to achieve adaptation. 1. Use padding techniques to create container boxes with fixed proportions. Common ratios such as 16:9 correspond to padding-top56.25%, 4:3 correspond to 75%, and 1:1 correspond to 100%; 2. Set the iframe width to 100% and use absolute positioning to fill the container, or use the aspect-ratio attribute to maintain the proportion; 3. When processing third-party embedded content, control the ratio through container wrapping, and ensure that the allowfullscreen attribute is added to support full-screen playback on mobile terminals. Master the container and proportion settings to realize the responsiveness of the iframe

See all articles