AOJ 2251 Merry Christmas (minimum point coverage)

Source: Internet
Author: User

"Topic link" http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2251

"The main topic"

Given a picture, now there are tasks that require TI to send gifts to pi locations at a time
Ask at least a few Santa Claus to finish the mission on time.

Exercises

We're going to send a gift and we can get to the next place. Connecting between two points for a gift
Only the minimum point of this graph is required to cover the answer.

Code

#include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <queue >using namespace Std;const int max_v=2000;int v,match[max_v];vector<int> g[max_v];bool used[MAX_V];void add_    Edge (int u,int v) {g[u].push_back (v); G[v].push_back (u);}    BOOL Dfs (int v) {used[v]=1;        for (int i=0;i<g[v].size (); i++) {int u=g[v][i],w=match[u]; if (w<0| |!            Used[w]&&dfs (W)) {match[v]=u;            Match[u]=v;        return 1; }}return 0;}    int bipartite_matching () {int res=0;    memset (match,-1,sizeof (match));            for (int v=0;v<v;v++) {if (match[v]<0) {memset (used,0,sizeof (used));        if (Dfs (v))) res++; }}return Res;} void Clear () {for (int i=0;i<v;i++) g[i].clear ();} const int MAX_N=100;CONST int Max_l=1000;const int inf=0x3f3f3f3f;int n,m,l,x,y,z;int d[max_n][max_n],p[max_l],t[max_l    ];void init () {v=2*l;    Clear ();    Memset (d,inf,sizeof (d)); for (int i=0;i<m;i++) {scanf ("%d%d%d", &x,&y,&z);    D[x][y]=d[y][x]=z;    } for (int i=0;i<l;i++) scanf ("%d%d", &p[i],&t[i]);        for (int k=0;k<n;k++) {d[k][k]=0;    for (int. i=0;i<n;i++) for (int j=0;j<n;j++) d[i][j]=min (D[i][j],d[i][k]+d[k][j]); }}void solve () {for (Int. i=0;i<l;i++) for (int j=0;j<l;j++) {if (i!=j&&t[i]+d[p[i]][p[j]]&        LT;=T[J]) Add_edge (i<<1,j<<1|1); } printf ("%d\n", l-bipartite_matching ());}        int main () {while (~scanf ("%d%d%d", &n,&m,&l), N) {init ();    Solve (); }return 0;}

AOJ 2251 Merry Christmas (minimum point overlay)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.