結果
| 問題 |
No.1320 Two Type Min Cost Cycle
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-30 16:36:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,068 bytes |
| コンパイル時間 | 5,929 ms |
| コンパイル使用メモリ | 170,516 KB |
| 実行使用メモリ | 36,324 KB |
| 最終ジャッジ日時 | 2025-09-30 16:36:28 |
| 合計ジャッジ時間 | 9,677 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
namespace IO{
const int SIZE=1<<21;
static char ibuf[SIZE],obuf[SIZE],*iS,*iT,*oS=obuf,*oT=oS+SIZE-1;
int qr;
char qu[55],c;
bool f;
#define getchar() (IO::iS==IO::iT?(IO::iT=(IO::iS=IO::ibuf)+fread(IO::ibuf,1,IO::SIZE,stdin),(IO::iS==IO::iT?EOF:*IO::iS++)):*IO::iS++)
#define putchar(x) *IO::oS++=x,IO::oS==IO::oT?flush():0
#define flush() fwrite(IO::obuf,1,IO::oS-IO::obuf,stdout),IO::oS=IO::obuf
#define puts(x) IO::Puts(x)
template<typename T>
inline void read(T&x){
for(f=1,c=getchar();c<48||c>57;c=getchar())f^=c=='-';
for(x=0;c<=57&&c>=48;c=getchar()) x=(x<<1)+(x<<3)+(c&15);
x=f?x:-x;
}
template<typename T>
inline void write(T x){
if(!x) putchar(48); if(x<0) putchar('-'),x=-x;
while(x) qu[++qr]=x%10^48,x/=10;
while(qr) putchar(qu[qr--]);
}
inline void Puts(const char*s){
for(int i=0;s[i];i++)
putchar(s[i]);
putchar('\n');
}
struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}
using IO::read;
using IO::write;
template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }
const int N = 2005;
int id, n, m, ans = 1e18;
int dis[N][N], p[N];
bool vis[N];
priority_queue < pii, vector < pii >, greater < pii > > q;
vector < int > g[N];
void dijkstra ( int s ) {
memset ( vis, 0, sizeof ( vis ) );
memset ( p, 0x3f, sizeof ( p ) );
p[s] = 0;
q.push ( { p[s], s } );
while ( !q.empty () ) {
int x = q.top ().second;
q.pop ();
if ( vis[x] ) {
continue;
}
vis[x] = 1;
for ( int v : g[x] ) {
if ( dis[x][v] && p[x] + dis[x][v] < p[v] ) {
p[v] = p[x] + dis[x][v];
q.push ( { -p[v], v } );
}
}
}
}
void Solve () {
ios :: sync_with_stdio ( false );
cin.tie ( 0 ), cout.tie ( 0 );
cin >> id >> n >> m;
for ( int i = 1; i <= m; i ++ ) {
int u, v, w;
cin >> u >> v >> w;
if ( !id ) {
g[u].push_back ( v ), g[v].push_back ( u );
dis[u][v] = dis[v][u] = w;
}
else {
g[u].push_back ( v );
dis[u][v] = w;
}
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= n; j ++ ) {
if ( dis[i][j] ) {
int tmpa = dis[i][j], tmpb = dis[j][i];
dis[i][j] = dis[j][i] = 0;
dijkstra ( j );
ans = min ( ans, p[i] + tmpa );
dis[i][j] = tmpa, dis[j][i] = tmpb;
}
}
}
cout << ( ans >= 1e18 ? -1 : ans );
}
signed main () {
#ifdef judge
freopen ( "Code.in", "r", stdin );
freopen ( "Code.out", "w", stdout );
freopen ( "Code.err", "w", stderr );
#endif
Solve ();
return 0;
}
vjudge1