QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318958 | #7181. Graph Cuts | PhanDinhKhoi# | WA | 45ms | 7848kb | C++20 | 2.2kb | 2024-02-01 12:19:43 | 2024-02-01 12:19:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef pair<ld,ld> pld;
#define fi first
#define se second
#define pb push_back
#define ffor(i,n) for (int i=0;i <int(n);i++)
#define sz(x) ((int) (x).size())
#define all(x) x.begin(),x.end()
const int sq = 450;
int deg[100005];
int inset[100005];
int big[100005];
vector<int> vadj[100005];
int cnt[100005];
int eu[100005];
int ev[100005];
vector<int> se;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n , m ; cin >> n >> m ;
for (int i = 1 ; i <= m ; i++) {
int u , v; cin >> u >> v;
deg[u]++;
deg[v]++;
vadj[u].pb(i);
vadj[v].pb(i);
eu[i] = u;
ev[i] = v;
}
for (int i = 1 ; i <= m ; i++) se.pb(i);
for (int i = 1 ; i <= n ; i++) {
if (deg[i] >= sq) {big[i] = 1;}
}
int q ; cin >> q;
while (q--) {
char t ; cin >> t;
if (t == '+') {
int id; cin >> id;
if (!big[id]) {
for (auto e : vadj[id]) {
cnt[e]++;
}
}
inset[id] = 1;
}
else if (t == '-') {
int id; cin >> id;
if (!big[id]) {
for (auto e : vadj[id]) {
cnt[e]--;
}
}
inset[id] = 0;
}
else {
int ans = 0;
vector<int> test;
vector<int> temp;
for (int tt = 1 ; tt <= sq+5 ; tt++) {
if (ans != 0) break;
if (se.empty()) break;
int id = se.back() ; se.pop_back();
int cur = cnt[id];
if ( big[eu[id]] && inset[eu[id]] ) cur++;
if ( big[ev[id]] && inset[ev[id]] ) cur++;
if (cur == 1) {
// found
ans = id;
}
else {
temp.pb(id);
}
}
for (auto id : temp) if (id != ans) se.pb(id);
cout << ans << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
4 5 1 2 1 3 1 4 2 3 2 4 10 + 1 + 2 ? ? ? ? ? - 2 ? ?
output:
5 4 3 2 0 1 0
result:
ok q=10
Test #2:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
0 0 0
output:
result:
ok q=0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
0 0 1 ?
output:
0
result:
ok q=1
Test #4:
score: 0
Accepted
time: 9ms
memory: 5660kb
input:
1000 2000 1 50 1 88 331 1 1 352 1 497 2 32 2 282 550 2 989 2 334 3 3 665 4 38 4 69 4 343 4 451 589 4 917 4 89 5 5 162 675 5 681 6 7 22 127 7 7 592 7 672 787 7 8 310 107 9 9 137 184 9 9 244 378 9 446 9 9 658 883 9 65 10 75 10 414 10 10 468 686 10 245 11 269 11 11 386 403 11 493 11 394 12 493 12 565 1...
output:
1998 1997 1996 1994 1991 1990 1989 1986 1985 1984 1981 1979 1978 1977 1976 1975 1974 1973 1971 1970 1969 1963 1962 1960 1958 1957 1954 1953 1952 1951 1950 1949 1947 1968 1946 1942 1938 1937 1934 1933 1932 1928 1927 1922 1920 1917 1915 1914 1913 1911 1903 1902 1901 1899 1956 1897 1895 1892 1890 1889 ...
result:
ok q=100000
Test #5:
score: 0
Accepted
time: 45ms
memory: 7848kb
input:
447 99681 2 1 1 3 4 1 1 5 1 6 1 7 1 8 9 1 10 1 1 11 1 12 1 13 1 14 1 15 1 16 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 1 26 27 1 28 1 1 29 30 1 31 1 1 32 33 1 1 34 1 35 36 1 37 1 38 1 39 1 40 1 1 41 1 42 43 1 44 1 45 1 46 1 1 47 48 1 49 1 1 50 1 51 1 52 53 1 54 1 55 1 1 56 57 1 1 58 59 1 60 1 1 6...
output:
99681
result:
ok q=100000
Test #6:
score: -100
Wrong Answer
time: 35ms
memory: 6032kb
input:
447 99681 1 2 3 1 4 1 5 1 1 6 7 1 8 1 9 1 10 1 11 1 1 12 13 1 14 1 15 1 1 16 1 17 18 1 19 1 1 20 21 1 22 1 23 1 24 1 1 25 26 1 27 1 28 1 1 29 1 30 31 1 32 1 1 33 1 34 35 1 1 36 37 1 38 1 1 39 40 1 41 1 42 1 43 1 1 44 45 1 46 1 47 1 48 1 49 1 50 1 1 51 1 52 1 53 1 54 1 55 56 1 1 57 58 1 1 59 1 60 61 ...
output:
0 99227 99233 99243 99256 99262 99237 99266 99272 99236 99265 99284 99290 99293 99277 99275 99246 99249 99294 99300 99303 99304 99311 99317 99320 99321 99327 99286 99229 99258 99313 99330 99331 99299 99298 99297 99296 99295 99247 99276 99292 99291 99283 99282 99281 99280 99278 99261 99274 99259 9923...
result:
wrong answer Edge exists, but not found