File tree 4 files changed +133
-0
lines changed
4 files changed +133
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ int main () {
7
+ ios_base::sync_with_stdio (false );
8
+ cin.tie (0 ); cout.tie (0 );
9
+
10
+ string N;
11
+ cin >> N;
12
+
13
+ if (N[0 ] == N[2 ]) {
14
+ cout << " Yes" << endl;
15
+ } else {
16
+ cout << " No" << endl;
17
+ }
18
+
19
+ return 0 ;
20
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ int main () {
7
+ ios_base::sync_with_stdio (false );
8
+ cin.tie (0 ); cout.tie (0 );
9
+
10
+ int A, B, C, D;
11
+ cin >> A >> B >> C >> D;
12
+
13
+ int L = max (A, C), R = min (B, D);
14
+ int ans = max (0 , R - L);
15
+ cout << ans << endl;
16
+
17
+ return 0 ;
18
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ int N;
7
+ vector<ll> T;
8
+
9
+ ll gcd (ll a, ll b) {
10
+ while (b > 0 ) {
11
+ ll c = a % b;
12
+ a = b, b = c;
13
+ }
14
+ return a;
15
+ }
16
+
17
+ ll lcm (ll a, ll b) {
18
+ return a / gcd (a, b) * b;
19
+ }
20
+
21
+ ll solve () {
22
+ ll ans = 1 ;
23
+ for (auto t : T) {
24
+ ans = lcm (ans, t);
25
+ }
26
+ return ans;
27
+ }
28
+
29
+ int main () {
30
+ ios_base::sync_with_stdio (false );
31
+ cin.tie (0 ); cout.tie (0 );
32
+
33
+ cin >> N;
34
+ T.assign (N, 0 );
35
+ for (int i = 0 ; i < N; ++i) {
36
+ cin >> T[i];
37
+ }
38
+ cout << solve () << endl;
39
+
40
+ return 0 ;
41
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ struct edge { int to; int w; };
7
+ int N, K;
8
+ vector<vector<edge>> G;
9
+
10
+ vector<ll> ds;
11
+ void dfs (int v, int p) {
12
+ for (auto const & e : G[v]) {
13
+ if (e.to == p) continue ;
14
+ ds[e.to ] = ds[v] + e.w ;
15
+ dfs (e.to , v);
16
+ }
17
+ }
18
+
19
+ void build () {
20
+ ds.assign (N, 0 );
21
+ dfs (K, K);
22
+ }
23
+
24
+ ll query (int x, int y) {
25
+ return ds[x] + ds[y];
26
+ }
27
+
28
+ int main () {
29
+ ios_base::sync_with_stdio (false );
30
+ cin.tie (0 ); cout.tie (0 );
31
+
32
+ cin >> N;
33
+ G.assign (N, vector<edge>());
34
+ for (int i = 0 ; i < N - 1 ; ++i) {
35
+ int a, b, c;
36
+ cin >> a >> b >> c;
37
+ --a, --b;
38
+ G[a].push_back ({ b, c });
39
+ G[b].push_back ({ a, c });
40
+ }
41
+
42
+ int Q;
43
+ cin >> Q >> K;
44
+ --K;
45
+ build ();
46
+ for (int i = 0 ; i < Q; ++i) {
47
+ int x, y;
48
+ cin >> x >> y;
49
+ --x, --y;
50
+ cout << query (x, y) << endl;
51
+ }
52
+
53
+ return 0 ;
54
+ }
You can’t perform that action at this time.
0 commit comments