QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201693 | #5160. Kebab Pizza | Delay_for_five_minutes# | WA | 2ms | 11044kb | C++20 | 2.2kb | 2023-10-05 16:11:43 | 2023-10-05 16:11:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int k , n;
set<pair<int,int> > st;
vector<int> E[100005];
int deg[200005];
int in[200005];
int d2[200005];
bool ok[200005];
vector<int> G[100005];
bool vis[100005];
int tv , te;
void dfs(int u)
{
vis[u] = 1;
tv++ ;
for(auto v : G[u]) {
if(!vis[v]) {
dfs(v) ;
}
te++;
}
}
void dfs2(int u)
{
vis[u] = 1;
tv++ ;
for(auto v : E[u]) {
if(!vis[v]) {
dfs2(v) ;
}
te++;
}
}
int main()
{
// freopen("in.txt","r",stdin) ;
ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
cin >> k >> n;
int cnt = 0;
for(int i = 1;i <= k;i++) {
int a , b;cin >> a >> b;
if(a > b) swap(a, b) ;
if(st.count({a , b})) continue ;
st.insert({a , b}) ; ++cnt;
if(a == b) {
in[a] = 1;
}
else {
deg[a]++ ; deg[b]++ ;
E[a].push_back(b) ; E[b].push_back(a) ;
}
}
for(int i = 1;i <= n;i++) {
if(deg[i] == 1 && !in[i]) ok[i] = 0;
else ok[i] = 1;
}
int mx = 0;
for(int i = 1;i <= n;i++) {
if(!ok[i]) continue ;
for(auto v : E[i]) {
if(ok[v]) {d2[i]++ ;
G[i].push_back(v) ;}
}
if(ok[i]) mx = max(mx , d2[i]) ;
}
if(mx <= 2) {
int has_l = 0 , has_c = 0;
for(int i = 1;i <= n;i++) {
if(ok[i] && !vis[i]) {
tv = 0 , te = 0;
dfs(i) ; te /= 2;
if(tv == 1 && !in[i]) continue ;
if(tv == te){
has_c = i;
}
else has_l++;
}
}
if(has_c) {
memset(vis,0,sizeof(vis)) ;
tv = te = 0;
dfs2(has_c) ; te /= 2;
// cout << tv << ' ' << te <<' ' << cnt << '\n' ;
if(te == cnt) cout << "possible" ;
else cout << "impossible" ;
}
else cout << "possible" ;
}
else cout << "impossible" ;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 10888kb
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: 11044kb
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: 0ms
memory: 10944kb
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: 1ms
memory: 10904kb
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: 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: 10824kb
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: 0ms
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: 0
Accepted
time: 1ms
memory: 10912kb
input:
4 5 1 2 3 4 4 5 5 3
output:
impossible
result:
ok single line: 'impossible'
Test #9:
score: 0
Accepted
time: 0ms
memory: 10936kb
input:
4 4 1 1 2 3 3 4 4 2
output:
impossible
result:
ok single line: 'impossible'
Test #10:
score: 0
Accepted
time: 1ms
memory: 11036kb
input:
3 4 1 2 2 3 3 1
output:
possible
result:
ok single line: 'possible'
Test #11:
score: 0
Accepted
time: 2ms
memory: 10924kb
input:
4 3 1 2 2 3 3 1 1 2
output:
possible
result:
ok single line: 'possible'
Test #12:
score: 0
Accepted
time: 1ms
memory: 10956kb
input:
5 4 1 2 2 3 3 1 1 4 4 4
output:
impossible
result:
ok single line: 'impossible'
Test #13:
score: -100
Wrong Answer
time: 2ms
memory: 10984kb
input:
4 3 1 2 2 3 3 1 1 1
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'