QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104578 | #5160. Kebab Pizza | rania__ | WA | 5ms | 12796kb | C++14 | 3.0kb | 2023-05-11 08:20:09 | 2023-05-11 08:20:12 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;
template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// mt19937_64 for long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1e5 + 7;
set<int> st[N];
int nfso[N];
vector<int> adj[N];
int color[N];
int par[N],cyclenumber;
vector<vector<int>> cycles;
int mp[N];
vector<int> vec[N];
void cycleDetection(int u, int p) {
if (color[u] == 2) {
return;
}
if (color[u] == 1) {
vector<int> v;
cyclenumber++;
int cur = p;
v.push_back(cur);
while (cur != u) {
cur = par[cur];
v.push_back(cur);
}
cycles.push_back(v);
return;
}
par[u] = p;
color[u] = 1;
for (int v: adj[u]) {
if (v == par[u]) {
continue;
}
cycleDetection(v, u);
}
color[u] = 2;
}
struct DSU
{
vector<int> par, sz;
DSU(int n)
{
par = vector<int>(n + 1), sz = vector<int>(n + 1, 1);
iota(par.begin(), par.end(), 0);
}
int findSet(int a)
{
return (a == par[a] ? a : par[a] = findSet(par[a]));
}
void unionSet(int a, int b)
{
a = findSet(a), b = findSet(b);
if(a == b)
return;
if(sz[b] > sz[a])
swap(a, b);
par[b] = a, sz[a] += sz[b];
}
};
void doWork()
{
int n, k;
cin >> n >> k;
for(int i = 0; i < n; ++i)
{
int a, b;
cin >> a >> b;
st[a].insert(b);
st[b].insert(a);
}
DSU dodo(k+5);
int ans =0;
for(int i = 1; i <= k; ++i)
{
int cnt = 0;
for(auto &it: st[i])
{
if ( i > it)
{
if ( dodo.findSet(i) == dodo.findSet(it))
ans++;
}
dodo.unionSet(i,it);
if(it == i)
continue;
if(st[it].size() > 1)
{
cnt++;
}
}
if(cnt > 2)
return cout << "impossible", void();
}
set<int> st;
for (int i = 1; i <= k ; ++i) {
st.insert(dodo.findSet(i));
}
if ( ans ==0 || st.size() == 1)
cout << "possible";
else
return cout << "impossible", void();
}
signed main()
{
FIO
int T = 1;
// cin >> T;
for(int i = 1; i <= T; i++)
doWork();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 12796kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'