# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
143122 |
2019-08-13T05:53:15 Z |
Ruxandra985 |
Pipes (CEOI15_pipes) |
C++14 |
|
1103 ms |
65540 KB |
/// trimit de curiozitate
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <map>
#define DIMN 100005
using namespace std;
int low[DIMN],bicnx,lvl[DIMN];
deque <int> st;
vector <int> v[DIMN];
set <int> sol[DIMN];
map <int,int> mp[DIMN];
int x,f[DIMN];
void dfs2 (int nod,int tt){
int i,vecin;
f[nod] = 1;
for (i=0;i<v[nod].size();i++){
vecin=v[nod][i];
if (vecin!=tt && !f[vecin])
dfs2(vecin,nod);
}
}
void dfs (int nod,int tt){
int i,vecin;
low[nod]=lvl[nod];
st.push_back(nod);
for (i=0;i<v[nod].size();i++){
vecin=v[nod][i];
if (vecin==tt)
continue;
if (lvl[vecin]==0){
lvl[vecin]=1+lvl[nod];
dfs(vecin,nod);
low[nod]=min(low[nod],low[vecin]);
if (low[vecin]>=lvl[nod]){ // nod e un nod critic
bicnx++;
do{
x=st.back();
st.pop_back();
sol[bicnx].insert(x);
//printf ("%d %d\n",bicnx , x);
}
while (x!=vecin);
sol[bicnx].insert(nod);
// printf ("%d %d\n",bicnx , nod);
// am scos din stiva muchiile care sunt in subarborele nod->vecin
}
}
else low[nod]=min(low[nod],lvl[vecin]);
}
}
int main()
{
// freopen ("a.in" , "r" , stdin);
// freopen ("a.out" , "w" , stdout);
int n,m,i,x,y;
scanf ("%d%d",&n,&m);
for (i=1;i<=m;i++){
scanf ("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
mp[x][y]++;
mp[y][x]++;
}
for (i=1;i<=n;i++){
if (!f[i]){
v[0].push_back(i);
dfs2(i,0);
}
}
dfs (0,0);
int a,b;
for (i=1;i<=bicnx;i++){
if (sol[i].size()==2){
a = *(sol[i].begin());
b = *(sol[i].rbegin());
if (a && b && mp[a][b]==1)
printf ("%d %d\n",a,b);
}
}
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs2(int, int)':
pipes.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i=0;i<v[nod].size();i++){
~^~~~~~~~~~~~~~
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i=0;i<v[nod].size();i++){
~^~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:60:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d",&n,&m);
~~~~~~^~~~~~~~~~~~~~
pipes.cpp:62:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d",&x,&y);
~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12024 KB |
Output is correct |
2 |
Correct |
12 ms |
12024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
13816 KB |
Output is correct |
2 |
Correct |
24 ms |
13748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1103 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1072 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1029 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
915 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
975 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
890 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
840 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
878 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |