QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106297 | #5160. Kebab Pizza | joesmitty | WA | 3ms | 6108kb | C++14 | 4.4kb | 2023-05-17 11:57:26 | 2023-05-17 11:57:30 |
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) {
deg[e.ff]++;
deg[e.ss]++;
}
for(auto e : edges) {
if(deg[e.ff] > 1 && deg[e.ss] > 1) {
if(e.ss != e.ff) {
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) {
// cout << i << ": ";
// pr(adj[i]);
// }
FOR(i,0,p) {
if(adj[i].size() > 2) {
cout << "impossible" << endl;
return 0;
} else if(adj[i].size() == 1) {
numdeg1++;
}
}
int rem = p - nvis;
FOR(i,0,p) {
if(!vis[i] && adj[i].size() > 0 && adj[i][0] != i) {
int pvis = nvis;
vis[i] = 1;
nvis++;
int prenum1 = numdeg1;
dfs(i);
// cycle
if(numdeg1 == prenum1 && nvis - pvis != rem) {
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();
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 6108kb
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: 1ms
memory: 5696kb
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: 5652kb
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: 3ms
memory: 5848kb
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: 0ms
memory: 5792kb
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: 5852kb
input:
5 4 1 1 1 4 2 2 2 4 3 4
output:
possible
result:
ok single line: 'possible'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
6 4 1 1 1 4 2 2 2 4 3 3 3 4
output:
impossible
result:
ok single line: 'impossible'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 5692kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'