10.22 race simulation solution to a problem

51nod a game makes me fear

Improve simulation game set high so I had to use bfs water? ? vis [x] per emptied and led to burst into written spfa 10. autistic

Maybe I'll change today about the right algorithm so today I Xiandiu a bfs exam data over the water can also write a lot of questions ran down the solution so I waited ...

// edge weight is one that bfs
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x) {
    x=0;
    T f=1,ch=getchar();
    while (!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
    x*=f;
}
const  int N = 1100 ;
int n, m, all, vis [N] lin [N] dis [N];
struct gg {
     int y, next;
}a[100100];
struct pink {
    int x,y;
}s[100100];
inline void add(int x,int y) {
    to [ ++ tot] y = y;
    a[tot].next=lin[x];
    lin [x] = tot;
}
inline int bfs(int s,int t) {
    queue<int>q; 
    memset(vis,0,sizeof(vis));
    while(q.size()) q.pop();
    q.push(s);vis[s]=1;dis[s]=0;
    for(int i=lin[s];i;i=a[i].next) {
        int y=a[i].y;
        if(y==t) continue;
        q.push (y); dis [y] = 1 , vis [y] = 1 ;
    }q.pop();//
    while(q.size()) {
        int x=q.front();q.pop();
        for(int i=lin[x];i;i=a[i].next) {
            int y=a[i].y;
            if(vis[y]) continue;
            if(y==t) return dis[x]+1;
            say [y] = Dis [x] + 1 ;
            vis [y] = 1 ;
            q.push(y);
        }
    }
    return -1;
}
int main() {
//    freopen("1.in","r",stdin);
    freopen("railway.in","r",stdin);
    freopen("railway.out","w",stdout);
    read(n); read(m);
    for(int i=1;i<=m;i++) {
        read(s[i].x);read(s[i].y);
        add(s[i].x,s[i].y);
    }
    for(int i=1;i<=m;i++) {
        cout<<bfs(s[i].x,s[i].y)<<' ';
    }
    return 0;
}
View Code

 

Perhaps I think the tree line and then consider writing a book on the tree line was later found to be two-dimensional plane of things we need to do then mapped to a range of how to do it

We wish to map a rectangle into two parts to the x coordinate of the y-axis corresponds to the height of two rectangles as a large rectangle and a small rectangle we consider doing this offline

At this time, it becomes a problem of 2n 2m queries and modification operations segment tree maintenance operations case len indicates the length of this interval is modified and the modified sum representing the current interval is the area and

Query answer is len * x-sum 

Perhaps the very abstract at least I think so.

 

Hey violent search full array qwq? ? ? But we found divisible by 11 have a very wonderful nature is, for odd bits and even bits

 

Guess you like

Origin www.cnblogs.com/Tyouchie/p/11765008.html