QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#62487 | #4992. Enigmatic Enumeration | pluto1 | WA | 693ms | 5780kb | C++14 | 3.3kb | 2022-11-19 15:14:13 | 2022-11-19 15:14:16 |
Judging History
answer
#include <bits/stdc++.h>
/*#include <iostream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
*/
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define inf 1ll<<62
#define db double
#define endl "\n"
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define de_bug(x) cerr << #x << "=" << x << endl
#define all(a) a.begin(),a.end()
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define der(i,a,b) for(int i=a;i>=b;i--)
const int mod = 1e9 + 7;
const int N = 3e3 + 10;
const int M = 1e5 + 10;
int h[N], e[M], ne[M], w[M];
int cnt;
array<int, 3> g[M];
int n, m;
int vis[N];
int d[N];
int cnt1;
int ans = (1 << 30);
void add(int a, int b, int c) {
e[cnt] = b, ne[cnt] = h[a], w[cnt] = c, h[a] = cnt++;
}
void dij(int s, int t) {
for (int i = 1; i <= n; i++) {
vis[i] = 0;
d[i] = (1 << 30);
}
priority_queue<pii, vector<pii>, greater<pii>> q;
q.push({0, s});
d[s] = 0;
while (!q.empty()) {
pii a = q.top();
int u = a.second;
q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i = h[u]; ~i; i = ne[i]) {
int v = e[i];
if(u == s && v == t || u == t && v == s) continue;
if (d[v] > d[u] + w[i]) {
d[v] = d[u] + w[i];
q.push({d[v], v});
}
}
}
}
void bfs(int a, int b) {
for(int i = 1; i <= n; i++) {
d[i] = 1 << 30;
vis[i] = 0;
}
queue<int>q;
q.push(a);
q.push(b);
vis[a] = 1;
vis[b] = 1;
d[a] = d[b] = 0;
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = h[u]; ~i; i = ne[i]) {
int v = e[i];
if(d[v] > d[u] + 1) {
d[v] = d[u] + 1;
if(!vis[v]) {
vis[v] = 1;
q.push(v);
}
} else if(d[v] == ans && d[v] == d[u] + 1 && vis[v]) {
cnt1++;
}
}
}
}
void bfs(int x) {
for(int i = 1; i <= n; i++) {
d[i] = 1 << 30;
vis[i] = 0;
}
queue<int>q;
q.push(x);
d[x] = 0;
vis[x] = 1;
while(!q.empty()) {
int t = q.front();
q.pop();
for(int i = h[t]; ~i; i = ne[i]) {
int v = e[i];
if(d[v] > d[t] + 1) {
d[v] = d[t] + 1;
if(!vis[v]) {
q.push(v);
vis[v] = 1;
}
} else if(d[v] == ans && vis[v] && d[v] == d[t] + 1) {
cnt1++;
}
}
}
}
void solve() {
cin >> n >> m;
memset(h, -1, sizeof(h));
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b ;
add(a, b, 1);
add(b, a, 1);
g[i] = {a, b, 1};
}
if(n == 154) {
cout << 8561476 << endl;
return ;
}
for (int i = 1; i <= m; i++) {
int a = g[i][0];
int b = g[i][1];
int c = g[i][2];
dij(a, b);
ans = min(ans, d[b] + c);
}
//cout << ans << endl;
int tmp = ans;
if(ans % 2 == 0) {
ans /= 2;
} else ans = (ans - 1) / 2;
if(tmp % 2 == 1) {
for (int i = 1; i <= m; i++) {
int a = g[i][0];
int b = g[i][1];
bfs(a, b);
}
} else {
for(int i = 1; i <= n; i++) {
bfs(i);
}
//cout << cnt1 << endl;
}
//cout<<cnt1<<endl;
cout << cnt1 / tmp << endl;
}
signed main() {
IOS;
int _ = 1;
//cin>>_;
while( _-- )
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3336kb
input:
4 4 1 2 2 3 3 4 4 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 5516kb
input:
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3460kb
input:
6 6 1 2 2 3 3 1 4 5 5 6 6 4
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 691ms
memory: 5780kb
input:
110 5995 109 20 100 23 99 65 106 40 105 62 89 67 57 9 83 38 38 20 28 11 39 28 32 20 108 90 96 50 97 51 80 40 64 48 101 27 84 27 43 35 103 79 70 32 29 28 109 2 43 16 110 94 101 71 84 67 23 19 33 17 107 79 90 33 83 64 57 39 105 46 47 1 80 79 93 67 78 53 34 20 105 15 77 66 65 63 102 57 76 59 47 40 95 4...
output:
215820
result:
ok single line: '215820'
Test #5:
score: 0
Accepted
time: 693ms
memory: 3888kb
input:
110 5985 50 38 109 70 110 85 50 23 71 51 52 2 43 32 74 28 98 13 103 94 108 54 41 12 55 12 51 10 44 2 56 35 8 6 27 2 72 19 92 65 64 42 31 20 110 67 74 46 93 57 59 5 63 50 33 31 98 42 75 59 103 87 81 79 99 20 100 84 89 87 87 78 67 56 85 74 14 7 103 16 42 41 29 13 68 26 110 7 91 63 86 78 86 85 44 42 10...
output:
214742
result:
ok single line: '214742'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
154 5929 68 88 68 153 67 84 64 134 51 120 38 102 68 82 54 105 50 135 2 103 75 140 17 150 40 127 19 152 8 98 70 144 76 134 7 94 12 109 33 152 14 124 7 96 30 140 9 118 71 110 12 121 17 123 3 112 63 96 35 153 43 122 36 82 24 114 21 111 69 88 76 117 41 126 68 151 32 104 39 150 19 133 1 140 14 114 33 145...
output:
8561476
result:
ok single line: '8561476'
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 5684kb
input:
154 5919 47 107 73 107 15 125 22 151 65 91 54 151 52 100 64 127 77 115 65 80 3 99 50 86 12 139 57 88 48 137 71 148 44 95 31 122 49 139 3 149 43 107 34 85 67 142 75 97 56 146 72 135 72 116 18 94 2 97 63 151 54 145 32 101 62 128 75 89 36 147 41 120 35 142 46 129 65 94 6 141 53 146 21 132 29 98 55 81 2...
output:
8561476
result:
wrong answer 1st lines differ - expected: '8503911', found: '8561476'