ログインしてください。
提出 #45438798
ソースコード 拡げる
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 998244353
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
Sqr(x), k >>= 1;
}
return res;
}
const int N = 1e6 + 5;
int n, m;
set<int> G[N];
set<int> S;
int w[N], wcnt;
queue<int> q;
int d[N];
set<int> s[N];
int f[N];
int main()
{
scanf("%d %d", &n, &m);
for(int i = 1; i <= m; ++i)
{
int x, y;
scanf("%d %d", &x, &y);
G[x].insert(y);
G[y].insert(x);
}
for(int i = 1; i <= n; ++i)
S.insert(i);
q.push(1);
S.erase(1);
while(!q.empty())
{
int u = q.front();
q.pop();
wcnt = 0;
for(auto v : S) w[++wcnt] = v;
for(int i = 1; i <= wcnt; ++i)
{
int v = w[i];
if(G[u].find(v) == G[u].end())
{
q.push(v);
d[v] = d[u] + 1;
S.erase(v);
}
}
if(S.empty())
break;
}
if(d[n] == 0)
{
puts("-1");
return 0;
}
for(int i = 1; i <= n; ++i)
s[d[i]].insert(i);
int sum = 1;
f[1] = 1;
for(int i = 1; i <= n; ++i)
{
int res = 0;
for(SII it = s[i].begin(); it != s[i].end(); ++it)
{
int u = *it;
f[u] = sum;
for(SII _it = G[u].begin(); _it != G[u].end(); ++_it)
{
int v = *_it;
if(d[v] == i - 1)
Dec(f[u], f[v]);
}
Inc(res, f[u]);
}
sum = res;
}
printf("%d\n", f[n]);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | G - Counting Shortest Paths |
| ユーザ | Schucking_Sattin |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 575 |
| コード長 | 2426 Byte |
| 結果 | AC |
| 実行時間 | 372 ms |
| メモリ | 128416 KiB |
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:53:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 575 / 575 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 49 ms | 97516 KiB |
| 001.txt | AC | 47 ms | 97520 KiB |
| 002.txt | AC | 47 ms | 97568 KiB |
| 003.txt | AC | 272 ms | 116056 KiB |
| 004.txt | AC | 276 ms | 116080 KiB |
| 005.txt | AC | 306 ms | 116116 KiB |
| 006.txt | AC | 290 ms | 116252 KiB |
| 007.txt | AC | 346 ms | 116076 KiB |
| 008.txt | AC | 311 ms | 115996 KiB |
| 009.txt | AC | 327 ms | 115888 KiB |
| 010.txt | AC | 334 ms | 116008 KiB |
| 011.txt | AC | 306 ms | 115772 KiB |
| 012.txt | AC | 311 ms | 116056 KiB |
| 013.txt | AC | 123 ms | 106852 KiB |
| 014.txt | AC | 260 ms | 114416 KiB |
| 015.txt | AC | 213 ms | 112908 KiB |
| 016.txt | AC | 227 ms | 111088 KiB |
| 017.txt | AC | 168 ms | 109336 KiB |
| 018.txt | AC | 170 ms | 107816 KiB |
| 019.txt | AC | 129 ms | 105940 KiB |
| 020.txt | AC | 110 ms | 104236 KiB |
| 021.txt | AC | 91 ms | 102536 KiB |
| 022.txt | AC | 70 ms | 100744 KiB |
| 023.txt | AC | 56 ms | 99248 KiB |
| 024.txt | AC | 135 ms | 109952 KiB |
| 025.txt | AC | 132 ms | 110124 KiB |
| 026.txt | AC | 299 ms | 126312 KiB |
| 027.txt | AC | 277 ms | 127020 KiB |
| 028.txt | AC | 349 ms | 128296 KiB |
| 029.txt | AC | 367 ms | 128300 KiB |
| 030.txt | AC | 372 ms | 128416 KiB |
| 031.txt | AC | 345 ms | 128416 KiB |
| 032.txt | AC | 349 ms | 128200 KiB |
| 033.txt | AC | 331 ms | 116376 KiB |
| 034.txt | AC | 340 ms | 116304 KiB |
| 035.txt | AC | 325 ms | 116312 KiB |
| 036.txt | AC | 346 ms | 116452 KiB |
| 037.txt | AC | 330 ms | 116312 KiB |
| 038.txt | AC | 324 ms | 116104 KiB |
| 039.txt | AC | 348 ms | 116336 KiB |
| 040.txt | AC | 339 ms | 116316 KiB |
| 041.txt | AC | 317 ms | 116192 KiB |
| 042.txt | AC | 333 ms | 116304 KiB |
| 043.txt | AC | 339 ms | 116304 KiB |
| 044.txt | AC | 295 ms | 116244 KiB |
| 045.txt | AC | 342 ms | 116300 KiB |
| 046.txt | AC | 325 ms | 116308 KiB |
| 047.txt | AC | 337 ms | 116188 KiB |
| 048.txt | AC | 368 ms | 116244 KiB |
| 049.txt | AC | 335 ms | 116188 KiB |
| 050.txt | AC | 368 ms | 116420 KiB |
| 051.txt | AC | 344 ms | 116312 KiB |
| 052.txt | AC | 356 ms | 116436 KiB |
| 053.txt | AC | 232 ms | 116236 KiB |
| 054.txt | AC | 330 ms | 116312 KiB |
| 055.txt | AC | 335 ms | 120088 KiB |
| 056.txt | AC | 308 ms | 119688 KiB |
| 057.txt | AC | 318 ms | 118888 KiB |
| 058.txt | AC | 317 ms | 118628 KiB |
| 059.txt | AC | 297 ms | 118424 KiB |
| 060.txt | AC | 319 ms | 118396 KiB |
| 061.txt | AC | 243 ms | 124372 KiB |
| 062.txt | AC | 65 ms | 101132 KiB |
| 063.txt | AC | 153 ms | 114744 KiB |
| 064.txt | AC | 51 ms | 98952 KiB |
| 065.txt | AC | 173 ms | 116256 KiB |
| 066.txt | AC | 191 ms | 120036 KiB |
| 067.txt | AC | 219 ms | 122436 KiB |
| 068.txt | AC | 164 ms | 115976 KiB |
| 069.txt | AC | 142 ms | 111508 KiB |
| 070.txt | AC | 194 ms | 119980 KiB |
| example0.txt | AC | 47 ms | 97404 KiB |
| example1.txt | AC | 45 ms | 97408 KiB |