int main(){
    int n;
    cin>>n;
    vi t;
    t.resize(n,-1);
    dp.resize(n,t);              // dp is n X n
    for(int i=0;i<n;i++){
            int r,c;
            cin>>r>>c;
            vi temp;
            temp.pb(r);
            temp.pb(c);
            matrices.pb(temp);
            }
    cout<<solve(0,n-1)<<endl;
    int A;
    cin>>A;
    return 0;
}
Ejemplo n.º 2
0
Archivo: A.cpp Proyecto: alexkats/Code
int main ()
{
    srand (time (0));

    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);

    scanf ("%d %d", &n, &m);
    g.resize (n + 1);
    used.resize (n + 1, 0);

    for (int i = 0; i < m; i++)
    {
        int x, y;
        scanf ("%d %d", &x, &y);
        g [x].pb (y);
        num [x][y] = i + 1;
    }

    int st;
    scanf ("%d", &st);
    vi ans;
    found = 0;
    dfs (st, ans);

    if ((int) ans.size () == 0)
    {
        puts ("-1");
        return 0;
    }

    reverse (ans.begin (), ans.end ());
    ans.pop_back ();
    printf ("%d\n", (int) ans.size ());

    for (int i = 0; i < (int) ans.size (); i++)
        printf ("%d%c", ans [i], " \n" [i == (int) ans.size () - 1]);

    return 0;
}
Ejemplo n.º 3
0
int main(){

    ios::sync_with_stdio(0);

    int n;
    while(cin >> n) {
        int a, num, b;
        char c;
        cont = 0;
        dfs_num.clear();
        dfs_num.resize(n, -1);
        dfs_low.clear();
        dfs_low.resize(n);
        dfs_parent.clear();
        dfs_parent.resize(n);
        vec.clear();
        vec.resize(n);
        for (int i = 0; i < n; ++i) {
            cin >> a >> c >> num >> c;
            for (int j = 0; j < num; ++j) {
                cin >> b;
                vec[a].push_back(b);
            }
        }
        for (int k = 0; k < n; ++k)
            if (dfs_num[k] == -1)
                artiBri(k);
        sort(bri.begin(), bri.end());
        cout << bri.size() << " critical links" << endl;
        for (int l = 0; l < bri.size(); ++l)
            cout << bri[l].first << " - " << bri[l].second << endl;

    }

    return 0;
}
Ejemplo n.º 4
0
int main(){
    ios::sync_with_stdio(0);
    int rel,network = 0;
    string a,b;
    while(cin >> V >> rel && (V||rel)){
        int cont = -1;
        map<string,int> nums;
        adjmat.clear(); adjmat.resize(V+5,vi(V+5,inf));

        for (int k = 0; k < V; ++k) {
            adjmat[k][k] = 0;
        }
        for (int i = 0; i < rel; ++i) {
            cin >> a >> b;
            if(nums.find(a) == nums.end()) nums[a] = ++cont;
            if(nums.find(b) == nums.end()) nums[b] = ++cont;
            adjmat[nums[a]][nums[b]] = 1;
            adjmat[nums[b]][nums[a]] = 1;
        }
        warshall();

        int ans = -1;
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                //cout << adjmat[i][j]<<"  ";
                ans = max(ans,adjmat[i][j]);
            }//cout<< endl;
        }

        cout << "Network "<< ++network << ": ";
        if(ans == inf) cout << "DISCONNECTED\n\n";
        else cout << ans << endl<<endl;
    }

    return 0;
}
Ejemplo n.º 5
0
Archivo: b.cpp Proyecto: nozdrenkov/sp
 dinic_mf_t(int n) : n(n) {
     g.resize(n);
 }