QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106296 | #5160. Kebab Pizza | joesmitty | WA | 3ms | 5840kb | C++14 | 4.3kb | 2023-05-17 11:44:04 | 2023-05-17 11:44:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
//#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX;
long double PI = 4*atan(1);
long double eps = 1e-12;
int n,k;
int m;
int p;
vector<pii> edges;
int deg[100010] = {};
vi adj[100010] = {};
vi verts;
int vis[100010] = {};
int nvis = 0;
int numdeg1 = 0;
void dfs(int u) {
if(adj[u].size() == 1) numdeg1--;
for(auto v : adj[u]) {
if(!vis[v]) {
vis[v] = 1;
nvis++;
dfs(v);
}
}
}
int main() {
//auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);cin.tie(0);
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> k;
FOR(i,0,n) {
int u,v; cin >> u >> v;
if(u > v) swap(u,v);
edges.pb({u,v});
verts.pb(u);
verts.pb(v);
}
sort(all(verts));
verts.resize(unique(all(verts)) - verts.begin());
p = verts.size();
for(auto &e : edges) {
e.ff = lower_bound(all(verts), e.ff) - verts.begin();
e.ss = lower_bound(all(verts), e.ss) - verts.begin();
}
edges.resize(unique(all(edges)) - edges.begin());
m = edges.size();
for(auto e : edges) {
if(e.ff != e.ss) {
deg[e.ff]++;
deg[e.ss]++;
}
}
for(auto e : edges) {
if(e.ff == e.ss) continue;
if(deg[e.ff] > 1 && deg[e.ss] > 1) {
adj[e.ff].pb(e.ss);
adj[e.ss].pb(e.ff);
}
if(deg[e.ff] == 1) {
if(vis[e.ff] == 0) {
nvis++;
vis[e.ff] = 1;
}
}
if(deg[e.ss] == 1) {
if(vis[e.ss] == 0) {
nvis++;
vis[e.ss] = 1;
}
}
}
FOR(i,0,p) {
if(adj[i].size() > 2) {
cout << "impossible" << endl;
return 0;
} else if(adj[i].size() == 1) {
numdeg1++;
}
}
FOR(i,0,p) {
if(!vis[i] && adj[i].size() > 0) {
vis[i] = 1;
nvis++;
int prenum1 = numdeg1;
dfs(i);
// cycle
if(numdeg1 == prenum1 && nvis != p) {
cout << "impossible" << endl;
return 0;
}
}
}
cout << "possible" << endl;
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5752kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
possible
result:
ok single line: 'possible'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5840kb
input:
5 5 1 3 1 5 2 3 2 5 3 4
output:
possible
result:
ok single line: 'possible'
Test #3:
score: 0
Accepted
time: 3ms
memory: 5840kb
input:
6 7 1 2 2 3 3 4 4 5 3 6 6 7
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 5652kb
input:
8 4 1 1 1 2 2 1 2 2 3 3 3 4 4 3 4 4
output:
possible
result:
ok single line: 'possible'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
5 4 1 1 1 4 2 2 2 4 3 4
output:
possible
result:
ok single line: 'possible'
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 5700kb
input:
6 4 1 1 1 4 2 2 2 4 3 3 3 4
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'