QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#195681 | #5160. Kebab Pizza | kevinshan# | WA | 2ms | 10892kb | C++20 | 2.8kb | 2023-10-01 06:08:29 | 2023-10-01 06:08:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll POW = 9973;
vector<int> adj[MAXN];
set<int> topp[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k;
cin>>n>>k;
vector<int> contained(k,0);
vector<int> doubled(k,0);
for(int i=0; i<n; i++){
int u, v; cin>>u>>v;
u--; v--;
topp[u].in(v);
topp[v].in(u);
if(u == v) doubled[u] = 1;
}
for(int i=0; i<k; i++){
if(doubled[i] == 0 && topp[i].size() <= 1) contained[i] = 1;
}
// for(int i=0; i<k; i++){
// cout<<i<<": ";
// ca(topp[i]);
// nl;
// }
// ca(contained); nl;
for(int i=0; i<k; i++){
if(contained[i]) continue;
for(int j:topp[i]){
if(contained[j] || i == j) continue;
// cout<<"E";
adj[i].pb(j);
}
}
// for(int i=0; i<k; i++){
// cout<<i<<": ";
// ca(adj[i]);
// nl;
// }
vector<int> vis(k, 0);
for(int i=0; i<k; i++){
if(contained[i]) vis[i] = 1;
if(adj[i].size() > 2){
cout<<"impossible";
return 0;
}
}
// for(int i=0; i<k; i++) {
// ca(adj[i]);
// nl;
// }
int frog = 0;
for(int i=0; i<k; i++){
// if(contained[i]) vis[i] = 1;
// if(adj[i].size() == 0) vis[i] = 1;
if(vis[i] || adj[i].size() >= 2) continue;
queue<int> q;
q.push(i);
vis[i] = 1;
frog = 1;
while(q.size()){
int c = q.front();
q.pop();
for(int a:adj[c]){
if(vis[a]) continue;
vis[a] = 1;
q.push(a);
}
}
}
// ca(vis);
for(int i=0; i<k; i++){
if(vis[i]) continue;
queue<int> q;
q.push(i);
if(frog){
cout<<"impossible";
return 0;
}
while(q.size()){
int c = q.front();
q.pop();
for(int a:adj[c]){
if(vis[a]) continue;
vis[a] = 1;
q.push(a);
}
}
break;
}
int sm = 0;
for(int i:vis) sm += 1;
if(sm == k)
cout<<"possible";
else cout<<"impossible";
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10592kb
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: 10600kb
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: 2ms
memory: 10596kb
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: 10856kb
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: 10888kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 0ms
memory: 10892kb
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: 2ms
memory: 10888kb
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: 0ms
memory: 10600kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'