QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106299 | #5160. Kebab Pizza | joesmitty | WA | 1ms | 5688kb | C++14 | 4.6kb | 2023-05-17 12:10:20 | 2023-05-17 12:10:22 |
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();
}
sort(all(edges));
edges.resize(unique(all(edges)) - edges.begin());
m = edges.size();
for(auto e : edges) {
// cout << e.ff << " " << e.ss << endl;
deg[e.ff]++;
deg[e.ss]++;
}
for(auto e : edges) {
bool good = true;
if(deg[e.ff] == 1 && deg[e.ss] > 1) good = false;
if(deg[e.ff] > 1 && deg[e.ss] == 1) good = false;
if(good) {
if(e.ss != e.ff) {
adj[e.ff].pb(e.ss);
adj[e.ss].pb(e.ff);
}
} else {
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) {
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: 0
Wrong Answer
time: 1ms
memory: 5688kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
0: 4 1: 2: 3: 4: 0 5 5: 4 possible
result:
wrong answer 1st lines differ - expected: 'possible', found: '0: 4 '