Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

help
Author: Mrym.Rhmni
ID: 064866
Problem: -
Contest: -
Date: 2015-09-14 16:08:28

problem 322
WHAT THE HELL IS TEST 9?
:(((((
i can not find my bug for a weak!
help me !! plz :((


#include <iostream>
#include <vector>
#include <set>
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 2010;
int n, color, mark[maxn];
set <int> G[maxn];
set <pii> seti, peti;
void DFS(int u){
mark[u] = color;
for (set<int> :: iterator it = G[u].begin(); it != G[u].end(); it++)
if (mark[*it] != color)
DFS(*it);
}
int main(){
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n - 1; i++){
int u, v; cin >> u >> v; u--, v--;
seti.insert(pii(u, v));
G[u].insert(v);
G[v].insert(u);
}
for (int i = 0; i < n - 1; i++){
int u, v; cin >> u >> v; u--, v--;
if(seti.find(pii(u, v)) != seti.end() || seti.find(pii(v, u)) != seti.end()){
seti.erase(pii(u, v));
seti.erase(pii(v, u));
}
else
peti.insert(pii(u, v));
}
cout << seti.size() << endl;
while(!seti.empty()){
int x = (*seti.begin()).F, y = (*seti.begin()).S;
G[x].erase(y), G[y].erase(x);
seti.erase(seti.begin());
color++;
DFS(x);
for (set<pii> :: iterator it = peti.begin(); it != peti.end(); it++){
int u = (*it).F, v = (*it).S;
if (mark[u] != mark[v] && (mark[u] == color || mark[v] == color)){
peti.erase(*it);
G[u].insert(v);
G[v].insert(u);
cout << "2 " << x + 1 << ' ' << y + 1 << ' ' << u + 1 << ' ' << v + 1 << endl;
break;
}
}
}
}

see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-09-22 21:00:53Online Contester Team © 2002 - 2016. All rights reserved.