#include #include #include #include #include using namespace std; struct qujian { int x,y; }a[150000],b[150000]; struct node { int from; int to; int w; int next; }e[550000]; int head[150000]; int dist[150000]; int vis[150000]; int n,m,cont; vectorEnd; mapMap; void add(int from,int to,int w) { //printf("----%d %d %d\n",from,to,w); e[cont].to=to; e[cont].w=w; e[cont].next=head[from]; head[from]=cont++; } int Cal(int x,int y) { if(xs; for(int i=1;i<=n;i++) { if(dist[i]==0)s.push(i); } while(!s.empty()) { int u=s.front(); vis[u]=0; s.pop(); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; int w=e[i].w; if(dist[v]>dist[u]+w) { dist[v]=dist[u]+w; if(vis[v]==0) { s.push(v); vis[v]=1; } } } } int ans=2000000000; for(int i=0;i=b[cnt-1].x) { flag=1; } if(a[i].x>=b[cnt-1].x&&a[i].x<=b[cnt-1].y) { flag=1; } if(flag==1) { int maxn=max(a[i].x,b[cnt-1].x); int minn=min(a[i].y,b[cnt-1].y); b[cnt-1].x=maxn; b[cnt-1].y=minn; } else { b[cnt].x=a[i].x; b[cnt].y=a[i].y; cnt++; } } } qqq=cnt; for(int i=0;is; vectorq; s.push_back(a[i].x); if(a[i].x+1a[i].x)s.push_back(a[i].y-1); if(a[i].x!=a[i].y)s.push_back(a[i].y); q.push_back(a[i+1].x); if(a[i+1].x+1a[i+1].x)q.push_back(a[i+1].y-1); if(a[i+1].x!=a[i+1].y)q.push_back(a[i+1].y); //printf("-%d %d\n",s.size(),q.size()); if(i==1)for(int j=0;j