Skip to content

Commit 98622f5

Browse files
committed
Solve problems 263D and 363C from codeforces
1 parent c6f9b48 commit 98622f5

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

CodeForces/263D. Cycle in Graph.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 2e5 + 10;
6+
int n, m, k;
7+
bool vis[N];
8+
vector<vector<int> > g;
9+
vector<int> sol;
10+
11+
void DFS(int v, int src) {
12+
vis[v] = true;
13+
sol.push_back(v);
14+
15+
for(int i = 0; i < (int)g[v].size(); ++i) {
16+
int u = g[v][i];
17+
if(u == src && sol.size() >= k + 1) {
18+
printf("%d\n", (int)sol.size());
19+
for(int j = 0; j < (int)sol.size(); ++j)
20+
printf("%d ", sol[j]);
21+
puts("");
22+
exit(0);
23+
}
24+
if(!vis[u])
25+
DFS(u, src);
26+
}
27+
28+
sol.pop_back();
29+
}
30+
31+
int main() {
32+
scanf("%d %d %d", &n, &m, &k);
33+
g.resize(n + 10);
34+
for(int i = 0, a, b; i < m; ++i) {
35+
scanf("%d %d", &a, &b);
36+
g[a].push_back(b);
37+
swap(a, b);
38+
g[a].push_back(b);
39+
}
40+
for(int i = 0; i < (int)g.size(); ++i)
41+
sort(g[i].begin(), g[i].end());
42+
43+
for(int i = 1; i < n; ++i) {
44+
memset(vis, false, sizeof vis);
45+
DFS(i, i);
46+
}
47+
48+
return 0;
49+
}

CodeForces/363C. Fixing Typos.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
char in[int(2e5 + 10)], out[int(2e5 + 10)];
6+
7+
int main() {
8+
scanf("%s", in + 5);
9+
int len = strlen(in + 5), cnt = 5;
10+
for(int i = 0; i < 5; ++i)
11+
out[i] = char(i + '0');
12+
for(int i = 5; i < len + 5; ++i) {
13+
if(out[cnt - 1] == in[i] && out[cnt - 2] == in[i])
14+
continue;
15+
if(out[cnt - 3] == out[cnt - 2] && out[cnt - 1] == in[i])
16+
continue;
17+
out[cnt++] = in[i];
18+
}
19+
out[cnt] = '\0';
20+
printf("%s\n", out + 5);
21+
22+
return 0;
23+
}

CodeForces/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
- [257A. Sockets](http://codeforces.com/contest/257/problem/A)
7676
- [262A. Roma and Lucky Numbers](http://codeforces.com/problemset/problem/262/A)
7777
- [263A. Beautiful Matrix](http://codeforces.com/problemset/problem/263/A)
78+
- [263D. Cycle in Graph](http://codeforces.com/contest/263/problem/D)
7879
- [266A. Stones on the Table](http://codeforces.com/problemset/problem/266/A)
7980
- [266B. Queue at the School](http://codeforces.com/problemset/problem/266/B)
8081
- [268A. Games](http://codeforces.com/problemset/problem/268/A)
@@ -96,6 +97,7 @@
9697
- [358A. Dima and Continuous Line](http://codeforces.com/problemset/problem/358/A)
9798
- [359D. Pair of Numbers](http://codeforces.com/contest/359/problem/D)
9899
- [363B. Fence](http://codeforces.com/contest/363/problem/B)
100+
- [363C. Fixing Typos](http://codeforces.com/contest/363/problem/C)
99101
- [368A. Sereja and Coat Rack](http://codeforces.com/problemset/problem/368/A)
100102
- [368B. Sereja and Suffixes](http://codeforces.com/problemset/problem/368/B)
101103
- [378A. Playing with Dice](http://codeforces.com/problemset/problem/378/A)

0 commit comments

Comments
 (0)