7.30 Test——Math Theory 2

T1:

1 problem

1.1 Description
Jia one hundred glass looking at ZJOI 2018 of a question "chart."
For an undirected graph G = (V, E), which line graph L (G) is an undirected graph:
? Vertex set of size | E |, each corresponding to a unique point of an original edge.
? Edged between two points when and only when both sides have a common point corresponding to point (note that there will be no self-loop) on the original.
ZJOI that question requires L (L (L (L ( L (L (L (L (L (G))))))))) points to a tree G,
it is very simple to nine poor, but Jia of one hundred glass too hard, then one hundred glass Jia intended to solve a more simple question:
for a tree G, seeking L (L (G)) points.

The Task 1.2
1.2.1 the Input
of the first row and n represents a positive integer of G points;
next n - 1 represented by a number of two per row G side.

1.2.2 Output
line a number indicates the answer.

1.3 Sample
1.3.1 Input
5
1 2
2 3
2 5
3 4
1.3.2 Output
4

1.4 Constraint
for 30% of data, n <= 100;
to 100% of the data, n-<= 10? . 5 .

1.5 Hint
This figure depicts a sample of the G, L (G) and L (L (G)).

 

Resolution:

  Nana really is a problem

  Request is not difficult to see the number of edges L (G) is, L (G) in the edge, the original figure, there are two common points of the edge point becomes connected together, so consider intersection enumeration of original while after it is connected into the point L (G) will twenty-two connected, so that a point of intersection in the original contribution generated answer is C (deg, 2), where deg is the degree of its

 Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100004;

int n, deg[maxn];
ll ans;

int main()
{
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i < n; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        deg[x] ++;
        deg[y] ++;
    }
    for(int i = 1; i <= n; ++i)
        ans += 1LL * deg[i] * (deg[i] - 1) / 2;
    printf("%lld", ans);
    return 0;
}
a

 

T2:

2 1 simple question

2.1 Description
Jia one hundred glass just learned Du teach sieve, want a very simple question practice your hand. Gives N, seeking:
$ \ sum_ = {I}. 1} ^ {N I \ MU (I) $
answer die 10 . 9   + 7.

Task 2.2
2.2.1 the Input
line a positive integer N.
2.2.2 Output
line a number indicates the answer.

2.3 Sample
2.3.1 Input
15
2.3.2 Output
5

2.4 Constraint
for 30% of data, N <= 10 . 6 ;
to 60% of the data, N <= 10 . 9 ;
100% of the data, N <= 10? 10 .

 

Guess you like

Origin www.cnblogs.com/Joker-Yza/p/11272465.html