PAT_A1076#Forwards on Weibo

Source:

PAT A1076 Forwards on Weibo (30 分)

Description:

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers are counted.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤), the number of users; and L (≤), the number of levels of indirect followers that are counted. Hence it is assumed that all the users are numbered from 1 to N. Then N lines follow, each in the format:

M[i] user_list[i]

where M[i] (≤) is the total number of people that user[i] follows; and user_list[i] is a list of the M[i] users that followed by user[i]. It is guaranteed that no one can follow oneself. All the numbers are separated by a space.

Then finally a positive K is given, followed by UserID's for query.

Output Specification:

For each UserID, you are supposed to print in one line the maximum potential amount of forwards this user can trigger, assuming that everyone who can view the initial post will forward it once, and that only L levels of indirect followers are counted.

Sample Input:

7 3
3 2 3 4
0
2 5 6
2 3 1
2 3 4
1 4
1 5
2 2 6

Sample Output:

4
5

Keys:

Attention:

  • 题目给的是关注列表,消息传播时的方向应该是相反的;
  • 有关层数的要用宽搜,刚开始直接用深搜去解了,答案居然还是对的,出题老师也是很心机-,-

Code:

 1 /*
 2 Data: 2019-06-20 16:47:58
 3 Problem: PAT_A1076#Forwards on Weibo
 4 AC: 15:23
 5 
 6 题目大意:
 7 在微博上,当一位用户发了一条动态,关注他的人可以查看和转发这条动态;
 8 现在你需要统计出某条动态最多可以被转发的次数(转发层级不超过L)
 9 输入:
10 第一行给出,人数N<=1e3(编号从1~N),转发层级L<=6
11 接下来N行,用户i关注的总人数W[i]及其各个编号
12 接下来一行,给出查询次数K,和要查询的各个编号
13 输出;
14 L层级内可获得的最大转发量
15 
16 基本思路:
17 层次遍历
18 */
19 #include<cstdio>
20 #include<queue>
21 #include<vector>
22 #include<algorithm>
23 using namespace std;
24 const int M=1e3+10,INF=1e9;
25 int vis[M],layer[M],L,n;
26 vector<int> adj[M];
27 
28 int BFS(int u)
29 {
30     fill(vis,vis+M,0);
31     fill(layer,layer+M,1);
32     queue<int> q;
33     q.push(u);
34     vis[u]=1;
35     int sum=0;
36     while(!q.empty())
37     {
38         u = q.front();
39         q.pop();
40         if(layer[u] > L)
41             return sum;
42         for(int i=0; i<adj[u].size(); i++){
43             if(vis[adj[u][i]]==0){
44                 vis[adj[u][i]]=1;
45                 q.push(adj[u][i]);
46                 layer[adj[u][i]]=layer[u]+1;
47                 sum++;
48             }
49         }
50     }
51     return sum;
52 }
53 
54 int main()
55 {
56 #ifdef ONLINE_JUDGE
57 #else
58     freopen("Test.txt", "r", stdin);
59 #endif // ONLINE_JUDGE
60 
61     int k,v;
62     scanf("%d%d", &n,&L);
63     for(int i=1; i<=n; i++)
64     {
65         scanf("%d", &k);
66         for(int j=0; j<k; j++)
67         {
68             scanf("%d", &v);
69             adj[v].push_back(i);
70         }
71     }
72     scanf("%d", &k);
73     while(k--)
74     {
75         scanf("%d", &v);
76         printf("%d\n", BFS(v));
77     }
78 
79     return 0;
80 }

 

转载于:https://www.cnblogs.com/blue-lin/p/10890553.html

#ifndef _SIP_PROTOCOL_H #define _SIP_PROTOCOL_H #include "common/sip_common.h" /* SIP方法定义 */ typedef enum sip_method { SIP_METHOD_INVITE = 0, SIP_METHOD_ACK, SIP_METHOD_BYE, SIP_METHOD_CANCEL, SIP_METHOD_REGISTER, SIP_METHOD_OPTIONS, SIP_METHOD_MAX }sip_method; /* SIP响应状态码 */ /* SIP响应状态码枚举 (RFC 3261及相关扩展) */ typedef enum sip_status_code { /* 1xx 临时响应 */ SIP_100_TRYING = 100, SIP_180_RINGING = 180, SIP_181_CALL_IS_BEING_FORWARDED = 181, SIP_182_QUEUED = 182, SIP_183_SESSION_PROGRESS = 183, /* 2xx 成功响应 */ SIP_200_OK = 200, SIP_202_ACCEPTED = 202, // RFC3265 /* 3xx 重定向响应 */ SIP_300_MULTIPLE_CHOICES = 300, SIP_301_MOVED_PERMANENTLY = 301, SIP_302_MOVED_TEMPORARILY = 302, SIP_305_USE_PROXY = 305, SIP_380_ALTERNATIVE_SERVICE = 380, /* 4xx 客户端错误 */ SIP_400_BAD_REQUEST = 400, SIP_401_UNAUTHORIZED = 401, SIP_402_PAYMENT_REQUIRED = 402, SIP_403_FORBIDDEN = 403, SIP_404_NOT_FOUND = 404, SIP_405_METHOD_NOT_ALLOWED = 405, SIP_406_NOT_ACCEPTABLE = 406, SIP_407_PROXY_AUTHENTICATION_REQUIRED = 407, SIP_408_REQUEST_TIMEOUT = 408, SIP_410_GONE = 410, SIP_413_REQUEST_ENTITY_TOO_LARGE = 413, SIP_414_REQUEST_URI_TOO_LONG = 414, SIP_415_UNSUPPORTED_MEDIA_TYPE = 415, SIP_416_UNSUPPORTED_URI_SCHEME = 416, SIP_420_BAD_EXTENSION = 420, SIP_421_EXTENSION_REQUIRED = 421, SIP_423_INTERVAL_TOO_BRIEF = 423, SIP_480_TEMPORARILY_UNAVAILABLE = 480, SIP_481_CALL_TRANSACTION_DOES_NOT_EXIST = 481, SIP_482_LOOP_DETECTED = 482, SIP_483_TOO_MANY_HOPS = 483, SIP_484_ADDRESS_INCOMPLETE = 484, SIP_485_AMBIGUOUS = 485, SIP_486_BUSY_HERE = 486, SIP_487_REQUEST_TERMINATED = 487, SIP_488_NOT_ACCEPTABLE_HERE = 488, SIP_489_BAD_EVENT = 489, // RFC3265 SIP_491_REQUEST_PENDING = 491, SIP_493_UNDECIPHERABLE = 493, /* 5xx 服务器错误 */ SIP_500_SERVER_INTERNAL_ERROR = 500, SIP_501_NOT_IMPLEMENTED = 501, SIP_502_BAD_GATEWAY = 502, SIP_503_SERVICE_UNAVAILABLE = 503, SIP_504_SERVER_TIME_OUT = 504, SIP_505_VERSION_NOT_SUPPORTED = 505, SIP_513_MESSAGE_TOO_LARGE = 513, /* 6xx 全局错误 */ SIP_600_BUSY_EVERYWHERE = 600, SIP_603_DECLINE = 603, SIP_604_DOES_NOT_EXIST_ANYWHERE = 604, SIP_606_NOT_ACCEPTABLE = 606 } sip_status_code; /* SIP URI结构 */ typedef struct sip_uri { char scheme[8]; /* "sip" or "sips" */ char user[32]; /* username */ char host[32]; /* domain or IP */ U16 port; /* port number */ char parameters[32]; /* URI parameters */ }sip_uri; /* SIP Via头结构 */ typedef struct sip_via { char protocol[16]; /* "SIP/2.0" */ char transport[8]; /* "UDP", "TCP" */ char host[64]; /* sent-by host */ U16 port; /* sent-by port */ char branch[32]; /* branch parameter */ char received[32]; /* received parameter */ U16 rport; /* rport parameter */ }sip_via; /* 认证信息结构体 */ typedef struct auth_info_t{ char realm[128]; char nonce[128]; char algorithm[32]; char qop[32]; char opaque[128]; int stale; char response[33]; } auth_info_t; /* SIP消息头结构 */ typedef struct sip_headers { struct sip_uri from; /* From header */ struct sip_uri to; /* To header */ struct sip_uri request_uri; /* Request-URI */ struct sip_via via; /* Via header */ char call_id[64]; /* Call-ID header */ U32 cseq; /* CSeq number */ enum sip_method cseq_method;/* CSeq method */ U8 max_forwards; /* Max-Forwards header */ char content_type[64]; /* Content-Type header */ char contact[64]; U32 content_length; /* Content-Length header */ U32 Expires; char user_agent[64]; /* User-Agent header */ auth_info_t auth; }sip_headers; /* SIP消息体结构 */ typedef struct sip_body { char *content; /* Message body content */ U32 length; /* Message body length */ char type[32]; /* Content type */ }sip_body; /* SIP消息结构 */ typedef struct sip_message { U8 type; /* 0: request, 1: response */ enum sip_method method;/* Method (for requests) */ U16 status_code; /* Status code (for responses) */ char reason_phrase[32];/* Reason phrase (for responses) */ struct sip_headers headers; /* SIP headers */ struct sip_body body; /* Message body */ char *raw_data; /* Raw message data */ U32 raw_length; /* Raw message length */ struct sockaddr_in source; /* Message source */ struct list_head list; /* List head for message queue */ }sip_message; /* SIP事务信息 */ typedef struct sip_transaction { char branch[32]; /* Transaction branch */ enum sip_method method; /* Transaction method */ U32 timeout; /* Transaction timeout */ unsigned long start_time; /* Start time in jiffies */ struct sip_message request; /* Original request */ struct sip_message last_response; /* Last response */ void *user_data; /* User-specific data */ U8 state; /*0,off,1 on*/ }sip_transaction; /* 协议栈配置 */ typedef struct sip_protocol_config { char user_agent[32]; U8 max_forwards; U32 t1_timeout; /* T1 timer (RTT estimate) */ U32 t2_timeout; /* T2 timer (64*T1) */ U32 t4_timeout; /* T4 timer (5000ms) */ }sip_protocol_config; /* SIP协议栈接口 */ int sip_message_parse(sip_message *msg, const char *data, U32 length); int sip_message_build(sip_message *msg, char *buffer, U32 size); void sip_message_free(sip_message *msg); // int sip_send_message(S32 sip_socket, struct sip_message *msg,const char *dest_addr, U16 dest_port); int sip_uri_parse(struct sip_uri *uri, const char *uri_str); int sip_uri_build(struct sip_uri *uri, char *buffer, U32 size); struct sip_transaction *sip_transaction_create(struct sip_message *ori_req); void sip_transaction_free(struct sip_transaction *trans); const char *sip_method_to_string(enum sip_method method); sip_method sip_string_to_method(const char *method_str); const char *sip_status_to_reason(U16 status_code); void sip_generate_branch(char *branch, U32 size); void sip_generate_tag(char *tag, U32 size); void sip_generate_call_id(char *buf, int len); #endif /* _SIP_PROTOCOL_H */ 为这段程序所有字符数组最大长度改为宏定义的最大长度
10-28
struct virtrdma_sq_stats { struct u64_stats_sync syncp; u64 packets; u64 bytes; u64 xdp_tx; u64 xdp_tx_drops; u64 kicks; u64 tx_timeouts; }; struct virtrdma_rq_stats { struct u64_stats_sync syncp; u64 packets; u64 bytes; u64 drops; u64 xdp_packets; u64 xdp_tx; u64 xdp_redirects; u64 xdp_drops; u64 kicks; }; /* Internal representation of a send virtqueue */ struct virtrdma_send_queue { /* Virtqueue associated with this send _queue */ struct virtqueue *vq; /* TX: fragments + linear part + virtio header */ struct scatterlist sg[MAX_SKB_FRAGS + 2]; /* Name of the send queue: output.$index */ char name[16]; struct virtrdma_sq_stats stats; struct napi_struct napi; /* Record whether sq is in reset state. */ bool reset; }; /* RX packet size EWMA. The average packet size is used to determine the packet * buffer size when refilling RX rings. As the entire RX ring may be refilled * at once, the weight is chosen so that the EWMA will be insensitive to short- * term, transient changes in packet size. */ DECLARE_EWMA(pkt_len, 0, 64) /* Internal representation of a receive virtqueue */ struct virtrdma_receive_queue { /* Virtqueue associated with this receive_queue */ struct virtqueue *vq; struct napi_struct napi; struct bpf_prog __rcu *xdp_prog; struct virtrdma_rq_stats stats; /* Chain pages by the private ptr. */ struct page *pages; /* Average packet length for mergeable receive buffers. */ struct ewma_pkt_len mrg_avg_pkt_len; /* Page frag for packet buffer allocation. */ struct page_frag alloc_frag; /* RX: fragments + linear part + virtio header */ struct scatterlist sg[MAX_SKB_FRAGS + 2]; /* Min single buffer size for mergeable buffers case. */ unsigned int min_buf_len; /* Name of this receive queue: input.$index */ char name[16]; struct xdp_rxq_info xdp_rxq; }; struct virtrdma_info { struct virtio_device *vdev; struct virtqueue *cvq; struct net_device *dev; struct virtrdma_send_queue *sq; struct virtrdma_receive_queue *rq; unsigned int status; /* Max # of queue pairs supported by the device */ u16 max_queue_pairs; /* # of queue pairs currently used by the driver */ u16 curr_queue_pairs; /* # of XDP queue pairs currently used by the driver */ u16 xdp_queue_pairs; /* xdp_queue_pairs may be 0, when xdp is already loaded. So add this. */ bool xdp_enabled; /* I like... big packets and I cannot lie! */ bool big_packets; /* number of sg entries allocated for big packets */ unsigned int big_packets_num_skbfrags; /* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs; /* Host supports rss and/or hash report */ bool has_rss; bool has_rss_hash_report; u8 rss_key_size; u16 rss_indir_table_size; u32 rss_hash_types_supported; u32 rss_hash_types_saved; /* Has control virtqueue */ bool has_cvq; /* Host can handle any s/g split between our header and packet data */ bool any_header_sg; /* Packet virtio header size */ u8 hdr_len; /* Work struct for delayed refilling if we run low on memory. */ struct delayed_work refill; /* Is delayed refill enabled? */ bool refill_enabled; /* The lock to synchronize the access to refill_enabled */ spinlock_t refill_lock; /* Work struct for config space updates */ struct work_struct config_work; /* Does the affinity hint is set for virtqueues? */ bool affinity_hint_set; /* CPU hotplug instances for online & dead */ struct hlist_node node; struct hlist_node node_dead; struct control_buf *ctrl; /* Ethtool settings */ u8 duplex; u32 speed; /* Interrupt coalescing settings */ u32 tx_usecs; u32 rx_usecs; u32 tx_max_packets; u32 rx_max_packets; unsigned long guest_offloads; unsigned long guest_offloads_capable; /* failover when STANDBY feature enabled */ struct failover *failover; }; static inline struct virtio_rdma_dev *to_vdev(struct ib_device *ibdev) { return container_of(ibdev, struct virtio_rdma_dev, ib_dev); } #define virtio_rdma_dbg(ibdev, fmt, ...) \ ibdev_dbg(ibdev, "%s: " fmt, __func__, ##__VA_ARGS__) #endif 这一段也改一下
09-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值