#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const double PI = 2.0 * acos(0.0); typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef vector vi; typedef vector vs; #define sz(c) int((c).size()) #define all(c) (c).begin(), (c).end() #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define FORS(i,a,b,s) for (int i = (a); i < (b); i=i+(s)) #define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--) #define FORIT(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++) typedef long long coord; struct pt{ coord x,y; pt():x(0),y(0){}; pt(coord _x,coord _y):x(_x),y(_y){}; }; int ccw(pt p0, pt p1, pt p2) { coord d1 =(p1.x-p0.x)*(p2.y-p0.y); coord d2 =(p2.x-p0.x)*(p1.y-p0.y); return (d1-d2>eps)-(d2-d1>eps); } int isPointOnSegment(pt p, pt a0, pt a1) { if(ccw(a0,a1,p)) return 0; coord cx = (p.x-a0.x)*(p.x-a1.x); coord cy = (p.y-a0.y)*(p.y-a1.y); if(cx > eps || cy > eps) return 0; if(cx < -eps || cy < -eps) return 2; return 1; } bool isSegmentIntersect(pt a0, pt a1, pt b0, pt b1) { int c1=ccw(a0,a1,b0); int c2=ccw(a0,a1,b1); int c3=ccw(b0,b1,a0); int c4=ccw(b0,b1,a1); if(c1*c2>0 || c3*c4>0) return 0; if(!c1 && !c2 && !c3 && !c4) { c1=isPointOnSegment(a0,b0,b1); c2=isPointOnSegment(a1,b0,b1); c3=isPointOnSegment(b0,a0,a1); c4=isPointOnSegment(b1,a0,a1); if(c1 && c2 && c3 && c4) return 1+(a0.x!=a1.x || a0.y!=a1.y); return max(max(c1,c2),max(c3,c4)); } return 1+(!min(c1,c2) || !min(c3,c4)); } map wells; pt pipeEnds[1000]; int toWell[1000]; bool selected[1000]; bool inter[1000][1000]; int main(){ int W,P; cin >> W >> P; // read the wells FOR(i,0,W){ pt x; cin >> x.x >> x.y; wells[i] = x; } // read the pipes FOR (i,0,P) cin >> toWell[i] >> pipeEnds[i].x >> pipeEnds[i].y, toWell[i]--; FOR (i,0,P) selected[i] = false; FOR(i,0,P) FOR(j,0,i) if (toWell[i] != toWell[j] && isSegmentIntersect(pipeEnds[i],wells[toWell[i]],pipeEnds[j],wells[toWell[j]]) == 1) inter[i][j] = true; else inter[i][j] = false; while (true){ bool carry = true; FOR(i,0,P) { if (!carry) break; if (!selected[i]) carry = false, selected[i] = true; else selected[i] = false; } if (carry) break; bool bad = false; // test the configuration FOR(i,0,P) FOR(j,0,i) if (inter[i][j]) if ((selected[i] && selected[j]) || (!selected[i] && !selected[j])) bad = 1; if (!bad) {cout << "possible" << endl; return 0;} } cout << "impossible" << endl; }