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 |
提交了40次的代码,谁能帮忙想下里面的问题。#include<map> #include<iterator> #include<vector> #include<string> #include<stdio.h> using namespace std; bool v[251000]; vector<int> vect[551000]; ///数组开小点就RE,这个就是MLE,能不能解决。 void dfs(int x) { if(v[x]) return ; else v[x]=1; vector<int>::iterator iter; for(iter=vect[x].begin();iter!=vect[x].end();iter++) dfs(*iter); } int main() { map<string,int>map1,map2; map<string,int>::iterator iter; memset(v,0,sizeof(v)); freopen("in.txt","r",stdin); char a[24],b[24]; int sum=0,i,c=1; while(scanf("%s%s",a,b)!=EOF) { int t1=map2[a],t2=map2[b]; if(!t1)t1=map2[a]=c++; if(!t2)t2=map2[b]=c++; vect[t1].push_back(t2); vect[t2].push_back(t1); map1[a]++,map1[b]++; } dfs(1); for(i=1;i<c;i++) if(!v[i]) break; if(i<c) {printf("Impossible\n"); return 0;} for(iter=map1.begin();iter!=map1.end();iter++) sum+=iter->second%2; if(sum!=2&&sum!=0)printf("Impossible\n"); else printf("Possible\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator