QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658226 | #6765. Don't Really Like How The Story Ends | CangShuV# | WA | 73ms | 8324kb | C++23 | 2.1kb | 2024-10-19 16:25:10 | 2024-10-19 16:25:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
set<int> g[N];
// void add(int f, int t) {
// g[f].insert(t);
// g[t].insert(f);
// }
void add(int f, int t) {
g[f].insert(t);
}
void clr(int n) {
n += 2;
for (int i = 0; i <= n; ++i) {
g[i].clear();
}
}
int res = 0;
int st[N];
int go,cnt;
void dfs(int u){
if(!g[u].size()){
return ;
}
for(auto &it:g[u]){
while(go<it){
go+=1;
cnt+=1;
dfs(go-1);
}
if(go==it){
go+=1;
}
}
}
// // set<int> stt;
// int dfs(int u, int go) {
// st[u] = 1;
// int acc = 0;
// for (auto &it : g[u]) {
// if (!st[it]) {
// if (it == go) {
// go = dfs(go, go + 1);
// } else
// acc = 1;
// }
// }
// if (!st[go]) {
// if (g[u].find(go) != g[u].end()) {
// go = dfs(go, go + 1);
// } else {
// if (acc) {
// add(u, go);
// ++res;
// go = dfs(go, go + 1);
// return go;
// } else {
// return go;
// }
// }
// }
// if (u == 1) {
// for (int i = 1; i <= n; ++i) {
// if (!st[i]) {
// if (g[1].find(i) == g[1].end()) {
// add(1, i);
// ++res;
// }
// dfs(i, i + 1);
// }
// }
// } else {
// return -1;
// }
// }
int n,m;
int a, b;
void solve() {
cin >> n >> m;
clr(n);
go=2;
cnt=0;
res = 0;
for (int i = 1; i <= n; ++i)
st[i] = 0;
for (int i = 1; i <= m; ++i) {
cin >> a >> b;
add(min(a,b), max(a,b));
}
add(1,n+1);
dfs(1);
cout << cnt << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
while (n--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8308kb
input:
3 2 3 1 1 1 2 2 1 4 1 1 4 4 2 1 2 3 4
output:
0 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 73ms
memory: 8324kb
input:
117747 3 7 2 1 3 3 1 3 1 1 3 2 1 1 3 1 4 8 2 3 4 3 3 2 4 2 1 3 2 1 4 3 2 4 3 4 2 3 2 2 3 3 1 1 2 5 1 1 2 2 2 2 1 2 2 2 3 7 2 1 1 2 3 3 3 2 1 2 3 3 3 2 4 5 1 2 3 3 4 4 1 4 2 1 3 1 3 2 1 3 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 1 1 1 1 5 4 2 1 2 5 1 3 3 2 4 7 1 1 2 4 3 2 1 1 1 1 4 2 2 3 5 8 3 3 2 2 4 2 1 4 1...
output:
0 1 1 0 1 1 1 0 0 2 1 1 0 0 2 1 2 0 1 0 2 3 0 0 0 2 1 1 1 0 0 0 1 1 2 1 3 0 1 1 3 1 3 1 0 0 1 2 0 2 0 1 1 0 0 2 0 0 0 1 0 3 0 3 0 0 1 2 0 3 2 0 1 0 1 0 2 3 0 0 1 1 1 0 0 2 1 3 0 1 2 0 0 0 3 0 0 3 1 0 2 0 0 1 1 0 1 0 0 0 0 4 0 0 0 0 0 0 2 0 1 0 0 1 0 0 0 2 0 1 0 0 0 2 1 1 2 2 0 1 0 1 1 1 2 1 1 1 0 0 ...
result:
wrong answer 2nd lines differ - expected: '0', found: '1'