Pagini recente » Cod sursa (job #527084) | Cod sursa (job #1377804) | Cod sursa (job #3345526) | Cod sursa (job #1335341) | Cod sursa (job #3330623)
#include <fstream>
#include <utility>
#define x first
#define y second
#include <vector>
using namespace std;
ifstream in("zaharel.in");
ofstream out("zaharel.out");
typedef pair <int, int> pii;
const int nmax = 1000;
int n, m, xx, yy;
int redd[nmax + 2];
int bluee[nmax + 2];
char color;
int where, visited[nmax + 2];
vector <pii> poly1, poly2;
int main(){
in>>n>>m;
for(int i = 1; i <= m; i++){
in>>xx>>yy>>color;
///we are interested of one point because there is a point of color C on each line
if(color == 'R'){ redd[xx] = yy; }
if(color == 'A'){ bluee[yy] = xx; }
}
for(where = 1; !visited[where]; ){ ///merged polygon
visited[where] = 1;
where = bluee[redd[where]];
}
for(; visited[where]; ){ ///get the two polygons
poly1.push_back(make_pair(where, redd[where]));
poly2.push_back(make_pair(bluee[redd[where]], redd[where]));
visited[where] = 0;
where = bluee[redd[where]];
}
out<<poly1.size()<<"\n";
for(auto f : poly1) out<<f.x<<" "<<f.y<<" "; out<<"\n";
for(auto f : poly2) out<<f.x<<" "<<f.y<<" "; out<<"\n";
return 0;
}