ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

P1983-车站分级

2019-09-16 17:01:56  阅读:261  来源: 互联网

标签:ch int 车站 分级 read P1983 ans push 1003


 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define pb push_back
 4 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 5 #define INF 100000003
 6 #define ll long long
 7 inline ll read()
 8 {
 9     ll ans = 0;
10     char ch = getchar(), last = ' ';
11     while(!isdigit(ch)) last = ch, ch = getchar();
12     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
13     if(last == '-') ans = -ans;
14     return ans;
15 }
16 inline void write(ll x)
17 {
18     if(x < 0) x = -x, putchar('-');
19     if(x >= 10) write(x / 10);
20     putchar(x % 10 + '0');
21 }
22 int n,m;
23 int a[1003][1003];
24 int in[1003];
25 int ans = 1;
26 vector<int> G[1003];
27 void toposort()
28 {
29     queue<int> q;
30     _for(j,1,n+1)
31     {
32         int sum = 0;
33         _for(i,1,n+1)
34         if(a[i][j])
35             G[i].pb(j),sum ++;
36         in[j] = sum;
37     }
38 
39     _for(i,1,n+1)
40         if(!in[i])
41             q.push(i);
42     q.push(0);
43     while(q.size()!=1)
44     {
45         int x = q.front();
46         q.pop();
47         if(!x)
48         {
49             q.push(0);
50             ans ++;
51             continue;
52         }
53         _for(i,0,G[x].size())
54         {
55             in[G[x][i]] --;
56             if(!in[G[x][i]])
57                 q.push(G[x][i]);
58         }
59     }
60 }
61 int main()
62 {
63     n = read(), m = read();
64     _for(i,1,m+1)
65     {
66         int t = read();
67         set<int> s;
68         int st,ed;
69         _for(j,1,t+1)
70         {
71             int k = read();
72             if(j==1)
73                 st = k;
74             else if(j==t)
75                 ed = k;
76             s.insert(k);
77         }
78         _for(j,st+1,ed)
79             if(!s.count(j))
80                 for(auto p:s)
81                     a[j][p] = 1;
82     }
83     toposort();
84     write(ans);
85     return 0;
86 }

 

标签:ch,int,车站,分级,read,P1983,ans,push,1003
来源: https://www.cnblogs.com/Asurudo/p/11528274.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有