Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:一组数据,虽然AC,但这过不了In Reply To:一组数据,虽然AC,但这过不了 Posted by:hhgff at 2010-01-13 10:44:41 > 5 8 > 1 2 > 1 3 > 2 4 > 3 2 > 4 3 > 4 5 > 5 4 > 2 1 > > ans : 5 我这组数据是对的,但没有ac,能不能帮忙看下,谢~ #include <cstdio> #include <cstring> #define maxe 500010 #define maxn 100010 using namespace std; typedef struct node { int x,y; int next; }node; int first[maxn+1],firstt[maxn+1],mark[maxn+1]={},seq[2*maxn+1]; node g[maxe+1],gt[maxe+1]; int num[maxn+1]={}; int n,e,total=0; void add(int a,int b,int c) { g[c].x = a; g[c].y = b; g[c].next = first[a]; first[a] = c; gt[c].x = b; gt[c].y = a; gt[c].next = firstt[b]; firstt[b] = c; } void init() { int a,b; scanf("%d%d",&n,&e); for (int i=1;i<=n;i++) { first[i] = -1; firstt[i] = -1; } for (int i=1;i<=e;i++) { scanf("%d%d",&a,&b); add(a,b,i); } } void dfs(int x,node *g,int *first,int color) { if (mark[x]) return; mark[x] = color; ++num[color]; total++; seq[total] = x; int temp; temp = first[x]; while (temp!=-1) { dfs(g[temp].y,g,first,color); temp = g[temp].next; } } void work() { int temp; int flag; int scc[maxn+1]; int color=0,t1,t2; for (int i=1;i<=n;i++) if (!mark[i]) dfs(i,g,first,1); memset(mark,0,sizeof(mark)); memset(num,0,sizeof(num)); for (int i=1;i<=n;i++) if (!mark[seq[i]]) { color++; dfs(seq[i],gt,firstt,color); //printf("%d %d\n",i,color); } for (int i=1;i<=n;i++) { flag = 0; for (temp=first[i];temp!=-1;temp=g[temp].next) { if (mark[g[temp].y]!=mark[i]) ++flag; } scc[mark[i]] += flag; //printf("%d\n",flag); } t1 = -1; for (int i=1;i<=color;i++) { if (!scc[i]) { ++t1; t2 = num[i]; } } //printf("%d\n",t1); if (!t1) printf("%d\n",t2); } int main() { init(); work(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator