Sgu 164. Airline

Source: Internet
Author: User

Time Limit: 0.25 s

Space limit: 4 m

Question:

M different edges exist in the undirected completely graph of N (1 <= n <= 200) points. select no more than (m + 1) or two edges, so that any two points can reach each other through no more than three edges.

 

 

 

 

 

Solution:

Divide the edges of a undirected full graph into two parts. Therefore, the shortest distance of some vertices must not exceed 3.

No good proof... -_-!

Code

1 ~ M/2 is a group, M/2 + 1 ~ M is a group, and Floyd determines whether the first group meets the requirements. If the first group is output, the second group is not output.

 

#include <cstdio>const int INF = 300 + 9;int g[INF][INF], f[INF][INF];int n, m, i, j, k, t;int main() {scanf ("%d%d", &n, &m);t = (m + 1) >> 1;for (i = 1; i <= n; ++i)for (j = 1; j <= n; ++j) {scanf ("%d", g[i] + j);f[i][j] = g[i][j] <= t ? 1 : INF;}for (k = 1; k <= n; ++k)for (i = 1; i < n; ++i)for (j = i + 1; j <= n; ++j)if (f[i][k] + f[j][k] < f[i][j])f[i][j] = f[j][i] = f[i][k] + f[j][k];for (i = 1; i < n; ++i)for (j = i + 1; j <= n; ++j)if (f[i][j] > 3) {printf ("%d\n", m - t);for (++t; t <= m; ++t)   printf ("%d ", t);putchar (10);return 0;}printf ("%d\n", t);for (i = 1; i <= t; ++i)  printf ("%d ", i);putchar (10);return 0;}

 

  

 

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.