清北暑假模拟day2 之
2016-10-19 19:13
225 查看
/* 现场代码,枚举每条边删除 */ #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<queue> #include<algorithm> #define mx 1005 using namespace std; struct orz { int d,p; friend bool operator <(orz a,orz b) {return a.d>b.d;} }; struct Edge{ int to; int w; int id; }; priority_queue < orz > ss; int flag,cnt,v[mx],d[mx],n,m,l; vector<Edge> edge[mx]; bool vis[mx]; void input(){ cin>>n>>l; int u,v,wei; Edge test; for(int i = 1;i <= l;i++){ cin>>u>>v>>wei; if(u == v) continue; test.id = ++cnt; test.to = v; test.w = wei; edge[u].push_back(test); test.to = u; edge[v].push_back(test); } m = 1; } void dij(int s) { for(int i = 0;i < mx;i++) d[i] = 1000000000; d[s]=0; orz tmp; tmp.d=0,tmp.p=s; ss.push(tmp); flag++; int x,dd; Edge j; while (!ss.empty()) { tmp=ss.top(); ss.pop(); x=tmp.p,dd=tmp.d; if (v[x]==flag) continue; v[x]=flag; for (int i = 0;i < edge[x].size();i++){ if(vis[edge[x][i].id]) continue; j = edge[x][i]; if (d[j.to]>dd+j.w) { d[j.to]=dd+j.w; tmp.d=dd+j.w,tmp.p=j.to; ss.push(tmp); } } } } int main(){ freopen("di.in","r",stdin); freopen("di.out","w",stdout); input(); int ans = 0; for(int i = 1;i <= cnt;i++){ vis[i] = true; dij(1); vis[i] = false; if(d < 1000000000) ans = max(ans,d ); } cout<<ans; return 0; } /* 要使最短路改变,就只能删除最短路经过的边 */ #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int maxn=210; const int maxm=50010; int n,m,en,f[maxn],q[maxn],dist[maxn],edg[maxm][3],z[maxn]; bool use[maxn]; struct edge { int e,d,id; edge *next; }*v[maxn],ed[maxm<<1],*fe[maxn]; void add_edge(int id,int s,int e,int d) { en++; ed[en].next=v[s];v[s]=ed+en;v[s]->e=e;v[s]->d=d;v[s]->id=id; } void spfa() { int front=0,tail=1; memset(dist,0x3f,sizeof(dist)); dist[1]=0; use[1]=true; q[0]=1; for (;front!=tail;) { int now=q[front++]; if (front==maxn) front=0; use[now]=false; for (edge *e=v[now];e;e=e->next) if (dist[e->e]>dist[now]+e->d) { dist[e->e]=dist[now]+e->d; f[e->e]=now;fe[e->e]=e; if (!use[e->e]) { use[e->e]=true; q[tail++]=e->e; if (tail==maxn) tail=0; } } } } int main() { freopen("di.in","r",stdin); freopen("di.out","w",stdout); scanf("%d%d",&n,&m); for (int a=1;a<=m;a++) scanf("%d%d%d",&edg[a][0],&edg[a][1],&edg[a][2]); for (int a=1;a<=m;a++) { add_edge(a,edg[a][0],edg[a][1],edg[a][2]); add_edge(a,edg[a][1],edg[a][0],edg[a][2]); } spfa(); int cnt=0; for (int a=n;a!=1;a=f[a]) z[++cnt]=fe[a]->id; int ans=-1; for (int a=1;a<=cnt;a++) { en=0; memset(v,0,sizeof(v)); for (int b=1;b<=m;b++) if (b!=z[a]) { add_edge(b,edg[b][0],edg[b][1],edg[b][2]); add_edge(b,edg[b][1],edg[b][0],edg[b][2]); } spfa(); if (dist !=0x3f3f3f3f) ans=max(ans,dist ); } printf("%d\n",ans); return 0; }
相关文章推荐
- 清北暑假模拟day2 将
- 清北暑假模拟day2 国
- 清北暑假模拟day1 爱
- 清北暑假模拟day1 生活
- 清北暑假模拟day1 艳阳天
- poj 1068 Parencodings 大模拟 水题 暑假第7题
- poj 2632Crashing Robots 暑假第8题 大模拟,水题
- 1/21集训二 模拟+贪心 G.(贪心 安排做作业的时间)Doing Homework again(感觉有点像HDU安排电视节目的那题(今年暑假不AC))
- 【ACM暑假培训】3、模拟算法(99乘法表+方块转换+循环数)
- 10.26最后的模拟DAY2 数字对[暴力]
- NOIP2017 模拟考试 day2 2017.10.07
- 【GDOI2017第二轮模拟day2】开房间
- 【JZOJ5078】【GDOI2017第三轮模拟day2】魔法咒语
- 暑假训练day2 : zoj选练
- poj 1573 Robot Motion 暑假训练第9题 模拟 大水题
- 2017.8.19~8.20 noip 模拟 day2
- 【HNOI模拟By lyp】Day2
- 【GDOI2017第三轮模拟day2】魔法咒语(AC自动机,矩阵乘法)
- 【NOIP模拟考三】线段树/ST表 day2 second 二叉树
- 【20150905】NOIP模拟套题01 day2 题解 & 总结