Skip to content

Commit 72026e9

Browse files
committed
Solve problem 1469 - Boss from URI
1 parent 090236d commit 72026e9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

URI/1469 - Boss.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <stdio.h>
2+
#include <vector>
3+
#include <bitset>
4+
#include <memory.h>
5+
#include <algorithm>
6+
7+
using namespace std;
8+
9+
struct node {
10+
int id, age;
11+
bitset<501> parents;
12+
13+
node(int id, int age) {
14+
this->id = id;
15+
this->age = age;
16+
parents.reset();
17+
}
18+
};
19+
20+
int n, m, q;
21+
bool vis[501];
22+
char ch;
23+
vector<node> nodes;
24+
25+
int get_min_age(int x) {
26+
vis[x] = true;
27+
int res = 101;
28+
for(int i = 0; i < n; ++i)
29+
if(nodes[x].parents[i] && !vis[i])
30+
res = min(res, min(nodes[i].age, get_min_age(i)));
31+
return res;
32+
}
33+
34+
int find(int x) {
35+
for(int i = 0; i < n; ++i)
36+
if(nodes[i].id == x)
37+
return i;
38+
return 0;
39+
}
40+
41+
int main() {
42+
while(scanf("%d %d %d", &n, &m, &q) != EOF) {
43+
nodes.clear();
44+
45+
for(int i = 0, age; i < n; ++i) {
46+
scanf("%d", &age);
47+
nodes.push_back(node(i, age));
48+
}
49+
50+
for(int i = 0, a, b; i < m; ++i) {
51+
scanf("%d %d", &a, &b);
52+
--a, --b;
53+
nodes[b].parents[a] = 1;
54+
}
55+
56+
for(int i = 0, a, b; i < q; ++i) {
57+
scanf(" %c", &ch);
58+
59+
if(ch == 'T') {
60+
scanf("%d %d", &a, &b);
61+
--a, --b;
62+
a = find(a);
63+
b = find(b);
64+
swap(nodes[a].id, nodes[b].id);
65+
swap(nodes[a].age, nodes[b].age);
66+
} else {
67+
scanf("%d", &a);
68+
--a;
69+
a = find(a);
70+
if(nodes[a].parents.none()) puts("*");
71+
else {
72+
memset(vis, false, sizeof vis);
73+
printf("%d\n", get_min_age(a));
74+
}
75+
}
76+
}
77+
}
78+
79+
return 0;
80+
}
81+

URI/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
- [1430 - Jingle Composing](https://www.urionlinejudge.com.br/judge/en/problems/view/1430)
7171
- [1451 - Broken Keyboard](https://www.urionlinejudge.com.br/judge/en/problems/view/1451)
7272
- [1467 - Zero or One](https://www.urionlinejudge.com.br/judge/en/problems/view/1467)
73+
- [1469 - Boss](https://www.urionlinejudge.com.br/judge/en/problems/view/1469)
7374
- [1548 - Canteen Queue](https://www.urionlinejudge.com.br/judge/en/problems/view/1548)
7475
- [1550 - Inversion](https://www.urionlinejudge.com.br/judge/en/problems/view/1550)
7576
- [1551 - Complete Sentence](https://www.urionlinejudge.com.br/judge/en/problems/view/1551)

0 commit comments

Comments
 (0)