杭电7- Link with Limit

传送门

思路:

dfs寻找所有的环的平均值。

#include<cstdio>
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
double a[100010];
int vis[100010];
double sum[100010];
int cnt = 0,flag = 0;
double ans = 0;
void dfs(int x)
{
	if(vis[x]==0 && flag==0)
	{
		vis[x]=1;
		dfs(a[x]);
	}
	else
	{
		if(vis[x]==2)
		{
			flag = -1;
			cnt--;
			return;
		}
		flag = x;
		ans++;
		sum[cnt]+=a[x];
		vis[x]=2;
		return;
	}
	if(flag>0)
	{
		vis[x]=2;
		if(flag==x)
		{
			sum[cnt]/=ans;
			flag = -1;
			return;
		}
		else
		{
			ans++;
			sum[cnt]+=a[x];
		}
	}
	else
	{
		vis[x]=2;
		return;
	}
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cnt = 0;
		memset(vis,0,sizeof(vis));
		memset(sum,0,sizeof(sum));
		memset(a,0,sizeof(a));
		int n;
		cin>>n;
		for(int i = 1; i <= n; i++)
		{
			scanf("%lf",&a[i]);
		}
		for(int i = 1; i <= n; i++)
		{
			ans = flag = 0;
			if(!vis[i])
			{
				cnt++;
				dfs(i);
			}
		}
		int f = 0;
		for(int i = 2; i <= cnt; i++)
		{
			if(sum[i] != sum[i-1])
			{
				f=1;
				break;
			}
		}
		f?printf("NO\n"):printf("YES\n");
	}
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Internetworking IPv6 with Cisco Routers 想要学习IPv6的,这本书我觉得真的很好,希望大家都可以看看。 先贴一个目录给大家看看: Chapter 1: Introduction Overview, Why IPv6, Why a new address scheme, Best Effort: is it enough, Requisites to be satisfied by IPv6, An address space to last, To unify Intranets and the Internet, A good support for ATM, Plug and play, Mobility, Transition from IPv4 to IPv6, Choice criteria, The path toward standardization. Chapter 2: An overview on IPv6 Terminology, The Architecture of an IPv6 network, Addresses and names, Router and Internetworking, Layer 2 and layer 3 addresses, Neighbor Discovery, Encapsulation of IPv6 on LANs, Impact of IPv6 on upper layers, Modifications to sockets, Domain Name Service (DNS) modifications, DHCP servers. Chapter 3: IPv6 Headers The IPv6 header, Version, Priority, Flow Label, Payload Length, Next Header, Hop Limit, Source Address, Destination Address, Examples of IPv6 packets, Extension Header, Hop-by-Hop Option Header, The Jumbo Payload option, Routing Header, Fragment Header, The fragmentation process, Destination Options Header, Security Header, Size of IPv6 packets. Chapter 4: IPv6 Addresses The addressing space, Syntax of IPv6 addresses, Types of IPv6 addresses, The addressing model, Assignment of IPv6 addresses, Unicast Addresses, Anycast Addresses, Multicast Addresses, Pre-defined multicast Addresses, Addresses of an host, Addresses of a router. Chapter 5: ICMPv6 Protocol overview, Packets format. ICMP messages transmission, Destination unreachable, Packet too big, Time exceeded, Parameter problems, Echo request, Echo response, Group membership, Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement, Redirect, Options format, Link Layer Address Source/Target Option, Information on Prefixes Option, Redirect Header, MTU Option. Chapter 6: Neighbor Discovery Link types, Neighbor Discovery service, Router and prefix discovery, The address resolution, Redirect function, Data structures of an host, Neighbor Cache, Destination Cache, Prefix List, Default Router List, An example of cache, Transmission algorithm of a packet, Neighbor Unreachability Detection, Address Autoconfiguration, Stateless autoconfiguration, DHCPv6 and the stateful autoconfiguration, Duplicate Address Detection, IPv6 on Ethernet. Chapter 7: The Routing in Ipv6 Network model, Routing algorithms, Static Routing, Metrics, Distance vector, Path vector, Link state, Redistribution, Multi-protocol routing, RIPv6, OSPFv6, IDRPv6, BGP4+, Relations between addressing and routing, Internet structure, Multihomed routing domains, Tunnels, Private links, Multicast Routing, Intranets. Chapter 8: Security in IPv6 Security functions, Authentication Header (AH), Authentication methodology, Encrypted Security Payload (ESP), Encryption keys distribution, Manual keys distribution, Automatic keys distribution, Applications of IPv6 security functions, Private Virtual Networks, Application Layer security, Routing security. Chapter 9: IPv6 on ATM LLC/SNAP encapsulation, VC multiplexing, AAL 5, Neighbor Discovery, Addresses Auto-configuration, ICMP Redirect, MARS (Multicast Address Resolution Server), NHRP (Next Hop Resolution Protocol), Alternative approaches, IP Switching, Tag Switching. Chapter 10: The mobility in Ipv6 Mobility problems, Introduction to host mobility in IPv6, Examples of operation of a mobile host in IPv6, Binding Update option, Binding Acknowledgment option, Binding Request option, Characteristics of nodes, Routers Requisites, Mobile nodes Requisites, Transmission of packets to a mobile node, Mobility detection, Multicast traffic handling, At home again. Chapter 11: IPv6 and multimedia traffic Introduction, Integrated Services model, Coding of multimedia information, Reference Implementation, Traffic control, Packet scheduler, Buffers management, Packets classification, Access control, RSVP, Flowspec and Filterspec, Reservation styles, The Soft State Approach, Reservations and routing, Integrated Services in an IP over ATM architecture. Chapter 12: The migration from IPv4 to IPv6 Tunneling, Alternative tunneling schemes, IPv6 Addresses with Embedded IPv4 Addresses, MTU, Hop Limit, Default configured tunnel, Dual Stack Approach, The 6bone, The 6bone node at Cisco Systems, Registration to RIPE-NCC. Chapter 13: Cisco Systems and IPv6 Cisco Systems, the premier IP vendor, is committed to the evolution of the Internet/Intranets and considers the next generation IP to be a key component of their growth. It has taken a leadership role in both the definition and implementation of the IPv6 protocols within the IETF and within its IOSTM software. This chapter describes the approach of Cisco System to IPv6 and how IPv6 is integrated in IOS. It contains an example of a 6bone backbone node running IPv6 on a Cisco router, with the IOSTM configuration file, the explanation of principal IPv6 IOSTM commands, the addressing plan and additional features, suvh as BGP4+ and NAT. Appendix A: Excerpts from RFC Routing header: pseudo code, Example of Routing header processing, Processing of ICMPv6 packets, Addresses to be used during the testing phase, MTU of a tunnel and fragmentation, Transmission of IP packets. Appendix B: Analysis of IPv6 packets This appendix contains example of decoding of IPv6 packets using a Radcom RC-100 WL protocol analyzer. Decoded packets are TCP, UDP, Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement Packets. Appendix C: How to receive more information Author's address, Author's WWW address, Mailing list, Where you can find RFCs and Internet Drafts, The Playground server, The 6bone, Other WWW servers. Appendix D: Glossary

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值