Skip to content

Commit b1ece50

Browse files
committed
[uva] Add C++ solution for 10305 - Ordering Tasks.
1 parent 2ffede7 commit b1ece50

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

uva/10305-1.ans

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4 1 5 2 3

uva/10305-1.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5 4
2+
1 2
3+
2 3
4+
1 3
5+
1 5
6+
0 0

uva/10305.cc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// https://uva.onlinejudge.org/external/103/10305.pdf
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
using vi=vector<int>;
5+
using vvi=vector<vi>;
6+
int main(){
7+
for(;;){
8+
int n,m,u,v;
9+
cin>>n>>m;
10+
if(!n)break;
11+
vvi g(n);
12+
for(int i=0;i<m;i++){
13+
cin>>u>>v;
14+
u--;v--;
15+
g[u].push_back(v);
16+
}
17+
vi s(n),p;
18+
function<void(int)>dfs=[&](int u){
19+
s[u]=1;
20+
for(int v:g[u])
21+
if(!s[v])
22+
dfs(v);
23+
p.push_back(u);
24+
};
25+
for(int i=0;i<n;i++)
26+
if(!s[i])
27+
dfs(i);
28+
reverse(p.begin(),p.end());
29+
for(int i=0;i<n;i++)
30+
cout<<p[i]+1<<" \n"[i==n-1];
31+
}
32+
}

uva/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ There are solutions for the following
5959
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1119))
6060
1. [10227 - Forests](10227.py)
6161
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1168))
62+
1. [10305 - Ordering Tasks](10305.cc)
63+
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1246))
6264
1. [10369 - Arctic Network](10369.cc)
6365
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1310))
6466
1. [10301 - Rings and Glue](10301.cc)

0 commit comments

Comments
 (0)