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 |
无数组ac代码,poj似乎真的不能正常读入size_t。。估计poj的计算机是32位的,所以size_t居然就是和unsigned int一样。。真无语无数组ac代码 #include<vector> #include<deque> #include<utility> #include<cstddef> #include<climits> #include<numeric> #include<cstdio> #include<string> #include<algorithm> template<typename Ty> long long spfa(Ty &gr) { std::vector<long long> relaxx(gr.size(),LLONG_MAX); long long *relax(&(relaxx.front())); std::string str(gr.size(),false); relax[1]=0; char *vh(const_cast<char*>(str.data())); vh[1]=1; for(std::deque<std::size_t> que(1,1);!que.empty();que.pop_front()) { std::size_t front(que.front()); for(std::pair<std::size_t,int> *iter(&(gr[front].front())),*end(iter+gr[front].size());iter!=end;++iter) if(relax[front]+iter->second<relax[iter->first]) { relax[iter->first]=relax[front]+iter->second; if(!vh[iter->first]) { vh[iter->first]=1; que.push_back(iter->first); } } vh[front]=0; } return std::accumulate(relax+1,relax+gr.size(),0LL); } int main() { std::size_t N; for(fscanf(stdin,"%u",&N);N;--N) { std::size_t n,m; fscanf(stdin,"%u%u",&n,&m); std::vector<std::vector<std::pair<std::size_t,int> > > gra(n+1,std::vector<std::pair<std::size_t,int> >()),rgra(gra); int dis; for(std::size_t a,b;m;--m) { fscanf(stdin,"%u%u%d",&a,&b,&dis); gra[a].push_back(std::pair<std::size_t,int>(b,dis)); rgra[b].push_back(std::pair<std::size_t,int>(a,dis)); } fprintf(stdout,"%lld\n",spfa(gra)+spfa(rgra)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator