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 |
谁能帮我检测一下,错在哪里,题目给出的数据时可以的。#include<iostream> using namespace std; int main(){ int *ad,*r,n,k,c=0,f,tt=0,*tf; int t,x=1,i,p,q=0; cin>>n>>k; ad=new int[n+1]; r=new int [n+1]; memset(ad,0,4*n+4); memset(r,0,4*n+4); for(t=0;t<k;t++ ){ cin>>f; tt=tt+f; for(p=0;p<f;p++){ q++; cin>>ad[q]; r[ad[q]]=1; }} tf=new int [tt+1]; memset(tf,1,4*tt+4); for (i=1;i<=tt;i++){ x=i; while(!r[x]&&x<=tt){ tf[x]=0; r[ad[x]]=0; r[x]=1; cout<<ad[x]<<" "<<x<<endl; x=ad[x]; } } for (i=1;i<=tt;i++){ if (tf[i]&&ad[i]!=i&&tf[ad[i]]){ x=c=i; r[c]=0; cout<<i<<" "<<n<<endl; while(!r[x]&&x<=tt){ r[ad[x]]=0; tf[x]=0; r[x]=1; cout<<ad[x]<<" "<<x<<endl; x=ad[x]; if(ad[x]==c) break; } cout<<n<<" "<<x<<endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator